Skip to content

Commit e2bb8ae

Browse files
authored
Improve the tests (#883)
1 parent ba8d181 commit e2bb8ae

File tree

4 files changed

+43
-20
lines changed

4 files changed

+43
-20
lines changed

e2e/page-objects/team-leaderboards-page.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,24 @@ export class TeamLeaderboardsPage extends BasePage {
209209
return await this.paginationInfo.innerText();
210210
}
211211

212+
/**
213+
* Get the total number of records from pagination info
214+
*/
215+
async getTotalRecordCount(): Promise<number> {
216+
const paginationText = await this.getPaginationInfo();
217+
// Extract total from "Showing X - Y of Z teams"
218+
const match = paginationText.match(/of (\d+) teams/);
219+
return match ? parseInt(match[1], 10) : 0;
220+
}
221+
222+
/**
223+
* Get the currently selected records per page value
224+
*/
225+
async getSelectedRecordsPerPage(): Promise<string> {
226+
// The select component shows the selected value in its button
227+
return await this.recordsPerPageSelect.locator("input").inputValue();
228+
}
229+
212230
/**
213231
* Click on a player name in the table
214232
*/
@@ -286,11 +304,15 @@ export class TeamLeaderboardsPage extends BasePage {
286304
.evaluate((el) => {
287305
return window.getComputedStyle(el).color;
288306
});
289-
// This is a basic check - you might need to adjust based on actual color values
290-
if (expectedColor === "green") {
291-
expect(color).toContain("green");
292-
} else {
293-
expect(color).toContain("red");
294-
}
307+
308+
// Normalize the computed color to RGB format for comparison
309+
// Expected colors: green = rgb(64, 192, 87) or similar, red = rgb(250, 82, 82) or similar
310+
// The actual RGB values may vary based on the theme, so we check the pattern
311+
const colorMapping = {
312+
green: /rgb\(\s*\d+,\s*1[5-9]\d|2\d\d,\s*\d+\s*\)/i, // Green has high G value (150+)
313+
red: /rgb\(\s*2[0-5]\d,\s*\d{1,2},\s*\d{1,2}\s*\)/i, // Red has high R value (200+)
314+
};
315+
316+
expect(color).toMatch(colorMapping[expectedColor]);
295317
}
296318
}

e2e/regression/player-export-api.spec.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test.describe("Player Export API", () => {
2020
expect(data.error).toBe("error parsing the profileIDs data");
2121
});
2222

23-
test("should return 400 when types parameter is not a string", async ({ request }) => {
23+
test("should return 400 when types contains invalid game types", async ({ request }) => {
2424
const profileIDs = JSON.stringify([1, 2]);
2525
const types = JSON.stringify(["1v1", "5v5"]);
2626
const response = await request.get(`${baseUrl}?profileIDs=${profileIDs}&types=${types}`);
@@ -41,16 +41,6 @@ test.describe("Player Export API", () => {
4141
expect(data.error).toBe("error parsing the types data");
4242
});
4343

44-
test("should return 400 when types contains invalid game types", async ({ request }) => {
45-
const profileIDs = JSON.stringify([1, 2]);
46-
const types = JSON.stringify(["1v1", "5v5"]);
47-
const response = await request.get(`${baseUrl}?profileIDs=${profileIDs}&types=${types}`);
48-
49-
expect(response.status()).toBe(400);
50-
const data = await response.json();
51-
expect(data.error).toBe("parsedTypes contains invalid data");
52-
});
53-
5444
test("should return 400 when requesting more than 50 records", async ({ request }) => {
5545
const profileIDs = JSON.stringify(Array.from({ length: 51 }, (_, i) => i + 1));
5646
const response = await request.get(`${baseUrl}?profileIDs=${profileIDs}`);

e2e/regression/team-leaderboards.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,24 @@ test.describe("Team Leaderboards Page", () => {
7878
await teamLeaderboardsPage.waitForTableLoad();
7979

8080
const rowCountBefore = await teamLeaderboardsPage.getRowCount();
81+
const totalRecords = await teamLeaderboardsPage.getTotalRecordCount();
8182

8283
await teamLeaderboardsPage.selectRecordsPerPage("50");
8384

85+
// Verify the page size control actually changed to "50"
86+
const selectedPageSize = await teamLeaderboardsPage.getSelectedRecordsPerPage();
87+
expect(selectedPageSize).toBe("50");
88+
8489
const rowCountAfter = await teamLeaderboardsPage.getRowCount();
8590

86-
// Row count should change
87-
expect(rowCountAfter).not.toBe(rowCountBefore);
91+
// Assert the displayed row count equals Math.min(totalRecords, 50)
92+
const expectedRowCount = Math.min(totalRecords, 50);
93+
expect(rowCountAfter).toBe(expectedRowCount);
94+
95+
// Also verify that either the row count changed OR total records is <= 50
96+
if (totalRecords > 50) {
97+
expect(rowCountAfter).not.toBe(rowCountBefore);
98+
}
8899
});
89100
});
90101

pages/api/playerExport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
4444
}
4545

4646
// Parse and validate types
47-
let parsedTypes: ["1v1", "2v2", "3v3", "4v4"];
47+
let parsedTypes: Array<"1v1" | "2v2" | "3v3" | "4v4">;
4848

4949
if (types !== undefined && typeof types !== "string") {
5050
return res.status(400).json({ error: "types contains invalid data" });

0 commit comments

Comments
 (0)