Skip to content

Commit

Permalink
chore: add test sequencer
Browse files Browse the repository at this point in the history
  • Loading branch information
guanbinrui committed Jul 1, 2020
1 parent 5c59905 commit 23782fa
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 68 deletions.
2 changes: 1 addition & 1 deletion e2e/commands/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function openSettings(page: Page) {

export async function openSetupCreatePersona(page: Page) {
await page.bringToFront()
await page.goto(`${DASHBOARD_URL}#/setup/create-persona`)
await page.goto(`${DASHBOARD_URL}#/setup/create-persona?noredirect=true`)
await page.waitFor(500)
}

Expand Down
10 changes: 1 addition & 9 deletions e2e/fixtures/persona/persona_backup_alice.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{
"_meta_": { "createdAt": 1585284379295, "maskbookVersion": "1.10.11", "version": 2, "type": "maskbook-backup" },
"grantedHostPermissions": [
"<all_urls>",
"chrome://favicon/*",
"https://facebook.com/*",
"https://m.facebook.com/*",
"https://mobile.twitter.com/*",
"https://twitter.com/*",
"https://www.facebook.com/*"
],
"grantedHostPermissions": ["<all_urls>"],
"personas": [
{
"createdAt": 1584273741400,
Expand Down
10 changes: 1 addition & 9 deletions e2e/fixtures/setup/db_backup_1_persona_0_profile.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{
"_meta_": { "createdAt": 1584276109482, "maskbookVersion": "1.10.10", "version": 2, "type": "maskbook-backup" },
"grantedHostPermissions": [
"<all_urls>",
"chrome://favicon/*",
"https://facebook.com/*",
"https://m.facebook.com/*",
"https://mobile.twitter.com/*",
"https://twitter.com/*",
"https://www.facebook.com/*"
],
"grantedHostPermissions": ["<all_urls>"],
"personas": [
{
"createdAt": 1584273741400,
Expand Down
10 changes: 1 addition & 9 deletions e2e/fixtures/setup/db_backup_1_persona_1_profile.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{
"_meta_": { "createdAt": 1584276109482, "maskbookVersion": "1.10.10", "version": 2, "type": "maskbook-backup" },
"grantedHostPermissions": [
"<all_urls>",
"chrome://favicon/*",
"https://facebook.com/*",
"https://m.facebook.com/*",
"https://mobile.twitter.com/*",
"https://twitter.com/*",
"https://www.facebook.com/*"
],
"grantedHostPermissions": ["<all_urls>"],
"personas": [
{
"createdAt": 1584273741400,
Expand Down
10 changes: 1 addition & 9 deletions e2e/fixtures/setup/db_backup_2_personas_0_profile.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{
"_meta_": { "createdAt": 1584276109482, "maskbookVersion": "1.10.10", "version": 2, "type": "maskbook-backup" },
"grantedHostPermissions": [
"<all_urls>",
"chrome://favicon/*",
"https://facebook.com/*",
"https://m.facebook.com/*",
"https://mobile.twitter.com/*",
"https://twitter.com/*",
"https://www.facebook.com/*"
],
"grantedHostPermissions": ["<all_urls>"],
"personas": [
{
"createdAt": 1584273741400,
Expand Down
10 changes: 1 addition & 9 deletions e2e/fixtures/setup/db_backup_2_personas_2_profiles.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{
"_meta_": { "createdAt": 1584276109482, "maskbookVersion": "1.10.10", "version": 2, "type": "maskbook-backup" },
"grantedHostPermissions": [
"<all_urls>",
"chrome://favicon/*",
"https://facebook.com/*",
"https://m.facebook.com/*",
"https://mobile.twitter.com/*",
"https://twitter.com/*",
"https://www.facebook.com/*"
],
"grantedHostPermissions": ["<all_urls>"],
"personas": [
{
"createdAt": 1584273741400,
Expand Down
21 changes: 3 additions & 18 deletions e2e/integration/setup/NewUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,12 @@ describe(`${SETUP_STORY_URL}-Workflow1A:CoreInit/NewUser`, () => {
// fill & submit the form
const usernameInput = await page.waitFor('[data-testid="username_input"]')
const nextButton = await page.waitFor('[data-testid="next_button"]')
await usernameInput.type('Alice')
await usernameInput.type('alice')
await nextButton.click()
await page.waitFor(500)

// setup spy for new page
const targetSpy = jasmine.createSpy()
page.browser().on('targetcreated', targetSpy)

// click the connect button
const connectButton = await page.waitFor(`[data-testid="connect_button_${sns.name}"]`)
await connectButton.click()
await page.waitFor(500)

// validate spy
expect(targetSpy).toHaveBeenCalled()
expect(
targetSpy.calls
.argsFor(0)[0] // target
.url()
.includes(sns.name),
).toBeTruthy()
// evaluate network
expect((await page.evaluate(() => location.hash)).includes('#/setup/connect-network')).toBeTruthy()
})
}
})
5 changes: 3 additions & 2 deletions e2e/support/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export async function newPage(page: Page) {
}

export async function setupPage(page: Page) {
// wait for default option page to be opened
await page.waitFor(500)

// set a modern viewport
await page.setViewport({ width: 1366, height: 768 })

// wait for default option page to be opened
await page.waitFor(500)
}

Expand Down
1 change: 1 addition & 0 deletions jest-e2e.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
preset: 'jest-puppeteer',
testRegex: ['/e2e/integration/.*\\.[jt]sx?$'],
testTimeout: 60 * 1000,
testSequencer: './jest-e2e.sequencer.js',
transform: {
...tsjPreset.transform,
},
Expand Down
12 changes: 12 additions & 0 deletions jest-e2e.sequencer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const Sequencer = require('@jest/test-sequencer').default

class AlphabeticalSequencer extends Sequencer {
sort(tests) {
// Test structure information
// https://github.com/facebook/jest/blob/6b8b1404a1d9254e7d5d90a8934087a9c9899dab/packages/jest-runner/src/types.ts#L17-L21
const copyTests = Array.from(tests)
return copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1))
}
}

module.exports = AlphabeticalSequencer
7 changes: 6 additions & 1 deletion src/extension/options-page/DashboardRouters/Personas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ export default function DashboardPersonasRouter() {
<Button color="primary" variant="outlined" onClick={openImportPersona}>
{t('import')}
</Button>,
<Button color="primary" variant="contained" onClick={openCreatePersona} endIcon={<AddCircleIcon />}>
<Button
color="primary"
variant="contained"
onClick={openCreatePersona}
endIcon={<AddCircleIcon />}
data-testid="create_button">
{t('create_persona')}
</Button>,
],
Expand Down
7 changes: 6 additions & 1 deletion src/extension/options-page/DashboardRouters/Wallets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ export default function DashboardWalletsRouter() {
<Button color="primary" variant="outlined" onClick={openWalletImport}>
{t('import')}
</Button>,
<Button color="primary" variant="contained" onClick={openWalletCreate} endIcon={<AddCircleIcon />}>
<Button
color="primary"
variant="contained"
onClick={openWalletCreate}
endIcon={<AddCircleIcon />}
data-testid="create_button">
{t('create_wallet')}
</Button>,
]}>
Expand Down

0 comments on commit 23782fa

Please sign in to comment.