Skip to content

Commit 3e9fb62

Browse files
authored
Merge pull request oasisprotocol#1780 from oasisprotocol/lw/fix-e2e-tests
Improve e2e tests
2 parents b26abd1 + e07e958 commit 3e9fb62

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

.changelog/1780.internal.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve e2e tests

playwright/tests/migrating-persisted-state.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,21 @@ test.describe('Migrating persisted state', () => {
2525

2626
const tab2 = await context.newPage()
2727
await tab2.goto('/e2e')
28+
await tab2.getByTestId('account-selector').click({ timeout: 15_000 })
29+
await expect(tab2.getByTestId('account-choice')).toHaveCount(1)
2830
const decryptedStateV1 = await tab2.evaluate(() => {
2931
const store: any = window['store']
3032
return store.getState() as RootState
3133
})
3234
expect(decryptedStateV1).toEqual({
3335
...privateKeyUnlockedState,
36+
staking: {
37+
...privateKeyUnlockedState.staking,
38+
validators: {
39+
...privateKeyUnlockedState.staking.validators,
40+
timestamp: expect.any(Number),
41+
},
42+
},
3443
persist: {
3544
...privateKeyUnlockedState.persist,
3645
stringifiedEncryptionKey: expect.any(String),

playwright/utils/extensionTestExtend.ts

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const test = base.extend<{
1313
context: BrowserContext
1414
extensionId: string
1515
extensionPopupURL: `chrome-extension://${string}`
16+
extensionManifestURL: `chrome-extension://${string}/manifest.json`
1617
}>({
1718
// eslint-disable-next-line no-empty-pattern
1819
context: async ({}, use) => {
@@ -38,4 +39,7 @@ export const test = base.extend<{
3839
extensionPopupURL: async ({ extensionId }, use) => {
3940
await use(`chrome-extension://${extensionId}/${popupFile}#`)
4041
},
42+
extensionManifestURL: async ({ extensionId }, use) => {
43+
await use(`chrome-extension://${extensionId}/manifest.json`)
44+
},
4145
})

playwright/utils/storage.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ import { privateKeyPersistedState } from '../../src/utils/__fixtures__/test-inpu
33

44
export async function clearPersistedStorage(
55
page: Page,
6-
url: '/app.webmanifest' | `chrome-extension://${string}`,
6+
url: '/app.webmanifest' | `chrome-extension://${string}/manifest.json`,
77
) {
88
// Move to the right domain, but don't needlessly load HTML and JS.
99
await page.goto(url)
10-
await page.evaluate(() => window.localStorage.clear())
10+
await page.evaluate(() => {
11+
window.localStorage.clear()
12+
13+
const chrome = (window as any).chrome
14+
chrome?.extension?.getBackgroundPage?.().location.reload()
15+
})
1116
}
1217

1318
export async function addPersistedStorageV1(
1419
page: Page,
15-
url: '/app.webmanifest' | `chrome-extension://${string}`,
20+
url: '/app.webmanifest' | `chrome-extension://${string}/manifest.json`,
1621
) {
1722
// Move to the right domain, but don't needlessly load HTML and JS.
1823
await page.goto(url)

src/utils/__fixtures__/test-inputs.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,16 @@ export const privateKeyPersistedState = typedStringify({
3939

4040
export const privateKeyUnlockedState = {
4141
account: {
42-
address: '',
43-
available: null,
44-
debonding: null,
45-
delegations: null,
46-
total: null,
42+
address: 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk',
43+
allowances: [],
44+
available: '0',
45+
debonding: '0',
46+
delegations: '0',
47+
total: '0',
4748
accountError: undefined,
4849
transactions: [],
4950
transactionsError: undefined,
50-
loading: true,
51+
loading: false,
5152
},
5253
contacts: {},
5354
evmAccounts: {},
@@ -88,17 +89,21 @@ export const privateKeyUnlockedState = {
8889
transactionFormStep: 'transferType' satisfies `${TransactionFormSteps}` as TransactionFormSteps,
8990
},
9091
staking: {
91-
debondingDelegations: null,
92-
delegations: null,
92+
debondingDelegations: [],
93+
delegations: [],
9394
updateDelegationsError: undefined,
94-
validators: null,
95+
validators: {
96+
list: [],
97+
network: 'mainnet',
98+
timestamp: 1701224528489,
99+
},
95100
updateValidatorsError: undefined,
96101
selectedValidatorDetails: null,
97102
selectedValidator: null,
98103
loading: false,
99104
},
100105
theme: { selected: 'dark' },
101-
transaction: { success: false, active: false },
106+
transaction: { success: false, error: undefined, preview: undefined, active: false },
102107
wallet: {
103108
wallets: {
104109
oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk: {

0 commit comments

Comments
 (0)