Skip to content

Commit

Permalink
Align Playwright tests with new mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Nov 22, 2024
1 parent eaac351 commit 2d11fb1
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion playwright/tests/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { privateKey, privateKeyAddress } from '../../src/utils/__fixtures__/test

test.beforeEach(async ({ context }) => {
await warnSlowApi(context)
await mockApi(context, 0)
await mockApi(context, '0')
})

test.describe('The extension popup should load', () => {
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mockApi } from '../utils/mockApi'

test.beforeEach(async ({ context }) => {
await warnSlowApi(context)
await mockApi(context, 0)
await mockApi(context, '0')
})

test.describe('The homepage should load', () => {
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/paraTimes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { mockApi } from '../utils/mockApi'

test.beforeEach(async ({ page }) => {
await warnSlowApi(page)
await mockApi(page, 500000000000)
await mockApi(page, '500000000000')
})

test.describe('ParaTimes', () => {
Expand Down
6 changes: 3 additions & 3 deletions playwright/tests/persist.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { fillPrivateKeyWithoutPassword, fillPrivateKeyAndPassword } from '../uti

test.beforeEach(async ({ context, page }) => {
await warnSlowApi(context)
await mockApi(context, 0)
await mockApi(context, '0')
await clearPersistedStorage(page, '/app.webmanifest')
})

Expand Down Expand Up @@ -141,14 +141,14 @@ test.describe('Persist', () => {
}) => {
await addPersistedStorageV1(page, '/app.webmanifest')
await page.goto('/')
await mockApi(context, 123)
await mockApi(context, '123000000000')
await page.getByPlaceholder('Enter your password', { exact: true }).fill(password)
await page.keyboard.press('Enter')
await expect(page).toHaveURL(new RegExp(`/account/${privateKeyAddress}`))
await expect(page.getByTestId('account-balance-summary')).toContainText('123.0')
await expect(page.getByTestId('account-balance-summary')).toContainText('ROSE')
await page.getByRole('button', { name: /Lock profile/ }).click()
await mockApi(context, 456)
await mockApi(context, '456000000000')
await page.getByPlaceholder('Enter your password', { exact: true }).fill(password)
await page.keyboard.press('Enter')
await expect(page.getByTestId('account-balance-summary')).toContainText('456.0')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const test = testWithUserDataDir(chromium)

test.beforeEach(async ({ context }) => {
await warnSlowApi(context)
await mockApi(context, 0)
await mockApi(context, '0')
})

test('Chromium expect mnemonic, privateKey, and password to NOT leak with preventSavingInputsToUserData', async ({
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/preventSavingInputsToDisk/firefox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const test = testWithUserDataDir(firefox)

test.beforeEach(async ({ context }) => {
await warnSlowApi(context)
await mockApi(context, 0)
await mockApi(context, '0')
})

test('Firefox expect mnemonic, privateKey, and password to NOT leak with preventSavingInputsToUserData', async ({
Expand Down
12 changes: 6 additions & 6 deletions playwright/tests/refreshing-balance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { mockApi } from '../utils/mockApi'

test.beforeEach(async ({ page }) => {
await warnSlowApi(page)
await mockApi(page, 123)
await mockApi(page, '123000000000')

await page.goto('/open-wallet/private-key')
await fillPrivateKeyWithoutPassword(page, {
Expand All @@ -24,7 +24,7 @@ test('Account selector should refresh balances on network change', async ({ page
await expect(page.getByTestId('account-choice')).toContainText('123.0')
await page.getByRole('button', { name: /Select/ }).click()

await mockApi(page, 456)
await mockApi(page, '456000000000')
await page.getByTestId('network-selector').click()
await page.getByRole('menuitem', { name: 'Testnet' }).click()
await page.getByTestId('account-selector').click()
Expand All @@ -37,9 +37,9 @@ test('Accounts page should continuously refresh balance', async ({ page }) => {
await page.getByTestId('account-selector').click()
await expect(page.getByTestId('account-balance-summary')).toContainText('123.0')
await expect(page.getByTestId('account-choice')).toContainText('123.0')
await mockApi(page, 456)
await page.waitForRequest('**/chain/account/info/*', { timeout: 60_000 })
await page.waitForRequest('**/chain/transactions*', { timeout: 60_000 })
await mockApi(page, '456000000000')
await page.waitForRequest('**/consensus/accounts/*', { timeout: 60_000 })
await page.waitForRequest('**/consensus/transactions?*', { timeout: 60_000 })
await expect(page.getByTestId('account-balance-summary')).toContainText('456.0')
await expect(page.getByTestId('account-choice')).toContainText('456.0')
// If balance in AccountSelector is not refreshed then making transactions with new balance will fail.
Expand All @@ -51,7 +51,7 @@ test('Accounts page should refresh balance on navigation', async ({ page }) => {
await expect(page.getByTestId('account-choice')).toContainText('123.0')
await page.getByRole('button', { name: /Select/ }).click()
await page.getByRole('link', { name: /Home/ }).click()
await mockApi(page, 456)
await mockApi(page, '456000000000')
await page.getByTestId('nav-myaccount').click()
await page.getByTestId('account-selector').click()
await expect(page.getByTestId('account-balance-summary')).toContainText('456.0')
Expand Down
15 changes: 9 additions & 6 deletions playwright/tests/syncTabs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {
} from '../../src/utils/__fixtures__/test-inputs'
import { addPersistedStorageV1, clearPersistedStorage } from '../utils/storage'
import { fillPrivateKeyWithoutPassword, fillPrivateKeyAndPassword } from '../utils/fillPrivateKey'
import type { AccountsRow } from '../../src/vendors/oasisscan/index'
import type { Account } from '../../src/vendors/nexus/index'

test.beforeEach(async ({ context, page }) => {
await warnSlowApi(context)
await mockApi(context, 0)
await mockApi(context, '0')
await clearPersistedStorage(page, '/app.webmanifest')
})

Expand Down Expand Up @@ -312,7 +312,7 @@ test.describe('syncTabs', () => {

// Delay getAccountBalanceWithFallback so addWallet is called after wallet is locked.
let apiBalance: Route
await context.route('**/chain/account/info/*', route => (apiBalance = route))
await context.route('**/consensus/accounts/*', route => (apiBalance = route))

await page.getByPlaceholder('Enter your private key here').fill(privateKey2)
await page.keyboard.press('Enter')
Expand All @@ -321,15 +321,18 @@ test.describe('syncTabs', () => {
body: JSON.stringify({
code: 0,
data: {
rank: 0,
address: '',
available: '0',
escrow: '0',
debonding: '0',
total: '0',
nonce: 1,
allowances: [],
} satisfies AccountsRow,
delegations_balance: '0',
debonding_delegations_balance: '0',
stats: {
num_txns: 1,
},
} satisfies Account,
}),
})
await page.waitForTimeout(100)
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/transfer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { mockApi } from '../utils/mockApi'

test.beforeEach(async ({ page }) => {
await warnSlowApi(page)
await mockApi(page, 123)
await mockApi(page, '123000000000')

await page.goto('/open-wallet/private-key')
await fillPrivateKeyWithoutPassword(page, {
Expand Down
8 changes: 4 additions & 4 deletions playwright/tests/validators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { expectNoErrorsInConsole } from '../utils/expectNoErrorsInConsole'

test.beforeEach(async ({ page }) => {
await warnSlowApi(page)
await mockApi(page, 500000000000)
await mockApi(page, '500000000000')
// Unmock validators list API
await page.unroute('**/validator/list?*')
await page.unroute('**/consensus/validators')
await expectNoErrorsInConsole(page, {
ignoreError: message => {
// Some validator icons need authentication
Expand Down Expand Up @@ -38,8 +38,8 @@ test.describe('Validators', () => {

await page.getByRole('link', { name: 'Stake' }).click()
// Wait for validators to be shown, then scroll to them to trigger lazy loading.
await expect(page.getByText('Everstake')).toBeVisible()
await page.getByText('Everstake').scrollIntoViewIfNeeded()
await expect(page.getByText('stakefish')).toBeVisible()
await page.getByText('stakefish').scrollIntoViewIfNeeded()
await (await someValidatorIconPromise).finished()
// Expect no errors.
})
Expand Down

0 comments on commit 2d11fb1

Please sign in to comment.