Have countdowns in the Timelist use a - symbol (#7452)

* fix issue

* add test

* remove debugger

* expanded legend showing, but malformed

* Revert "expanded legend showing, but malformed"

This reverts commit b954f00257f41059e1cdd9b1bbff456ac0574eda.
This commit is contained in:
Scott Bell 2024-02-02 09:37:37 +01:00 committed by GitHub
parent 18e4b9da65
commit 3cbaa7bf07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 13 deletions

View File

@ -186,8 +186,8 @@ test("View a timelist in expanded view, verify all the activities are displayed
const COUNTDOWN_REGEXP = /(-)?(\d+D\s)?(\d{2}):(\d{2}):(\d{2})/;
/**
* @typedef {Object} CountdownObject
* @property {string} sign - The sign of the countdown ('-' if the countdown is negative, otherwise undefined).
* @typedef {Object} CountdownOrUpObject
* @property {string} sign - The sign of the countdown ('-' if the countdown is negative, '+' otherwise).
* @property {string} days - The number of days in the countdown (undefined if there are no days).
* @property {string} hours - The number of hours in the countdown.
* @property {string} minutes - The number of minutes in the countdown.
@ -259,11 +259,13 @@ test.describe('Time List with controlled clock', () => {
await test.step(`Countdown cell ${i + 1} counts down`, async () => {
const countdownCell = countdownCells[i];
// Get the initial countdown timestamp object
const beforeCountdown = await getAndAssertCountdownObject(page, i + 3);
const beforeCountdown = await getAndAssertCountdownOrUpObject(page, i + 3);
// should not have a '-' sign
await expect(countdownCell).not.toHaveText('-');
// Wait until it changes
await expect(countdownCell).not.toHaveText(beforeCountdown.toString());
// Get the new countdown timestamp object
const afterCountdown = await getAndAssertCountdownObject(page, i + 3);
const afterCountdown = await getAndAssertCountdownOrUpObject(page, i + 3);
// Verify that the new countdown timestamp object is less than the old one
expect(Number(afterCountdown.seconds)).toBeLessThan(Number(beforeCountdown.seconds));
});
@ -272,15 +274,17 @@ test.describe('Time List with controlled clock', () => {
// Verify that the count-up cells are counting up
for (let i = 0; i < countUpCells.length; i++) {
await test.step(`Count-up cell ${i + 1} counts up`, async () => {
const countdownCell = countUpCells[i];
const countUpCell = countUpCells[i];
// Get the initial count-up timestamp object
const beforeCountdown = await getAndAssertCountdownObject(page, i + 1);
const beforeCountUp = await getAndAssertCountdownOrUpObject(page, i + 1);
// should not have a '+' sign
await expect(countUpCell).not.toHaveText('+');
// Wait until it changes
await expect(countdownCell).not.toHaveText(beforeCountdown.toString());
await expect(countUpCell).not.toHaveText(beforeCountUp.toString());
// Get the new count-up timestamp object
const afterCountdown = await getAndAssertCountdownObject(page, i + 1);
const afterCountUp = await getAndAssertCountdownOrUpObject(page, i + 1);
// Verify that the new count-up timestamp object is greater than the old one
expect(Number(afterCountdown.seconds)).toBeGreaterThan(Number(beforeCountdown.seconds));
expect(Number(afterCountUp.seconds)).toBeGreaterThan(Number(beforeCountUp.seconds));
});
}
});
@ -310,13 +314,13 @@ async function getCellTextByIndex(page, rowIndex, columnIndex) {
}
/**
* Get the text from the countdown cell in the given row, assert that it matches the countdown
* Get the text from the countdown (or countup) cell in the given row, assert that it matches the countdown/countup
* regex, and return an object representing the countdown.
* @param {import('@playwright/test').Page} page
* @param {number} rowIndex the row index
* @returns {Promise<CountdownObject>} countdownObject
* @returns {Promise<CountdownOrUpObject>} The countdown (or countup) object
*/
async function getAndAssertCountdownObject(page, rowIndex) {
async function getAndAssertCountdownOrUpObject(page, rowIndex) {
const timeToFrom = await getCellTextByIndex(page, HEADER_ROW + rowIndex, TIME_TO_FROM_COLUMN);
expect(timeToFrom).toMatch(COUNTDOWN_REGEXP);

View File

@ -138,7 +138,7 @@ const headerItems = [
useDayFormat: true
})}`;
} else if (value > 0) {
const prefix = options.skipPrefix ? '' : '+';
const prefix = options.skipPrefix ? '' : '-';
result = `${prefix}${getPreciseDuration(value, {
excludeMilliSeconds: true,
useDayFormat: true