Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress testing/add grant contribution tests #9518

3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ cypress-local: ## Run the cypress tests locally - the application MUST already b
@npx cypress install
@npx cypress run --headed --browser chrome

cypress-docker: ## Run the cypress tests in a container - the application MUST already be running for these to pass
@docker-compose exec -e VERBOSE=1 -e CYPRESS_REMOTE_DEBUGGING_PORT=9222 web node_modules/.bin/cypress run --browser chrome --headed

pytest: ## Run pytest (Backend)
@docker-compose exec -e PYTHONPATH=/code/app/ -e DJANGO_SETTINGS_MODULE="app.settings" web pytest -p no:ethereum

Expand Down
18 changes: 18 additions & 0 deletions app/grants/migrations/0125_auto_20210928_2029.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.24 on 2021-09-28 20:29

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('grants', '0124_auto_20210922_1731'),
]

operations = [
migrations.AlterField(
model_name='contribution',
name='checkout_type',
field=models.CharField(blank=True, choices=[('eth_std', 'eth_std'), ('eth_zksync', 'eth_zksync'), ('zcash_std', 'zcash_std'), ('celo_std', 'celo_std'), ('zil_std', 'zil_std'), ('polkadot_std', 'polkadot_std'), ('harmony_std', 'harmony_std'), ('binance_std', 'binance_std'), ('rsk_std', 'rsk_std'), ('algorand_std', 'algorand_std')], help_text='The checkout method used while making the contribution', max_length=30, null=True),
),
]
2 changes: 1 addition & 1 deletion app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ def grant_new(request):
return JsonResponse(response)

eth_payout_address = request.POST.get('eth_payout_address', request.POST.get('admin_address'))
zcash_payout_address = request.POST.get('zcash_payout_address', '0x0')
zcash_payout_address = request.POST.get('zcash_payout_address', None)
celo_payout_address = request.POST.get('celo_payout_address', None)
zil_payout_address = request.POST.get('zil_payout_address', None)
polkadot_payout_address = request.POST.get('polkadot_payout_address', None)
Expand Down
1 change: 1 addition & 0 deletions bin/ci/cypress-run
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ python3 app/manage.py collectstatic --noinput --disable-collectfast
python3 app/manage.py migrate
python3 app/manage.py loaddata "${TRAVIS_BUILD_DIR}/app/app/fixtures/users.json"
python3 app/manage.py loaddata "${TRAVIS_BUILD_DIR}/app/app/fixtures/profiles.json"
python3 app/manage.py loaddata "${TRAVIS_BUILD_DIR}/app/app/fixtures/economy.json"

# run app server
python3 app/manage.py runserver 0.0.0.0:8000 &
Expand Down
94 changes: 94 additions & 0 deletions cypress/integration/grants/test_contributing_to_grant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
describe('contributing to grant', () => {
before(() => {
cy.setupMetamask();
});

afterEach(() => {
cy.disconnectMetamaskWallet();
cy.logout();
});

after(() => {
cy.clearWindows();
});

it('contributes eth to a single grant', () => {
cy.createGrantSubmission().then((response) => {
console.log('response: ', response);
const grantUrl = response.body.url;

cy.approveGrant(grantUrl);
cy.impersonateUser();

cy.visit(grantUrl);

cy.get('#navbarDropdownWallet').click();
cy.contains('Connect Wallet').click();
cy.contains('MetaMask').click();

cy.changeMetamaskNetwork('localhost');
cy.acceptMetamaskAccess();

cy.get('.grant-checkout').contains('Add to Cart').click();
cy.wait(1000); // slow the test down to allow cart data to load

cy.get('#gc-cart').click();
cy.contains('Checkout').click();

cy.get('#vs3__combobox').click().type('ETH{enter}');
cy.get('#gitcoin-grant-input-amount').type('{backspace}');
cy.get('#js-fundGrants-button').scrollIntoView().click();

cy.confirmMetamaskTransaction();

cy.get('body').should('contain.text', 'Thank you for contributing to open source!');
});
});

it('contributes eth to multiple grants', () => {
cy.createGrantSubmission().then((response) => {
const grantUrl = response.body.url;

cy.wrap(grantUrl).as('grant1');

cy.approveGrant(grantUrl);
});

cy.createGrantSubmission().then((response) => {
const grantUrl = response.body.url;

cy.wrap(grantUrl).as('grant2');

cy.approveGrant(grantUrl);
});

cy.impersonateUser();

cy.get('@grant1').then((grantUrl) => {
cy.visit(grantUrl);
cy.get('.grant-checkout').contains('Add to Cart').click();
});

cy.get('@grant2').then((grantUrl) => {
cy.visit(grantUrl);
cy.get('.grant-checkout').contains('Add to Cart').click();
});

cy.visit('grants/cart?');


cy.contains('MetaMask').click();

cy.changeMetamaskNetwork('localhost');
cy.acceptMetamaskAccess();

cy.get('#vs3__combobox').click().type('ETH{enter}');
cy.get('#vs4__combobox').click().type('ETH{enter}');
cy.get('#gitcoin-grant-input-amount').type('{backspace}');
cy.get('#js-fundGrants-button').scrollIntoView().click();

cy.confirmMetamaskTransaction();

cy.get('body').should('contain.text', 'Thank you for contributing to open source!');
});
});
3 changes: 1 addition & 2 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Cypress.Commands.add('createGrantSubmission', (options = {}) => {
reference_url: options.reference_url || 'https://gitcoin.co',
github_project_url: options.github_project_url || 'https://github.com/gitcoinco/web',
'team_members[]': options.team_members || '',
'categories[]': options.categories || 4
'tags[]': options.tags || '1'
},
form: true
});
Expand All @@ -99,7 +99,6 @@ Cypress.Commands.add('approveGrant', (grantSlug) => {

cy.visit(changePath);
cy.get('[name=active]').check();
cy.get('[name=defer_clr_to]').select(pk);
cy.get('[name=_save]').click();

cy.logout();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"babel-loader": "^8.2.2",
"css-loader": "^5.2.4",
"cypress": "^8.3.1",
"cypress-metamask": "github:gitcoinco/cypress-metamask#v1.0.10-dev",
"cypress-metamask": "github:gitcoinco/cypress-metamask#v1.0.11-dev",
"eslint": "^7.14.0",
"file-loader": "^6.2.0",
"filemanager-webpack-plugin": "^4.0.0",
Expand Down
Loading