diff --git a/.changelog/1780.internal.md b/.changelog/1780.internal.md new file mode 100644 index 0000000000..e1bf891d94 --- /dev/null +++ b/.changelog/1780.internal.md @@ -0,0 +1 @@ +Improve e2e tests diff --git a/playwright/tests/migrating-persisted-state.spec.ts b/playwright/tests/migrating-persisted-state.spec.ts index 89247a05a2..290d7c5856 100644 --- a/playwright/tests/migrating-persisted-state.spec.ts +++ b/playwright/tests/migrating-persisted-state.spec.ts @@ -25,12 +25,21 @@ test.describe('Migrating persisted state', () => { const tab2 = await context.newPage() await tab2.goto('/e2e') + await tab2.getByTestId('account-selector').click({ timeout: 15_000 }) + await expect(tab2.getByTestId('account-choice')).toHaveCount(1) const decryptedStateV1 = await tab2.evaluate(() => { const store: any = window['store'] return store.getState() as RootState }) expect(decryptedStateV1).toEqual({ ...privateKeyUnlockedState, + staking: { + ...privateKeyUnlockedState.staking, + validators: { + ...privateKeyUnlockedState.staking.validators, + timestamp: expect.any(Number), + }, + }, persist: { ...privateKeyUnlockedState.persist, stringifiedEncryptionKey: expect.any(String), diff --git a/playwright/utils/extensionTestExtend.ts b/playwright/utils/extensionTestExtend.ts index d4659766d7..87f8ce4232 100644 --- a/playwright/utils/extensionTestExtend.ts +++ b/playwright/utils/extensionTestExtend.ts @@ -13,6 +13,7 @@ export const test = base.extend<{ context: BrowserContext extensionId: string extensionPopupURL: `chrome-extension://${string}` + extensionManifestURL: `chrome-extension://${string}/manifest.json` }>({ // eslint-disable-next-line no-empty-pattern context: async ({}, use) => { @@ -38,4 +39,7 @@ export const test = base.extend<{ extensionPopupURL: async ({ extensionId }, use) => { await use(`chrome-extension://${extensionId}/${popupFile}#`) }, + extensionManifestURL: async ({ extensionId }, use) => { + await use(`chrome-extension://${extensionId}/manifest.json`) + }, }) diff --git a/playwright/utils/storage.ts b/playwright/utils/storage.ts index b8e9ff0cca..acf38ca155 100644 --- a/playwright/utils/storage.ts +++ b/playwright/utils/storage.ts @@ -3,16 +3,21 @@ import { privateKeyPersistedState } from '../../src/utils/__fixtures__/test-inpu export async function clearPersistedStorage( page: Page, - url: '/app.webmanifest' | `chrome-extension://${string}`, + url: '/app.webmanifest' | `chrome-extension://${string}/manifest.json`, ) { // Move to the right domain, but don't needlessly load HTML and JS. await page.goto(url) - await page.evaluate(() => window.localStorage.clear()) + await page.evaluate(() => { + window.localStorage.clear() + + const chrome = (window as any).chrome + chrome?.extension?.getBackgroundPage?.().location.reload() + }) } export async function addPersistedStorageV1( page: Page, - url: '/app.webmanifest' | `chrome-extension://${string}`, + url: '/app.webmanifest' | `chrome-extension://${string}/manifest.json`, ) { // Move to the right domain, but don't needlessly load HTML and JS. await page.goto(url) diff --git a/src/utils/__fixtures__/test-inputs.ts b/src/utils/__fixtures__/test-inputs.ts index 2fd975939b..ba60442b46 100644 --- a/src/utils/__fixtures__/test-inputs.ts +++ b/src/utils/__fixtures__/test-inputs.ts @@ -39,15 +39,16 @@ export const privateKeyPersistedState = typedStringify({ export const privateKeyUnlockedState = { account: { - address: '', - available: null, - debonding: null, - delegations: null, - total: null, + address: 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk', + allowances: [], + available: '0', + debonding: '0', + delegations: '0', + total: '0', accountError: undefined, transactions: [], transactionsError: undefined, - loading: true, + loading: false, }, contacts: {}, evmAccounts: {}, @@ -88,17 +89,21 @@ export const privateKeyUnlockedState = { transactionFormStep: 'transferType' satisfies `${TransactionFormSteps}` as TransactionFormSteps, }, staking: { - debondingDelegations: null, - delegations: null, + debondingDelegations: [], + delegations: [], updateDelegationsError: undefined, - validators: null, + validators: { + list: [], + network: 'mainnet', + timestamp: 1701224528489, + }, updateValidatorsError: undefined, selectedValidatorDetails: null, selectedValidator: null, loading: false, }, theme: { selected: 'dark' }, - transaction: { success: false, active: false }, + transaction: { success: false, error: undefined, preview: undefined, active: false }, wallet: { wallets: { oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk: {