-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathlogin.spec.ts
133 lines (97 loc) · 4 KB
/
login.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { exec, execSync } 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';
import { expectDisconnected } from '../../shared/tunnel-state';
// This test expects the daemon to be logged out.
// Env parameters:
// `ACCOUNT_NUMBER`: Account number to use when logging in
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('Login failed');
await expect(subtitle).toHaveText('Invalid account number');
await 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');
expect(await util.waitForNavigation(async () => {
await page.getByText('Create account').click();
await expect(title).toHaveText('Account created');
await expect(subtitle).toHaveText('Logged in');
})).toEqual(RoutePath.expired);
const outOfTimeTitle = page.getByTestId('title');
await expect(outOfTimeTitle).toHaveText('Congrats!');
const inputValue = await page.getByTestId('account-number').textContent();
expect(inputValue).toHaveLength(19);
accountNumber = inputValue!.replaceAll(' ', '');
});
test('App should become logged 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.fill(process.env.ACCOUNT_NUMBER!);
expect(await util.waitForNavigation(async () => {
await loginInput.press('Enter');
await expect(title).toHaveText('Logged in');
await expect(subtitle).toHaveText('Valid account number');
})).toEqual(RoutePath.main);
await expectDisconnected(page);
});
test('App should log out', async () => {
expect(await util.waitForNavigation(() => {
void page.getByTestId('account-button').click();
})).toEqual(RoutePath.account);
expect(await util.waitForNavigation(() => {
void page.getByText('Log out').click();
})).toEqual(RoutePath.login);
const title = page.locator('h1')
const subtitle = page.getByTestId('subtitle');
await expect(title).toHaveText('Login');
await expect(subtitle).toHaveText('Enter your account number');
});
test('App should log in to expired account', 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(accountNumber);
expect(await util.waitForNavigation(async () => {
await loginInput.press('Enter');
})).toEqual(RoutePath.expired);
const outOfTimeTitle = page.getByTestId('title');
await expect(outOfTimeTitle).toHaveText('Out of time');
execSync('mullvad account logout');
});
function getInput(page: Page): Locator {
return page.getByPlaceholder('0000 0000 0000 0000');
}