Skip to content

Commit

Permalink
frontend: desktop e2e onboarding test
Browse files Browse the repository at this point in the history
  • Loading branch information
horacioh committed Aug 25, 2023
1 parent cf0031d commit 7fdc869
Show file tree
Hide file tree
Showing 12 changed files with 1,195 additions and 1,125 deletions.
2 changes: 1 addition & 1 deletion frontend/apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"main": ".vite/build/main.js",
"scripts": {
"dev": "electron-forge start",
"e2e": "playwright test",
"test": "playwright test",
"format": "prettier \"**/*.{ts,tsx,md,mdx,json}\" --check --ignore-path ../../../.prettierignore",
"lint": "echo TODO",
"make": "electron-forge make",
Expand Down
2 changes: 1 addition & 1 deletion frontend/apps/desktop/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {PlaywrightTestConfig} from '@playwright/test'

const config: PlaywrightTestConfig = {
testDir: './e2e',
testDir: './test',
maxFailures: 2,
}

Expand Down
2 changes: 2 additions & 0 deletions frontend/apps/desktop/src/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const prodDaemonBinaryPath = join(

const userDataDir = join(app.getPath('userData'), 'daemon')

console.log(`== ~ userDataDir:`, userDataDir)

let goDaemonExecutablePath =
process.env.NODE_ENV == 'development'
? devDaemonBinaryPath
Expand Down
86 changes: 86 additions & 0 deletions frontend/apps/desktop/test/onboarding.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {Page, test, expect} from '@playwright/test'
import {alias, bio, electronApp} from './test-setup'

let page: Page

test('Onboarding', async () => {
page = await electronApp.firstWindow()

await page.waitForSelector('[role=heading]')
// const text = await page.$eval(
// '[data-testid="step-title"]',
// (el) => el.textContent,
// )
const welcomeTitles = await page.getByRole('heading').allTextContents()
expect(welcomeTitles).toEqual(['Welcome to', 'Mintter'])

await page.getByRole('button', {name: 'NEXT'}).click()

// Mnemonics Step
const mnemonicsTitles = await page.getByRole('heading').allTextContents()
expect(mnemonicsTitles).toEqual(['Your Keys.', 'Your Data.'])
const mnemonics = await page.getByTestId('mnemonics')
expect(mnemonics).toBeVisible()

// check prev button
expect(await page.getByRole('button', {name: 'PREV'})).toBeVisible()
expect(await page.getByRole('button', {name: 'PREV'})).not.toBeDisabled()

// check if the mnemonics are the correct amount of words
let text = (await mnemonics.allTextContents())[0]
let words = text?.split(', ')
expect(words).toHaveLength(12)

// toggle own seed textarea
await page.getByTestId('ownseed-btn').click()
const textarea = await page.getByPlaceholder('food barrel buzz ...')
expect(textarea).toBeVisible()
await page.getByTestId('ownseed-btn').click({force: true})

// continue to next step
await page.getByRole('button', {name: 'NEXT'}).click()

// check Profile step title
const profileTitles = await page.getByRole('heading').allTextContents()
expect(profileTitles).toEqual(['Profile', 'Information'])

// check profile alias input
let inputAlias = await page.getByPlaceholder(
`Readable alias or username. Doesn't have to be unique.`,
)
expect(inputAlias).toBeVisible()
await inputAlias.type(alias)

// check profile bio input
let inputBio = await page.getByPlaceholder(`A little bit about yourself...`)
expect(inputBio).toBeVisible()
await inputBio.type(bio)

// check prev button
expect(await page.getByRole('button', {name: 'PREV'})).toBeVisible()
expect(await page.getByRole('button', {name: 'PREV'})).not.toBeDisabled()

// continue to next step
await page.getByRole('button', {name: 'NEXT'}).click()

await page.waitForTimeout(10)
// check Analytics step title
const analyticsTitles = await page.getByRole('heading').allTextContents()
expect(analyticsTitles).toEqual(['Crash', 'Analytics'])

// check prev button
expect(await page.getByRole('button', {name: 'PREV'})).toBeVisible()
expect(await page.getByRole('button', {name: 'PREV'})).not.toBeDisabled()

// continue to next step
await page.getByRole('button', {name: 'NEXT'}).click()
// await page.waitForTimeout(10000)

// check finish step
await page.waitForTimeout(10)
// check Analytics step title
const finishTitles = await page.getByRole('heading').allTextContents()
expect(finishTitles).toEqual(['You are Ready!'])

await page.getByRole('button', {name: 'Open Mintter App'}).click()
})
52 changes: 52 additions & 0 deletions frontend/apps/desktop/test/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
ElectronApplication,
Page,
_electron as electron,
expect,
test,
} from '@playwright/test'
import path from 'path'
import {findLatestBuild, parseElectronApp} from 'electron-playwright-helpers'

let electronApp: ElectronApplication

test.beforeAll(async () => {
// remove the app data:

// find the latest build in the out directory
const latestBuild = findLatestBuild()

// parse the directory and find paths and other info
const appInfo = parseElectronApp(latestBuild)

// set the CI environment variable to true
process.env.CI = 'e2e'

electronApp = await electron.launch({
args: [appInfo.main],
executablePath: appInfo.executable,
})

electronApp.on('window', async (page) => {
const filename = page.url()?.split('/').pop()

// capture errors
page.on('pageerror', (error) => {
console.error(error)
})
// capture console messages
page.on('console', (msg) => {
console.log(msg.text())
})
})
})

test.afterAll(async () => {
// close app
await electronApp.close()
})

export {electronApp}

export const alias = 'test alias'
export const bio = 'some random test bio'
4 changes: 3 additions & 1 deletion frontend/packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"private": true,
"scripts": {
"lint": "eslint .",
"format": "prettier \"**/*.{ts,tsx,md,mdx,json}\" --check --ignore-path ../../../.prettierignore"
"format": "prettier \"**/*.{ts,tsx,md,mdx,json}\" --check --ignore-path ../../../.prettierignore",
"test": "echo TODO",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@bufbuild/connect-web": "0.7.0",
Expand Down
7 changes: 5 additions & 2 deletions frontend/packages/app/src/pages/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ function Mnemonics(props: OnboardingStepProps) {
fontSize={18}
fontWeight="700"
display="block"
testID="mnemonics"
>
{mnemonics.data?.join(', ')}
</SizableText>
Expand Down Expand Up @@ -273,6 +274,7 @@ function Mnemonics(props: OnboardingStepProps) {
<Button
size="$2"
theme="green"
testID="ownseed-btn"
onPress={() => {
if (useOwnSeed) {
// refetch here is so that user always sees new words when they click "generate a new seed"
Expand Down Expand Up @@ -346,11 +348,12 @@ function Profile(props: OnboardingStepProps) {
borderColor="transparent"
borderWidth={0}
>
<Label size="$2" htmlFor="alias">
<Label size="$2" htmlFor="alias" role="complementary">
Alias
</Label>
<Input
id="alias"
testID="input-alias"
onChangeText={(val) => (submitValue.current.alias = val)}
placeholder="Readable alias or username. Doesn't have to be unique."
/>
Expand All @@ -361,7 +364,7 @@ function Profile(props: OnboardingStepProps) {
borderColor="transparent"
borderWidth={0}
>
<Label size="$2" htmlFor="bio">
<Label size="$2" htmlFor="bio" role="complementary">
Bio
</Label>
<TextArea
Expand Down
7 changes: 2 additions & 5 deletions frontend/packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
"version": "0.1.0",
"main": "src/index.ts",
"scripts": {
"dev": "tsc -w",
"build": "tsc ",
"test": "vitest --run",
"test:watch": "vitest --watch",
"lint": "eslint .",
"format": "prettier \"**/*.{ts,tsx,md,mdx,json}\" --check --ignore-path ../../../.prettierignore",
"validate": "yarn lint && yarn test"
"test": "echo TODO",
"typecheck": "tsc --noEmit"
},
"keywords": [],
"author": "",
Expand Down
4 changes: 3 additions & 1 deletion frontend/packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"build": "tamagui-build",
"format": "prettier \"**/*.{ts,tsx,md,mdx,json}\" --check --ignore-path ../../../.prettierignore",
"clean": "tamagui-build clean",
"clean:build": "tamagui-build clean:build"
"clean:build": "tamagui-build clean:build",
"test": "echo TODO",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@tamagui/animations-react-native": "1.52.5",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"lint:fix": "turbo lint --continue -- --fix --cache --cache-location 'node_modules/.cache/.eslintcache'",
"format": "turbo format --continue -- --cache --cache-location='node_modules/.cache/.prettiercache'",
"format:fix": "turbo format --continue -- --write --cache --cache-location='node_modules/.cache/.prettiercache'",
"test": "yarn workspaces foreach run test",
"test": "turbo test --continue",
"validate": "yarn lint && yarn format",
"site": "yarn workspace @mintter/site dev",
"site:prod": "yarn workspace @mintter/site build",
Expand Down
3 changes: 2 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dev": {
"cache": false,
"persistent": true
}
},
"test": {}
}
}
Loading

0 comments on commit 7fdc869

Please sign in to comment.