From 1558f58bc719f62548a2011c5b078f2ef3a58a35 Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Fri, 13 Sep 2024 15:34:47 -0400 Subject: [PATCH] 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 --- .../e2e-tests/schedules/schedulesList.test.ts | 10 +++---- .../e2e-tests/schedules/timezones.test.ts | 29 +++++++++++++++---- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/grafana-plugin/e2e-tests/schedules/schedulesList.test.ts b/grafana-plugin/e2e-tests/schedules/schedulesList.test.ts index 018ebdcfb8..96d878210a 100644 --- a/grafana-plugin/e2e-tests/schedules/schedulesList.test.ts +++ b/grafana-plugin/e2e-tests/schedules/schedulesList.test.ts @@ -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(); }); diff --git a/grafana-plugin/e2e-tests/schedules/timezones.test.ts b/grafana-plugin/e2e-tests/schedules/timezones.test.ts index 4f69839623..1bac2e3b93 100644 --- a/grafana-plugin/e2e-tests/schedules/timezones.test.ts +++ b/grafana-plugin/e2e-tests/schedules/timezones.test.ts @@ -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(