forked from blockscout/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Playwright tests refactoring, pt.2 (blockscout#1787)
* create storageState fixture * remove auth fixture * renaming * migrate bridge tokens and shibarium rollup tests * migrate to common app config * update screenshots * re-implement fixtures for mocking envs, features and auth state * update screenshot
- Loading branch information
Showing
45 changed files
with
775 additions
and
1,617 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import type { BrowserContext } from '@playwright/test'; | ||
import type { BrowserContext, TestFixture } from '@playwright/test'; | ||
|
||
import config from 'configs/app'; | ||
import * as cookies from 'lib/cookies'; | ||
import { domain } from 'playwright/utils/app'; | ||
|
||
export default function authFixture(context: BrowserContext) { | ||
context.addCookies([ { name: cookies.NAMES.API_TOKEN, value: 'foo', domain, path: '/' } ]); | ||
export function authenticateUser(context: BrowserContext) { | ||
context.addCookies([ { name: cookies.NAMES.API_TOKEN, value: 'foo', domain: config.app.host, path: '/' } ]); | ||
} | ||
|
||
export const contextWithAuth: TestFixture<BrowserContext, { context: BrowserContext }> = async({ context }, use) => { | ||
authenticateUser(context); | ||
use(context); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { TestFixture, Page } from '@playwright/test'; | ||
|
||
import type { WalletProvider } from 'types/web3'; | ||
|
||
export type InjectMetaMaskProvider = () => Promise<void>; | ||
|
||
const fixture: TestFixture<InjectMetaMaskProvider, { page: Page }> = async({ page }, use) => { | ||
await use(async() => { | ||
await page.evaluate(() => { | ||
window.ethereum = { | ||
isMetaMask: true, | ||
_events: {}, | ||
} as WalletProvider; | ||
}); | ||
}); | ||
}; | ||
|
||
export default fixture; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { TestFixture, Page } from '@playwright/test'; | ||
|
||
import config from 'configs/app'; | ||
import { buildExternalAssetFilePath } from 'configs/app/utils'; | ||
|
||
export type MockConfigResponseFixture = (envName: string, envValue: string, content: string, isImage?: boolean) => Promise<void>; | ||
|
||
const fixture: TestFixture<MockConfigResponseFixture, { page: Page }> = async({ page }, use) => { | ||
await use(async(envName, envValue, content, isImage) => { | ||
const url = config.app.baseUrl + buildExternalAssetFilePath(envName, envValue); | ||
|
||
if (isImage) { | ||
await page.route(url, (route) => route.fulfill({ | ||
status: 200, | ||
path: content, | ||
})); | ||
} else { | ||
await page.route(url, (route) => route.fulfill({ | ||
status: 200, | ||
body: content, | ||
})); | ||
} | ||
|
||
}); | ||
}; | ||
|
||
export default fixture; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable max-len */ | ||
import type { TestFixture, Page } from '@playwright/test'; | ||
|
||
export type MockEnvsFixture = (envs: Array<[string, string]>) => Promise<void>; | ||
|
||
const fixture: TestFixture<MockEnvsFixture, { page: Page }> = async({ page }, use) => { | ||
await use(async(envs) => { | ||
for (const [ name, value ] of envs) { | ||
await page.evaluate(({ name, value }) => { | ||
window.localStorage.setItem(name, value); | ||
}, { name, value }); | ||
} | ||
}); | ||
}; | ||
|
||
export default fixture; | ||
|
||
export const ENVS_MAP: Record<string, Array<[string, string]>> = { | ||
shibariumRollup: [ | ||
[ 'NEXT_PUBLIC_ROLLUP_TYPE', 'shibarium' ], | ||
[ 'NEXT_PUBLIC_ROLLUP_L1_BASE_URL', 'https://localhost:3101' ], | ||
], | ||
bridgedTokens: [ | ||
[ 'NEXT_PUBLIC_BRIDGED_TOKENS_CHAINS', '[{"id":"1","title":"Ethereum","short_title":"ETH","base_url":"https://eth.blockscout.com/token/"},{"id":"56","title":"Binance Smart Chain","short_title":"BSC","base_url":"https://bscscan.com/token/"},{"id":"99","title":"POA","short_title":"POA","base_url":"https://blockscout.com/poa/core/token/"}]' ], | ||
[ 'NEXT_PUBLIC_BRIDGED_TOKENS_BRIDGES', '[{"type":"omni","title":"OmniBridge","short_title":"OMNI"},{"type":"amb","title":"Arbitrary Message Bridge","short_title":"AMB"}]' ], | ||
], | ||
userOps: [ | ||
[ 'NEXT_PUBLIC_HAS_USER_OPS', 'true' ], | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* eslint-disable max-len */ | ||
import type { TestFixture, Page } from '@playwright/test'; | ||
|
||
export type MockFeaturesFixture = (features: Array<[string, unknown]>) => Promise<void>; | ||
|
||
const fixture: TestFixture<MockFeaturesFixture, { page: Page }> = async({ page }, use) => { | ||
await use(async(features) => { | ||
for (const [ name, value ] of features) { | ||
await page.evaluate(({ name, value }) => { | ||
window.localStorage.setItem(`pw_feature:${ name }`, JSON.stringify(value)); | ||
}, { name, value }); | ||
} | ||
}); | ||
}; | ||
|
||
export default fixture; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
export const url = `${ process.env.NEXT_PUBLIC_APP_PROTOCOL }://${ process.env.NEXT_PUBLIC_APP_HOST }:${ process.env.NEXT_PUBLIC_APP_PORT }`; | ||
|
||
export const domain = process.env.NEXT_PUBLIC_APP_HOST; | ||
|
||
export const socketPort = 3200; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.