Skip to content

Commit fc1aa6b

Browse files
authored
test: e2e tests added for psm UI (#125)
* test: boilerplate added for e2e tests * test: spec file created * fix: swapping 1.25 tokens instead of 10 * test: updated tests to verify change in IST value * fix: swapping 1 tokens instead of 1.25 * fix: excluding tests/e2e from vitest * chore: fix for prettier
1 parent 2169d4d commit fc1aa6b

8 files changed

+4496
-81
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ node_modules
1111
dist
1212
dist-ssr
1313
*.local
14+
.env
1415

1516
# Editor directories and files
1617
.vscode/*
@@ -22,3 +23,7 @@ dist-ssr
2223
*.njsproj
2324
*.sln
2425
*.sw?
26+
27+
# E2E tests
28+
tests/e2e/screenshots
29+
tests/e2e/videos

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"lint": "eslint src",
1111
"format": "prettier --write . && yarn lint --fix",
1212
"test": "vitest",
13-
"coverage": "vitest run --coverage"
13+
"coverage": "vitest run --coverage",
14+
"test:e2e": "EXTENSION=keplr synpress run --configFile=tests/e2e/synpress.config.cjs"
1415
},
1516
"dependencies": {
1617
"react": "^18.2.0",
@@ -21,6 +22,7 @@
2122
"@agoric/ertp": "^0.16.2",
2223
"@agoric/rpc": "^0.9.0",
2324
"@agoric/smart-wallet": "^0.5.3",
25+
"@agoric/synpress": "^3.7.2-beta.12",
2426
"@agoric/ui-components": "^0.9.0",
2527
"@agoric/web-components": "^0.15.0",
2628
"@agoric/zoe": "^0.26.2",

tests/e2e/.eslintrc.cjs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const path = require('path');
2+
const synpressPath = path.join(process.cwd(), '/node_modules/@agoric/synpress');
3+
4+
module.exports = {
5+
extends: `${synpressPath}/.eslintrc.js`,
6+
};

tests/e2e/specs/swap-tokens.spec.js

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* eslint-disable ui-testing/no-disabled-tests */
2+
describe('Swap Tokens Tests', () => {
3+
it(`should connect with Agoric Chain on https;//wallet.agoric.app`, () => {
4+
cy.origin('https://wallet.agoric.app/', () => {
5+
cy.visit('/');
6+
});
7+
cy.acceptAccess().then(taskCompleted => {
8+
expect(taskCompleted).to.be.true;
9+
});
10+
11+
cy.origin('https://wallet.agoric.app/', () => {
12+
cy.visit('/wallet/');
13+
14+
cy.get('input.PrivateSwitchBase-input').click();
15+
cy.contains('Proceed').click();
16+
17+
cy.get('button[aria-label="Settings"]').click();
18+
19+
cy.get('#demo-simple-select').click();
20+
cy.get('li[data-value="local"]').click();
21+
cy.contains('button', 'Connect').click();
22+
});
23+
24+
cy.acceptAccess().then(taskCompleted => {
25+
expect(taskCompleted).to.be.true;
26+
});
27+
});
28+
29+
it('should connect with wallet', () => {
30+
cy.visit('/');
31+
32+
// Switch to local network
33+
cy.get('button').contains('Agoric Mainnet').click();
34+
cy.get('button').contains('Local Network').click();
35+
36+
// Click the connect button
37+
cy.get('button').contains('Connect Keplr').click();
38+
cy.get('input[type="checkbox"]').click();
39+
cy.get('button:enabled').contains('Proceed').click();
40+
41+
// Accept access and confirm
42+
cy.acceptAccess();
43+
cy.get('button').contains('Keplr Connected').should('be.visible');
44+
});
45+
46+
it('should swap tokens from IST to stable', () => {
47+
let ISTbalance;
48+
49+
// Connect wallet
50+
cy.visit('/');
51+
cy.get('button').contains('Connect Keplr').click();
52+
53+
cy.addNewTokensFound();
54+
cy.getTokenAmount('IST').then(amount => (ISTbalance = amount));
55+
56+
// Select asset and swap positions
57+
cy.get('button').contains('Select asset').click();
58+
cy.get('button').contains('USDC_axl').click();
59+
cy.get('svg.transform.rotate-90').click();
60+
61+
// Swap 1 IST
62+
cy.get('input[type="number"]').first().type(1);
63+
cy.get('button').contains('Swap').click();
64+
65+
// Confirm transactions
66+
cy.confirmTransaction();
67+
cy.get('div').contains('Swap Completed').should('be.visible');
68+
69+
cy.getTokenAmount('IST').then(amount =>
70+
expect(amount).to.equal(ISTbalance - 1)
71+
);
72+
});
73+
74+
it('should swap tokens from stable to IST', () => {
75+
let ISTbalance;
76+
77+
// Connect wallet
78+
cy.visit('/');
79+
cy.get('button').contains('Connect Keplr').click();
80+
81+
cy.getTokenAmount('IST').then(amount => (ISTbalance = amount));
82+
83+
// Select asset
84+
cy.get('button').contains('Select asset').click();
85+
cy.get('button').contains('USDC_axl').click();
86+
87+
// Swap 1 USDC_axl
88+
cy.get('input[type="number"]').first().type(1);
89+
cy.get('button').contains('Swap').click();
90+
91+
// Confirm transactions
92+
cy.confirmTransaction();
93+
cy.get('div').contains('Swap Completed').should('be.visible');
94+
95+
cy.getTokenAmount('IST').then(amount =>
96+
expect(amount).to.equal(ISTbalance + 1)
97+
);
98+
});
99+
});

tests/e2e/support.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@agoric/synpress/support/index';

tests/e2e/synpress.config.cjs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const config = require('@agoric/synpress/synpress.config');
2+
const { defineConfig } = require('cypress');
3+
4+
module.exports = defineConfig({
5+
...config,
6+
e2e: {
7+
...config.e2e,
8+
baseUrl: 'http://localhost:5173',
9+
},
10+
});

vitest.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mergeConfig } from 'vite';
2-
import { defineConfig } from 'vitest/config';
2+
import { defineConfig, configDefaults } from 'vitest/config';
33
import viteConfig from './vite.config';
44

55
export default mergeConfig(
@@ -8,6 +8,7 @@ export default mergeConfig(
88
test: {
99
setupFiles: ['src/installSesLockdown.ts'],
1010
environment: 'happy-dom',
11+
exclude: [...configDefaults.exclude, 'tests/e2e/**'],
1112
},
1213
})
1314
);

0 commit comments

Comments
 (0)