Skip to content

Commit 99411af

Browse files
committed
Fixed janky test
1 parent 61227d6 commit 99411af

1 file changed

Lines changed: 19 additions & 22 deletions

File tree

e2e/tests/functional/planning/timelistControlledClock.e2e.spec.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ const examplePlanSmall1 = JSON.parse(
5252
);
5353

5454
const TIME_TO_FROM_COLUMN = 2;
55-
const HEADER_ROW = 0;
56-
const NUM_COLUMNS = 5;
5755

5856
/**
5957
* The regular expression used to parse the countdown string.
@@ -125,26 +123,26 @@ test.describe('Time List with controlled clock @clock', () => {
125123
page
126124
}) => {
127125
const countUpCells = [
128-
getTimeListCellByIndex(page, 1, TIME_TO_FROM_COLUMN),
129-
getTimeListCellByIndex(page, 2, TIME_TO_FROM_COLUMN)
126+
getTimeListCellByIndex(page, 2, TIME_TO_FROM_COLUMN),
127+
getTimeListCellByIndex(page, 3, TIME_TO_FROM_COLUMN)
130128
];
131129
const countdownCells = [
132-
getTimeListCellByIndex(page, 3, TIME_TO_FROM_COLUMN),
133-
getTimeListCellByIndex(page, 4, TIME_TO_FROM_COLUMN)
130+
getTimeListCellByIndex(page, 4, TIME_TO_FROM_COLUMN),
131+
getTimeListCellByIndex(page, 5, TIME_TO_FROM_COLUMN)
134132
];
135133

136134
// Verify that the countdown cells are counting down
137135
for (let i = 0; i < countdownCells.length; i++) {
138136
await test.step(`Countdown cell ${i + 1} counts down`, async () => {
139137
const countdownCell = countdownCells[i];
140138
// Get the initial countdown timestamp object
141-
const beforeCountdown = await getAndAssertCountdownOrUpObject(page, i + 3);
142-
// should not have a '-' sign
143-
await expect(countdownCell).not.toHaveText('-');
139+
const beforeCountdown = await getAndAssertCountdownOrUpObject(page, i + 4);
140+
// should have a '-' sign BECAUSE IT'S A COUNTDOWN
141+
await expect(countdownCell).toContainText('-');
144142
// Wait until it changes
145-
await expect(countdownCell).not.toHaveText(beforeCountdown.toString());
143+
await expect(countdownCell).not.toContainText(beforeCountdown.toString());
146144
// Get the new countdown timestamp object
147-
const afterCountdown = await getAndAssertCountdownOrUpObject(page, i + 3);
145+
const afterCountdown = await getAndAssertCountdownOrUpObject(page, i + 4);
148146
// Verify that the new countdown timestamp object is less than the old one
149147
expect(Number(afterCountdown.seconds)).toBeLessThan(Number(beforeCountdown.seconds));
150148
});
@@ -155,13 +153,13 @@ test.describe('Time List with controlled clock @clock', () => {
155153
await test.step(`Count-up cell ${i + 1} counts up`, async () => {
156154
const countUpCell = countUpCells[i];
157155
// Get the initial count-up timestamp object
158-
const beforeCountUp = await getAndAssertCountdownOrUpObject(page, i + 1);
159-
// should not have a '+' sign
160-
await expect(countUpCell).not.toHaveText('+');
156+
const beforeCountUp = await getAndAssertCountdownOrUpObject(page, i + 2);
157+
// should have a '+' sign BECAUSE IT'S A COUNTUP
158+
await expect(countUpCell).toContainText('+');
161159
// Wait until it changes
162-
await expect(countUpCell).not.toHaveText(beforeCountUp.toString());
160+
await expect(countUpCell).not.toContainText(beforeCountUp.toString());
163161
// Get the new count-up timestamp object
164-
const afterCountUp = await getAndAssertCountdownOrUpObject(page, i + 1);
162+
const afterCountUp = await getAndAssertCountdownOrUpObject(page, i + 2);
165163
// Verify that the new count-up timestamp object is greater than the old one
166164
expect(Number(afterCountUp.seconds)).toBeGreaterThan(Number(beforeCountUp.seconds));
167165
});
@@ -203,7 +201,10 @@ test.describe('Activity progress when now is after end of the activity @clock',
203201
* @returns {import('@playwright/test').Locator} cell
204202
*/
205203
function getTimeListCellByIndex(page, rowIndex, columnIndex) {
206-
return page.getByRole('cell').nth(rowIndex * NUM_COLUMNS + columnIndex);
204+
const rowLocator = page.getByRole('row').nth(rowIndex - 1);
205+
const cellLocator = rowLocator.getByRole('cell').nth(columnIndex);
206+
207+
return cellLocator;
207208
}
208209

209210
/**
@@ -226,11 +227,7 @@ async function getTimeListCellTextByIndex(page, rowIndex, columnIndex) {
226227
* @returns {Promise<CountdownOrUpObject>} The countdown (or countup) object
227228
*/
228229
async function getAndAssertCountdownOrUpObject(page, rowIndex) {
229-
const timeToFrom = await getTimeListCellTextByIndex(
230-
page,
231-
HEADER_ROW + rowIndex,
232-
TIME_TO_FROM_COLUMN
233-
);
230+
const timeToFrom = await getTimeListCellTextByIndex(page, rowIndex, TIME_TO_FROM_COLUMN);
234231

235232
expect(timeToFrom).toMatch(COUNTDOWN_REGEXP);
236233
const match = timeToFrom.match(COUNTDOWN_REGEXP);

0 commit comments

Comments
 (0)