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

test: e2e tests added for psm UI #125

Merged
merged 7 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_modules
dist
dist-ssr
*.local
.env

# Editor directories and files
.vscode/*
Expand All @@ -22,3 +23,7 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# E2E tests
tests/e2e/screenshots
tests/e2e/videos
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"lint": "eslint src",
"format": "prettier --write . && yarn lint --fix",
"test": "vitest",
"coverage": "vitest run --coverage"
"coverage": "vitest run --coverage",
"test:e2e": "EXTENSION=keplr synpress run --configFile=tests/e2e/synpress.config.cjs"
},
"dependencies": {
"react": "^18.2.0",
Expand All @@ -21,6 +22,7 @@
"@agoric/ertp": "^0.16.2",
"@agoric/rpc": "^0.9.0",
"@agoric/smart-wallet": "^0.5.3",
"@agoric/synpress": "^3.7.2-beta.12",
"@agoric/ui-components": "^0.9.0",
"@agoric/web-components": "^0.15.0",
"@agoric/zoe": "^0.26.2",
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const path = require('path');
const synpressPath = path.join(process.cwd(), '/node_modules/@agoric/synpress');

module.exports = {
extends: `${synpressPath}/.eslintrc.js`,
};
99 changes: 99 additions & 0 deletions tests/e2e/specs/swap-tokens.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* eslint-disable ui-testing/no-disabled-tests */
describe('Swap Tokens Tests', () => {
it(`should connect with Agoric Chain on https;//wallet.agoric.app`, () => {
cy.origin('https://wallet.agoric.app/', () => {
cy.visit('/');
});
cy.acceptAccess().then(taskCompleted => {
expect(taskCompleted).to.be.true;
});

cy.origin('https://wallet.agoric.app/', () => {
cy.visit('/wallet/');

cy.get('input.PrivateSwitchBase-input').click();
cy.contains('Proceed').click();

cy.get('button[aria-label="Settings"]').click();

cy.get('#demo-simple-select').click();
cy.get('li[data-value="local"]').click();
cy.contains('button', 'Connect').click();
});

cy.acceptAccess().then(taskCompleted => {
expect(taskCompleted).to.be.true;
});
});

it('should connect with wallet', () => {
cy.visit('/');

// Switch to local network
cy.get('button').contains('Agoric Mainnet').click();
cy.get('button').contains('Local Network').click();

// Click the connect button
cy.get('button').contains('Connect Keplr').click();
cy.get('input[type="checkbox"]').click();
cy.get('button:enabled').contains('Proceed').click();

// Accept access and confirm
cy.acceptAccess();
cy.get('button').contains('Keplr Connected').should('be.visible');
});

it('should swap tokens from IST to stable', () => {
let ISTbalance;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our style is camel case

Suggested change
let ISTbalance;
let istBalance;


// Connect wallet
cy.visit('/');
cy.get('button').contains('Connect Keplr').click();

cy.addNewTokensFound();
cy.getTokenAmount('IST').then(amount => (ISTbalance = amount));

// Select asset and swap positions
cy.get('button').contains('Select asset').click();
cy.get('button').contains('USDC_axl').click();
cy.get('svg.transform.rotate-90').click();

// Swap 1 IST
cy.get('input[type="number"]').first().type(1);
cy.get('button').contains('Swap').click();

// Confirm transactions
cy.confirmTransaction();
cy.get('div').contains('Swap Completed').should('be.visible');

cy.getTokenAmount('IST').then(amount =>
expect(amount).to.equal(ISTbalance - 1)
);
});

it('should swap tokens from stable to IST', () => {
let ISTbalance;

// Connect wallet
cy.visit('/');
cy.get('button').contains('Connect Keplr').click();

cy.getTokenAmount('IST').then(amount => (ISTbalance = amount));

// Select asset
cy.get('button').contains('Select asset').click();
cy.get('button').contains('USDC_axl').click();

// Swap 1 USDC_axl
cy.get('input[type="number"]').first().type(1);
cy.get('button').contains('Swap').click();

// Confirm transactions
cy.confirmTransaction();
cy.get('div').contains('Swap Completed').should('be.visible');

cy.getTokenAmount('IST').then(amount =>
expect(amount).to.equal(ISTbalance + 1)
);
});
});
1 change: 1 addition & 0 deletions tests/e2e/support.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@agoric/synpress/support/index';
10 changes: 10 additions & 0 deletions tests/e2e/synpress.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const config = require('@agoric/synpress/synpress.config');
const { defineConfig } = require('cypress');

module.exports = defineConfig({
...config,
e2e: {
...config.e2e,
baseUrl: 'http://localhost:5173',
},
});
6 changes: 5 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mergeConfig } from 'vite';
import { defineConfig } from 'vitest/config';
import { defineConfig, configDefaults } from 'vitest/config';
import viteConfig from './vite.config';

export default mergeConfig(
Expand All @@ -8,6 +8,10 @@ export default mergeConfig(
test: {
setupFiles: ['src/installSesLockdown.ts'],
environment: 'happy-dom',
exclude: [
...configDefaults.exclude,
'tests/e2e/**'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternately we could consider tests to be the purview of vitest and have synpress run in /integration-tests or /e2e-tests. I advise this to simplify the configurations but I defer to whatever @samsiegart prefers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if our goal is to simply config then just a head up: changing this path will require updating the synpress.config.js file since it uses tests/e2e/** as its default path

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up, I think we can consider separating the directories but not a blocker

]
},
})
);
Loading
Loading