From 7fdc869c95a7b3349dc66ac861bff3cb7c439dbc Mon Sep 17 00:00:00 2001 From: Horacio Herrera Date: Sat, 26 Aug 2023 01:13:19 +0200 Subject: [PATCH] frontend: desktop e2e onboarding test --- frontend/apps/desktop/package.json | 2 +- frontend/apps/desktop/playwright.config.ts | 2 +- frontend/apps/desktop/src/daemon.ts | 2 + frontend/apps/desktop/test/onboarding.spec.ts | 86 + frontend/apps/desktop/test/test-setup.ts | 52 + frontend/packages/app/package.json | 4 +- .../packages/app/src/pages/onboarding.tsx | 7 +- frontend/packages/shared/package.json | 7 +- frontend/packages/ui/package.json | 4 +- package.json | 2 +- turbo.json | 3 +- yarn.lock | 2149 ++++++++--------- 12 files changed, 1195 insertions(+), 1125 deletions(-) create mode 100755 frontend/apps/desktop/test/onboarding.spec.ts create mode 100755 frontend/apps/desktop/test/test-setup.ts diff --git a/frontend/apps/desktop/package.json b/frontend/apps/desktop/package.json index 60b2c443ad..50438f6ece 100644 --- a/frontend/apps/desktop/package.json +++ b/frontend/apps/desktop/package.json @@ -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", diff --git a/frontend/apps/desktop/playwright.config.ts b/frontend/apps/desktop/playwright.config.ts index da08c1341e..438541a51e 100644 --- a/frontend/apps/desktop/playwright.config.ts +++ b/frontend/apps/desktop/playwright.config.ts @@ -1,7 +1,7 @@ import {PlaywrightTestConfig} from '@playwright/test' const config: PlaywrightTestConfig = { - testDir: './e2e', + testDir: './test', maxFailures: 2, } diff --git a/frontend/apps/desktop/src/daemon.ts b/frontend/apps/desktop/src/daemon.ts index 556484b4c3..f2b940a523 100644 --- a/frontend/apps/desktop/src/daemon.ts +++ b/frontend/apps/desktop/src/daemon.ts @@ -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 diff --git a/frontend/apps/desktop/test/onboarding.spec.ts b/frontend/apps/desktop/test/onboarding.spec.ts new file mode 100755 index 0000000000..3b96e756d1 --- /dev/null +++ b/frontend/apps/desktop/test/onboarding.spec.ts @@ -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() +}) diff --git a/frontend/apps/desktop/test/test-setup.ts b/frontend/apps/desktop/test/test-setup.ts new file mode 100755 index 0000000000..bdfec01e29 --- /dev/null +++ b/frontend/apps/desktop/test/test-setup.ts @@ -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' diff --git a/frontend/packages/app/package.json b/frontend/packages/app/package.json index e2f33af592..70e45240f1 100644 --- a/frontend/packages/app/package.json +++ b/frontend/packages/app/package.json @@ -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", diff --git a/frontend/packages/app/src/pages/onboarding.tsx b/frontend/packages/app/src/pages/onboarding.tsx index 16e539c818..e01f6ef709 100644 --- a/frontend/packages/app/src/pages/onboarding.tsx +++ b/frontend/packages/app/src/pages/onboarding.tsx @@ -244,6 +244,7 @@ function Mnemonics(props: OnboardingStepProps) { fontSize={18} fontWeight="700" display="block" + testID="mnemonics" > {mnemonics.data?.join(', ')} @@ -273,6 +274,7 @@ function Mnemonics(props: OnboardingStepProps) {