improve reliability of scheduleList +timezone e2e tests (#5023)

# What this PR does

Related to https://github.com/grafana/irm/pull/99

## Which issue(s) this PR closes

Closes https://github.com/grafana/oncall/issues/4991
This commit is contained in:
Joey Orlando 2024-09-13 15:34:47 -04:00 committed by GitHub
parent 091dc68e2c
commit 1558f58bc7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 10 deletions

View file

@ -27,9 +27,9 @@ test('schedule calendar and list of schedules is correctly displayed', async ({
await page.waitForTimeout(2000);
// schedules table displays details created schedule
const schedulesTable = page.getByTestId('schedules-table');
await expect(schedulesTable.getByRole('cell', { name: onCallScheduleName })).toBeVisible();
await expect(schedulesTable.getByRole('cell', { name: 'Web' })).toBeVisible();
await expect(schedulesTable.getByRole('cell', { name: userName })).toBeVisible();
await expect(schedulesTable.getByRole('cell', { name: 'No team' })).toBeVisible();
const schedulesTableLastRow = page.getByTestId('schedules-table').getByRole('row').last();
await expect(schedulesTableLastRow.getByRole('cell', { name: onCallScheduleName })).toBeVisible();
await expect(schedulesTableLastRow.getByRole('cell', { name: 'Web' })).toBeVisible();
await expect(schedulesTableLastRow.getByRole('cell', { name: userName })).toBeVisible();
await expect(schedulesTableLastRow.getByRole('cell', { name: 'No team' })).toBeVisible();
});

View file

@ -13,14 +13,33 @@ dayjs.extend(utc);
dayjs.extend(isoWeek);
test.use({ timezoneId: MOSCOW_TIMEZONE }); // GMT+3 the whole year
const currentUtcTimeHour = dayjs().utc().format('HH');
const currentUtcDate = dayjs().utc().format('DD MMM');
const currentMoscowTimeHour = dayjs().utcOffset(180).format('HH');
const currentMoscowDate = dayjs().utcOffset(180).format('DD MMM');
test('dates in schedule are correct according to selected current timezone', async ({ adminRolePage }) => {
const { page, userName } = adminRolePage;
/**
* Always set a fixed time of today's date but at 12:00:00 (noon)
*
* This solves the issue here https://github.com/grafana/oncall/issues/4991
* where we would occasionally see this test flake if it srtated and finished at a different hour
*
* See playwright docs for more details
* https://playwright.dev/docs/clock
*/
const fixedDateAtNoon = new Date().setHours(12, 0, 0, 0);
await page.clock.setFixedTime(fixedDateAtNoon);
/**
* Use the fixed time for all time calculations + use the same fixed time for both UTC and Moscow time
*/
const fixedDayjs = dayjs(fixedDateAtNoon).utc();
// Calculate time and date based on the fixed time
const currentUtcTimeHour = fixedDayjs.format('HH'); // 12 in this case
const currentUtcDate = fixedDayjs.format('DD MMM');
const currentMoscowTimeHour = fixedDayjs.utcOffset(180).format('HH'); // Adjust for Moscow time (UTC+3)
const currentMoscowDate = fixedDayjs.utcOffset(180).format('DD MMM');
await setTimezoneInProfile(page, MOSCOW_TIMEZONE);
const onCallScheduleName = generateRandomValue();
@ -36,7 +55,7 @@ test('dates in schedule are correct according to selected current timezone', asy
// Selected timezone and local time is correctly displayed
await expect(page.getByText(`Current timezone: GMT, local time: ${currentUtcTimeHour}`)).toBeVisible();
// // User avatar tooltip shows correct time and timezones
// User avatar tooltip shows correct time and timezones
await page.getByTestId('user-avatar-in-schedule').hover();
await expect(page.getByTestId('schedule-user-details_your-current-time')).toHaveText(/GMT\+3/);
await expect(page.getByTestId('schedule-user-details_your-current-time')).toHaveText(