Skip to content

Commit 18ce278

Browse files
authored
Merge pull request #1798 from headlamp-k8s/e2e-pagination-test
e2e-tests: headlamp.spec: Add test for pagination
2 parents 7ac2edd + 593cb3d commit 18ce278

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

e2e-tests/tests/headlamp.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,20 @@ test('404 page is present', async ({ page }) => {
8686
await headlampPage.authenticate();
8787
await headlampPage.navigateTopage('/404test', /Whoops! This page doesn't exist/);
8888
});
89+
90+
test('pagination goes to next page', async ({ page }) => {
91+
const headlampPage = new HeadlampPage(page);
92+
await headlampPage.authenticate();
93+
94+
const securityPage = new SecurityPage(page);
95+
await securityPage.navigateToSecurity();
96+
await securityPage.clickOnRolesSection();
97+
98+
// Check if there is text "Rows per page" on the page
99+
await headlampPage.checkPageContent('Rows per page');
100+
101+
// Check working of pagination
102+
await headlampPage.checkRows();
103+
});
104+
89105
// --- Headlamp tests end --- //

e2e-tests/tests/headlampPage.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class HeadlampPage {
4747
}
4848

4949
async checkPageContent(text: string) {
50+
await this.page.waitForSelector(`:has-text("${text}")`);
5051
const pageContent = await this.page.content();
5152
expect(pageContent).toContain(text);
5253
}
@@ -97,4 +98,25 @@ export class HeadlampPage {
9798
await this.page.click(`a:has-text("${pluginName}")`);
9899
await this.page.waitForLoadState('load');
99100
}
101+
102+
async checkRows() {
103+
// Get value of rows per page
104+
const rowsDisplayed1 = await this.getRowsDisplayed();
105+
106+
// Click on the next page button
107+
const nextPageButton = this.page.getByTitle('Next page');
108+
await nextPageButton.click();
109+
110+
// Get value of rows per page after clicking next page button
111+
const rowsDisplayed2 = await this.getRowsDisplayed();
112+
113+
// Check if the rows displayed are different
114+
expect(rowsDisplayed1).not.toBe(rowsDisplayed2);
115+
}
116+
117+
async getRowsDisplayed() {
118+
const paginationCaption = this.page.locator("p:has-text(' of ')");
119+
const captionText = await paginationCaption.textContent();
120+
return captionText;
121+
}
100122
}

e2e-tests/tests/securityPage.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,13 @@ export class SecurityPage {
1818
// Wait for the page to load
1919
await this.page.waitForLoadState('load');
2020
}
21+
22+
async clickOnRolesSection() {
23+
// Wait for the Service Accounts tab to load
24+
await this.page.waitForSelector('span:has-text("Roles")');
25+
// Click on the "Service Accounts" section
26+
await this.page.click('span:has-text("Roles")');
27+
// Wait for the page to load
28+
await this.page.waitForLoadState('load');
29+
}
2130
}

0 commit comments

Comments
 (0)