Skip to content

Commit

Permalink
Have countdowns in the Timelist use a - symbol (#7452)
Browse files Browse the repository at this point in the history
* fix issue

* add test

* remove debugger

* expanded legend showing, but malformed

* Revert "expanded legend showing, but malformed"

This reverts commit b954f00.
  • Loading branch information
scottbell authored Feb 2, 2024
1 parent 18e4b9d commit 3cbaa7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 16 additions & 12 deletions e2e/tests/functional/planning/timelist.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
});
Expand All @@ -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));
});
}
});
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/timelist/TimelistComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3cbaa7b

Please sign in to comment.