Skip to content

Commit 16fefa9

Browse files
committed
frontend/tests: add tests.
Added tests for username change, password change, connecting to charger after password change.
1 parent ecf1dcf commit 16fefa9

File tree

4 files changed

+76
-24
lines changed

4 files changed

+76
-24
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import test, { expect } from "@playwright/test";
2-
import { login, testPassword, testUser1Email } from "../tests/common";
2+
import { login, testPassword2, testUser2Email } from "../tests/common";
33

44
test('delete account', async ({ page }) => {
5-
await login(page, testUser1Email, testPassword);
5+
await login(page, testUser2Email, testPassword2);
66

77
await page.getByRole('link', { name: 'User' }).click();
88
await page.getByRole('button', { name: 'Delete account' }).click();
99
await page.getByPlaceholder('Password').click();
10-
await page.getByPlaceholder('Password').fill(testPassword);
10+
await page.getByPlaceholder('Password').fill(testPassword2);
1111
await page.getByPlaceholder('Password').press('Enter');
1212
await expect(page.getByText('LoginRegisterEmail-')).toBeVisible();
1313
});

frontend/pre-test/registration.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test } from "@playwright/test";
2-
import { testDomain, testPassword, testUser1, mailiskClient, mailiskNameSpace, testUserName, testUser1Email } from "../tests/common";
2+
import { testDomain, testPassword1, testUser1, mailiskClient, mailiskNameSpace, testUserName1, testUser1Email } from "../tests/common";
33

44

55
test('register', async ({ page }) => {
@@ -9,9 +9,9 @@ test('register', async ({ page }) => {
99
await page.getByRole('textbox', { name: 'Email-address' }).click();
1010
await page.getByRole('textbox', { name: 'Email-address' }).fill(testUser1Email);
1111
await page.getByPlaceholder('John Doe').click();
12-
await page.getByPlaceholder('John Doe').fill(testUserName);
12+
await page.getByPlaceholder('John Doe').fill(testUserName1);
1313
await page.getByRole('textbox', { name: 'Password' }).click();
14-
await page.getByRole('textbox', { name: 'Password' }).fill(testPassword);
14+
await page.getByRole('textbox', { name: 'Password' }).fill(testPassword1);
1515
await page.getByText('I have read, understood and I am accepting the privacy notice.').click();
1616
await page.getByText('I have read, understood and I am accepting the terms and conditions.').click();
1717
await page.getByRole('button', { name: 'Register' }).click();

frontend/tests/basic.spec.ts

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect, Page } from '@playwright/test';
2-
import { login, testDomain, testPassword, testUser1Email, testUserName, testWallboxDomain, testWallboxUID } from './common';
2+
import { login, mailiskClient, mailiskNameSpace, testDomain, testPassword1, testPassword2, testUser1Email, testUser2, testUser2Email, testUserName1, testUserName2, testWallboxDomain, testWallboxUID } from './common';
33

44
test('has title', async ({ page }) => {
55
await page.goto(testDomain);
@@ -9,14 +9,14 @@ test('has title', async ({ page }) => {
99
});
1010

1111
test('login', async ({ page }) => {
12-
await login(page, testUser1Email, testPassword);
12+
await login(page, testUser1Email, testPassword1);
1313
});
1414

1515

1616
test('show user page', async ({ page }) => {
17-
await login(page, testUser1Email, testPassword);
17+
await login(page, testUser1Email, testPassword1);
1818
await page.getByRole('link', { name: 'User' }).click();
19-
await expect(page.getByLabel('Name')).toHaveValue(testUserName);
19+
await expect(page.getByLabel('Name')).toHaveValue(testUserName1);
2020
});
2121

2222
test('invalid register form', async ({ page }) => {
@@ -39,12 +39,12 @@ test('charger lifecycle', async ({ page }) => {
3939
await page.getByLabel('Email ad­dress').click();
4040
await page.getByLabel('Email ad­dress').fill(testUser1Email);
4141
await page.getByLabel('Email ad­dress').press('Tab');
42-
await page.getByLabel('Passwordonly used for the reg').fill(testPassword);
42+
await page.getByLabel('Passwordonly used for the reg').fill(testPassword1);
4343
await page.getByLabel('Passwordonly used for the reg').press('Enter');
4444
await page.getByRole('button', { name: 'Reboot' }).click();
4545

4646
// Connect to charger
47-
await login(page, testUser1Email, testPassword);
47+
await login(page, testUser1Email, testPassword1);
4848
await expect(page.locator('tbody')).toContainText(testWallboxUID);
4949
await expect(page.locator('.bg-success').first()).toBeVisible({timeout: 100_000});
5050
await page.getByRole('button', { name: 'Connect' }).click();
@@ -62,11 +62,11 @@ test('charger lifecycle', async ({ page }) => {
6262
await expect(page.getByText('NameDevice-IDNoteSortAscending')).toBeVisible();
6363
});
6464

65-
test('charger lifecycle with auth token', async ({page}) => {
65+
test('add charger with auth token', async ({page}) => {
6666
test.slow();
6767
await page.waitForTimeout(10_000);
6868

69-
await login(page, testUser1Email, testPassword);
69+
await login(page, testUser1Email, testPassword1);
7070

7171
// Create token
7272
await page.getByRole('link', { name: 'Token' }).click();
@@ -81,7 +81,6 @@ test('charger lifecycle with auth token', async ({page}) => {
8181
await page.getByRole('button', { name: 'Remote Access' }).click();
8282
await page.getByRole('row', { name: 'of 5 users config­ured.' }).getByRole('button').click();
8383
await page.getByLabel('Autho­ri­za­tion method').selectOption('token');
84-
await page.getByLabel('Autho­ri­za­tion token').click();
8584
await page.getByLabel('Autho­ri­za­tion token').fill(token);
8685
await page.getByRole('button', { name: 'Add' }).click();
8786
await page.getByRole('button', { name: 'Reboot' }).click();
@@ -93,18 +92,67 @@ test('charger lifecycle with auth token', async ({page}) => {
9392
await page.getByRole('button', { name: 'Connect' }).click();
9493
await expect(page.locator('#interface').contentFrame().getByRole('heading', { name: 'Status' })).toBeVisible();
9594
await page.locator('#interface').contentFrame().getByRole('button', { name: 'Close remote access' }).click();
95+
});
9696

97-
// Remove charger
97+
test('change username', async ({page}) => {
98+
test.slow();
99+
100+
await login(page, testUser1Email, testPassword1);
101+
102+
await page.getByRole('link', { name: 'User' }).click();
103+
await page.getByLabel('Email-address').fill(testUser2Email);
104+
await page.getByLabel('Name').fill(testUserName2);
105+
await page.getByRole('button', { name: 'Save changes' }).click();
106+
await expect(page.getByLabel('Email-address')).toBeVisible();
107+
await page.getByLabel('Name').click();
108+
await page.getByRole('button', { name: 'Logout', exact: true }).click();
109+
110+
const inbox = await mailiskClient.searchInbox(mailiskNameSpace, { to_addr_prefix: testUser2});
111+
const idx = inbox.data[0].text.indexOf("[https://tf-freddy/api/auth/verify?") + 1;
112+
if (idx === -1) {
113+
throw new Error("Failed to verify email");
114+
}
115+
const url = inbox.data[0].text.substring(idx, inbox.data[0].text.indexOf("]", idx));
116+
const response = await fetch(url);
117+
if (response.status !== 200) {
118+
throw new Error("Failed to verify email");
119+
}
120+
121+
await login(page, testUser2Email, testPassword1);
122+
123+
await page.getByRole('link', { name: 'User' }).click();
124+
await expect(page.getByRole('heading', { name: 'User information' })).toBeVisible();
125+
});
126+
127+
test('change password', async ({page}) => {
128+
await login(page, testUser2Email, testPassword1);
129+
130+
await page.getByRole('link', { name: 'User' }).click();
131+
await page.getByRole('button', { name: 'Change password' }).click();
132+
await page.getByLabel('Current password').click();
133+
await page.getByLabel('Current password').fill(testPassword1);
134+
await page.getByLabel('New password').fill(testPassword2);
135+
await page.getByRole('dialog').getByRole('button', { name: 'Change password' }).click();
136+
await expect(page.getByText('LoginRegisterEmail-')).toBeVisible();
137+
138+
await login(page, testUser2Email, testPassword2);
139+
});
140+
141+
test('connect to charger with new password', async ({page}) => {
142+
await login(page, testUser2Email, testPassword2);
143+
144+
await expect(page.locator('tbody')).toContainText(testWallboxUID);
145+
await expect(page.locator('.bg-success').first()).toBeVisible({timeout: 100_000});
146+
await page.getByRole('button', { name: 'Connect' }).click();
147+
await expect(page.locator('#interface').contentFrame().getByRole('heading', { name: 'Status' })).toBeVisible();
148+
await page.locator('#interface').contentFrame().getByRole('button', { name: 'Close remote access' }).click();
149+
});
150+
151+
test('remove charger', async ({page}) => {
98152
await page.goto(testWallboxDomain + '/#status');
99153
await page.getByRole('button', { name: 'System' }).click();
100154
await page.getByRole('button', { name: 'Remote Access' }).click();
101155
await page.getByRole('row', { name: testUser1Email }).getByRole('button').click();
102156
await page.getByRole('button', { name: 'Save' }).click();
103157
await page.getByRole('button', { name: 'Reboot' }).click();
104-
await page.goto(testDomain);
105-
await expect(page.getByText('NameDevice-IDNoteSortAscending')).toBeVisible();
106-
});
107-
108-
test('change username', async ({page}) => {
109-
110158
});

frontend/tests/common.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import { expect, Page } from "@playwright/test";
22
import { MailiskClient } from "mailisk"
33

44
export const testDomain = process.env.TEST_DOMAIN;
5-
export const testUserName = process.env.TEST_USER_NAME;
6-
export const testPassword = process.env.TEST_PASSWORD;
5+
export const testUserName1 = process.env.TEST_USER_NAME1;
6+
export const testUserName2 = process.env.TEST_USER_NAME2;
7+
export const testPassword1 = process.env.TEST_PASSWORD1;
8+
export const testPassword2 = process.env.TEST_PASSWORD2;
79

810
export const mailiskClient = new MailiskClient({apiKey: process.env.MAILISK_API_KEY});
911
export const mailiskNameSpace = process.env.MAILISK_NAMESPACE;
1012
export const testUser1 = process.env.MAILISK_USER1;
13+
export const testUser2 = process.env.MAILISK_USER2;
1114
export const testUser1Email = `${testUser1}@${mailiskNameSpace}.mailisk.net`;
15+
export const testUser2Email = `${testUser2}@${mailiskNameSpace}.mailisk.net`;
1216
export const testWallboxDomain = process.env.TEST_WALLBOX_DOMAIN;
1317
export const testWallboxUID = process.env.TEST_WALLBOX_UID;
1418

0 commit comments

Comments
 (0)