Skip to content

Commit 547180b

Browse files
committed
frontend: Refactor namespace playwright for app mode
Signed-off-by: Vincent T <[email protected]>
1 parent 7f3e899 commit 547180b

File tree

3 files changed

+64
-16
lines changed

3 files changed

+64
-16
lines changed

e2e-tests/tests/headlampPage.ts

+19
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ export class HeadlampPage {
5757
expect(await pageContent).toContain(text);
5858
}
5959

60+
// note: must have minikube started before running these
61+
async startFromMainPage() {
62+
await this.page.goto('/');
63+
await this.page.waitForLoadState('load');
64+
65+
console.log('MAIN PAGE');
66+
67+
await this.page.waitForTimeout(5000);
68+
const currentURL = this.page.url();
69+
70+
if (!currentURL.includes('c/minikube')) {
71+
console.log('MORE THAN ONE CLUSTER');
72+
73+
await this.page.waitForSelector('link:has-text("minikube")');
74+
await this.page.getByRole('link', { name: 'minikube' }).click();
75+
await this.page.waitForLoadState('load');
76+
}
77+
}
78+
6079
async navigateTopage(page: string, title: RegExp) {
6180
await this.page.goto(page);
6281
await this.page.waitForLoadState('load');

e2e-tests/tests/namespaces.spec.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@ import { NamespacesPage } from './namespacesPage';
55
test('create a namespace with the minimal editor then delete it', async ({ page }) => {
66
const name = 'testing-e2e';
77
const headlampPage = new HeadlampPage(page);
8-
await headlampPage.authenticate();
9-
10-
// If there's no namespaces permission, then we return
11-
const content = await page.content();
12-
if (!content.includes('Namespaces') || !content.includes('href="/c/main/namespaces')) {
13-
return;
8+
// If we are running in cluster, we need to authenticate
9+
if (process.env.PLAYWRIGHT_TEST_MODE === 'incluster') {
10+
await headlampPage.authenticate();
11+
// If there's no namespaces permission, then we return
12+
const content = await page.content();
13+
if (!content.includes('Namespaces') || !content.includes('href="/c/main/namespaces')) {
14+
return;
15+
}
1416
}
15-
17+
await headlampPage.startFromMainPage();
1618
const namespacesPage = new NamespacesPage(page);
1719
await namespacesPage.navigateToNamespaces();
1820
await namespacesPage.createNamespace(name);
1921
await namespacesPage.deleteNamespace(name);
2022
});
23+
24+
// to do: add test for 'create a namespace with the create namespace button then delete it'

e2e-tests/tests/namespacesPage.ts

+34-9
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ export class NamespacesPage {
44
constructor(private page: Page) {}
55

66
async navigateToNamespaces() {
7-
await this.page.click('span:has-text("Cluster")');
87
await this.page.waitForLoadState('load');
8+
await this.page.waitForSelector('span:has-text("Cluster")');
9+
await this.page.getByText('Cluster', { exact: true }).click();
910
await this.page.waitForSelector('span:has-text("Namespaces")');
1011
await this.page.click('span:has-text("Namespaces")');
1112
await this.page.waitForLoadState('load');
@@ -28,35 +29,59 @@ export class NamespacesPage {
2829
// This makes it a bit more resilient to flakiness.
2930
const pageContent = await this.page.content();
3031
if (pageContent.includes(name)) {
31-
return;
32+
throw new Error(`Test failed: Namespace "${name}" already exists.`);
3233
}
3334

34-
await expect(page.getByRole('button', { name: 'Create' })).toBeVisible();
35-
await page.getByRole('button', { name: 'Create' }).click();
35+
await page.getByText('Create', { exact: true }).click();
3636

3737
await page.waitForLoadState('load');
3838

39-
await expect(page.getByText('Use minimal editor')).toBeVisible();
40-
await page.getByText('Use minimal editor').click();
39+
// this is a workaround for the checked input not having any unique identifier
40+
const checkedSpan = await page.$('span.Mui-checked');
41+
42+
if (!checkedSpan) {
43+
await expect(page.getByText('Use minimal editor')).toBeVisible();
44+
45+
await page.getByText('Use minimal editor').click();
46+
}
4147

4248
await page.waitForLoadState('load');
49+
50+
await page.waitForSelector('textarea[aria-label="yaml Code"]', { state: 'visible' });
51+
52+
await expect(page.getByRole('textbox', { name: 'yaml Code' })).toBeVisible();
4353
await page.fill('textarea[aria-label="yaml Code"]', yaml);
4454

4555
await expect(page.getByRole('button', { name: 'Apply' })).toBeVisible();
4656
await page.getByRole('button', { name: 'Apply' }).click();
4757

48-
await page.waitForSelector(`text=Applied ${name}`);
58+
await page.waitForSelector(`a:has-text("${name}")`);
59+
await expect(page.locator(`a:has-text("${name}")`)).toBeVisible();
4960
}
5061

5162
async deleteNamespace(name) {
5263
const page = this.page;
5364
await page.click('span:has-text("Namespaces")');
5465
await page.waitForLoadState('load');
66+
5567
await page.waitForSelector(`text=${name}`);
5668
await page.click(`a:has-text("${name}")`);
57-
await page.click('button[title="Delete"]');
69+
70+
await page.waitForSelector('button[aria-label="Delete"]');
71+
await page.click('button[aria-label="Delete"]');
72+
73+
await page.waitForLoadState('load');
74+
5875
await page.waitForSelector('text=Are you sure you want to delete this item?');
76+
await page.waitForSelector('button:has-text("Yes")');
77+
78+
await page.waitForLoadState('load');
79+
5980
await page.click('button:has-text("Yes")');
60-
await page.waitForSelector(`text=Deleted item ${name}`);
81+
82+
await page.waitForSelector('h1:has-text("Namespaces")');
83+
await page.waitForSelector('td:has-text("Terminating")');
84+
85+
await expect(page.locator(`a:has-text("${name}")`)).toBeHidden();
6186
}
6287
}

0 commit comments

Comments
 (0)