Skip to content

Commit 30b8251

Browse files
committed
frontend: fix tests.
1 parent fc24f2d commit 30b8251

File tree

4 files changed

+55
-29
lines changed

4 files changed

+55
-29
lines changed

frontend/post-test/delete_account.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { login, testPassword2, testUser2Email } from "../tests/common";
44
test('delete account', async ({ page }) => {
55
await login(page, testUser2Email, testPassword2);
66

7-
await page.getByRole('link', { name: 'User' }).click();
7+
await page.getByRole('link', { name: 'Account' }).click();
88
await page.getByRole('button', { name: 'Delete account' }).click();
99
await page.getByPlaceholder('Password').click();
1010
await page.getByPlaceholder('Password').fill(testPassword2);

frontend/pre-test/registration.spec.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,23 @@ test('register', async ({ page }) => {
1717
await page.getByRole('button', { name: 'Register' }).click();
1818
await page.getByText('Close').click();
1919
const inbox = await mailiskClient.searchInbox(mailiskNameSpace, { to_addr_prefix: testUser1, from_timestamp: (Date.now() / 1000) - 5 });
20-
const idx = inbox.data[0].text.indexOf(`[${testDomain}/api/auth/verify?`) + 1;
21-
if (idx === -1) {
22-
throw new Error("Failed to verify email");
20+
21+
if (!inbox.data || inbox.data.length === 0) {
22+
throw new Error("No emails found in inbox");
23+
}
24+
25+
const emailText = inbox.data[0].text;
26+
if (!emailText) {
27+
throw new Error("Email text is empty");
28+
}
29+
30+
const idx = emailText.indexOf(`[${testDomain}/api/auth/verify?`) + 1;
31+
if (idx === 0) {
32+
throw new Error("Failed to find verification URL in email");
2333
}
24-
const url = inbox.data[0].text.substring(idx, inbox.data[0].text.indexOf("]", idx));
34+
const url = emailText.substring(idx, emailText.indexOf("]", idx));
2535
const response = await fetch(url);
2636
if (response.status !== 200) {
2737
throw new Error("Failed to verify email");
2838
}
29-
});
39+
});

frontend/tests/basic.spec.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ test('login', async ({ page }) => {
1313
});
1414

1515

16-
test('show user page', async ({ page }) => {
16+
test('show account page', async ({ page }) => {
1717
await login(page, testUser1Email, testPassword1);
18-
await page.getByRole('link', { name: 'User' }).click();
18+
await page.getByRole('link', { name: 'Account' }).click();
1919
await expect(page.getByLabel('Name')).toHaveValue(testUserName1);
2020
});
2121

@@ -78,8 +78,9 @@ test('add charger with auth token', async ({page}) => {
7878

7979
// Create token
8080
await page.getByRole('link', { name: 'Token' }).click();
81+
await page.getByRole('textbox', { name: 'Name' }).fill('Test');
8182
await page.getByRole('button', { name: 'Create token' }).click();
82-
const token = await page.getByRole('textbox').inputValue();
83+
const token = await page.getByRole('textbox').nth(1).inputValue();
8384

8485
// Add charger
8586
await page.goto(testWallboxDomain);
@@ -102,12 +103,12 @@ test('add charger with auth token', async ({page}) => {
102103
await page.locator('#interface').contentFrame().getByRole('button', { name: 'Close remote access' }).click();
103104
});
104105

105-
test('change username', async ({page}) => {
106+
test('change accountname', async ({page}) => {
106107
test.slow();
107108

108109
await login(page, testUser1Email, testPassword1);
109110

110-
await page.getByRole('link', { name: 'User' }).click();
111+
await page.getByRole('link', { name: 'Account' }).click();
111112
await expect(page.getByLabel('Email-address')).toHaveValue(testUser1Email);
112113
await page.getByLabel('Email-address').fill(testUser2Email);
113114
await page.getByLabel('Name').fill(testUserName2);
@@ -118,26 +119,33 @@ test('change username', async ({page}) => {
118119

119120

120121
const inbox = await mailiskClient.searchInbox(mailiskNameSpace, { to_addr_prefix: testUser2, from_timestamp: (Date.now() / 1000) - 5 });
121-
const idx = inbox.data[0].text.indexOf(`[${testDomain}/api/auth/verify?`) + 1;
122-
if (idx === -1) {
123-
throw new Error("Failed to verify email");
122+
if (!inbox.data || inbox.data.length === 0) {
123+
throw new Error("No emails found in inbox");
124+
}
125+
const firstEmail = inbox.data[0];
126+
if (!firstEmail || !firstEmail.text) {
127+
throw new Error("Email data is invalid");
128+
}
129+
const idx = firstEmail.text.indexOf(`[${testDomain}/api/auth/verify?`) + 1;
130+
if (idx === 0) {
131+
throw new Error("Failed to find verification URL in email");
124132
}
125-
const url = inbox.data[0].text.substring(idx, inbox.data[0].text.indexOf("]", idx));
133+
const url = firstEmail.text.substring(idx, firstEmail.text.indexOf("]", idx));
126134
const response = await fetch(url);
127135
if (response.status !== 200) {
128136
throw new Error("Failed to verify email");
129137
}
130138

131139
await login(page, testUser2Email, testPassword1);
132140

133-
await page.getByRole('link', { name: 'User' }).click();
134-
await expect(page.getByRole('heading', { name: 'User information' })).toBeVisible();
141+
await page.getByRole('link', { name: 'Account' }).click();
142+
await expect(page.getByRole('heading', { name: 'Account information' })).toBeVisible();
135143
});
136144

137145
test('change password', async ({page}) => {
138146
await login(page, testUser2Email, testPassword1);
139147

140-
await page.getByRole('link', { name: 'User' }).click();
148+
await page.getByRole('link', { name: 'Account' }).click();
141149
await page.getByRole('button', { name: 'Change password' }).click();
142150
await page.getByLabel('Current password').click();
143151
await page.getByLabel('Current password').fill(testPassword1);

frontend/tests/common.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
import { expect, Page } from "@playwright/test";
22
import { MailiskClient } from "mailisk"
33

4-
export const testDomain = process.env.TEST_DOMAIN;
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;
4+
function getEnvVar(name: string): string {
5+
const value = process.env[name];
6+
if (!value) {
7+
throw new Error(`Environment variable ${name} is not defined`);
8+
}
9+
return value;
10+
}
11+
12+
export const testDomain = getEnvVar('TEST_DOMAIN');
13+
export const testUserName1 = getEnvVar('TEST_USER_NAME1');
14+
export const testUserName2 = getEnvVar('TEST_USER_NAME2');
15+
export const testPassword1 = getEnvVar('TEST_PASSWORD1');
16+
export const testPassword2 = getEnvVar('TEST_PASSWORD2');
917

10-
export const mailiskClient = new MailiskClient({apiKey: process.env.MAILISK_API_KEY});
11-
export const mailiskNameSpace = process.env.MAILISK_NAMESPACE;
12-
export const testUser1 = process.env.MAILISK_USER1;
13-
export const testUser2 = process.env.MAILISK_USER2;
18+
export const mailiskClient = new MailiskClient({apiKey: getEnvVar('MAILISK_API_KEY')});
19+
export const mailiskNameSpace = getEnvVar('MAILISK_NAMESPACE');
20+
export const testUser1 = getEnvVar('MAILISK_USER1');
21+
export const testUser2 = getEnvVar('MAILISK_USER2');
1422
export const testUser1Email = `${testUser1}@${mailiskNameSpace}.mailisk.net`;
1523
export const testUser2Email = `${testUser2}@${mailiskNameSpace}.mailisk.net`;
16-
export const testWallboxDomain = process.env.TEST_WALLBOX_DOMAIN;
17-
export const testWallboxUID = process.env.TEST_WALLBOX_UID;
24+
export const testWallboxDomain = getEnvVar('TEST_WALLBOX_DOMAIN');
25+
export const testWallboxUID = getEnvVar('TEST_WALLBOX_UID');
1826

1927
export const needCustomCert = process.env.NEED_CUSTOM_CERT === "true";
2028

0 commit comments

Comments
 (0)