Skip to content

Commit

Permalink
Merge pull request oasisprotocol#1780 from oasisprotocol/lw/fix-e2e-t…
Browse files Browse the repository at this point in the history
…ests

Improve e2e tests
  • Loading branch information
lukaw3d authored Nov 29, 2023
2 parents b26abd1 + e07e958 commit 3e9fb62
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
1 change: 1 addition & 0 deletions .changelog/1780.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve e2e tests
9 changes: 9 additions & 0 deletions playwright/tests/migrating-persisted-state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions playwright/utils/extensionTestExtend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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`)
},
})
11 changes: 8 additions & 3 deletions playwright/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 15 additions & 10 deletions src/utils/__fixtures__/test-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 3e9fb62

Please sign in to comment.