diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2023-03-24 09:28:25 +0100 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2023-03-27 10:18:28 +0200 |
| commit | 7900bee0590832c0dfdb922b4b71510ead8813e5 (patch) | |
| tree | 8d0ebbd33f7c2cc5c3c4fc0c6d6adddb2ecb1339 /gui/test | |
| parent | 872e02022ad4fc43441c398d3e7ac3e14c67e0fb (diff) | |
| download | mullvadvpn-7900bee0590832c0dfdb922b4b71510ead8813e5.tar.xz mullvadvpn-7900bee0590832c0dfdb922b4b71510ead8813e5.zip | |
Add login tests
Diffstat (limited to 'gui/test')
| -rw-r--r-- | gui/test/e2e/installed/requires-input/login.spec.ts | 32 | ||||
| -rw-r--r-- | gui/test/e2e/installed/state-dependent/login.spec.ts | 94 |
2 files changed, 94 insertions, 32 deletions
diff --git a/gui/test/e2e/installed/requires-input/login.spec.ts b/gui/test/e2e/installed/requires-input/login.spec.ts deleted file mode 100644 index 2ff0fd576c..0000000000 --- a/gui/test/e2e/installed/requires-input/login.spec.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { expect, test } from '@playwright/test'; -import { Page } from 'playwright'; -import { RoutePath } from '../../../../src/renderer/lib/routes'; -import { TestUtils } from '../../utils'; -import { assertDisconnected } from '../../shared/tunnel-state'; - -import { startInstalledApp } from '../installed-utils'; - -// This test expects the daemon to be logged out and then log in. - -let page: Page; -let util: TestUtils; - -test.beforeAll(async () => { - ({ page, util } = await startInstalledApp()); -}); - -test.afterAll(async () => { - await page.close(); -}); - -// Disables timeout since it's handled by the rust test -test.setTimeout(0); - -test('App should go from login view to main view when daemon logs in', async () => { - expect(await util.currentRoute()).toEqual(RoutePath.login); - - // Waiting for the daemon to log in - expect(await util.waitForNavigation()).toEqual(RoutePath.main); - - await assertDisconnected(page); -}); diff --git a/gui/test/e2e/installed/state-dependent/login.spec.ts b/gui/test/e2e/installed/state-dependent/login.spec.ts new file mode 100644 index 0000000000..21568a6130 --- /dev/null +++ b/gui/test/e2e/installed/state-dependent/login.spec.ts @@ -0,0 +1,94 @@ +import { exec } from 'child_process'; +import { expect, test } from '@playwright/test'; +import { Locator, Page } from 'playwright'; +import { RoutePath } from '../../../../src/renderer/lib/routes'; +import { TestUtils } from '../../utils'; + +import { startInstalledApp } from '../installed-utils'; + +// This test expects the daemon to be logged out. + +let page: Page; +let util: TestUtils; + +let accountNumber: string; + +test.beforeAll(async () => { + ({ page, util } = await startInstalledApp()); +}); + +test.afterAll(async () => { + await page.close(); +}); + +test('App should fail to login', async () => { + expect(await util.currentRoute()).toEqual(RoutePath.login); + + const title = page.locator('h1') + const subtitle = page.getByTestId('subtitle'); + const loginInput = getInput(page); + + await expect(title).toHaveText('Login'); + await expect(subtitle).toHaveText('Enter your account number'); + + await loginInput.fill('1234 1234 1324 1234'); + await loginInput.press('Enter'); + + await expect(title).toHaveText('Logging in...'); + await expect(subtitle).toHaveText('Checking account number'); + await expect(title).toHaveText('Login failed'); + await expect(subtitle).toHaveText('Invalid account number'); + + loginInput.fill(''); +}); + +test('App should create account', async () => { + expect(await util.currentRoute()).toEqual(RoutePath.login); + + const title = page.locator('h1') + const subtitle = page.getByTestId('subtitle'); + + await page.getByText('Create account').click(); + await expect(title).toHaveText('Creating account...'); + await expect(subtitle).toHaveText('Please wait'); + + await expect(title).toHaveText('Account created'); + await expect(subtitle).toHaveText('Logged in'); + + expect(await util.waitForNavigation()).toEqual(RoutePath.main); + + const inputValue = await page.getByTestId('account-number').textContent(); + expect(inputValue).toHaveLength(19); + accountNumber = inputValue!.replaceAll(' ', ''); +}); + +test('App should log out', async () => { + expect(await util.waitForNavigation(() => { + exec('mullvad account logout'); + })).toEqual(RoutePath.login); +}); + +test('App should log in', async () => { + expect(await util.currentRoute()).toEqual(RoutePath.login); + + const title = page.locator('h1') + const subtitle = page.getByTestId('subtitle'); + const loginInput = getInput(page); + + await expect(title).toHaveText('Login'); + await expect(subtitle).toHaveText('Enter your account number'); + + await loginInput.type(accountNumber); + await loginInput.press('Enter'); + + await expect(title).toHaveText('Logging in...'); + await expect(subtitle).toHaveText('Checking account number'); + await expect(title).toHaveText('Logged in'); + await expect(subtitle).toHaveText('Valid account number'); + + expect(await util.waitForNavigation()).toEqual(RoutePath.main); +}); + +function getInput(page: Page): Locator { + return page.getByPlaceholder('0000 0000 0000 0000'); +} |
