Skip to content

Commit

Permalink
improve reliability of scheduleList +timezone e2e tests (#5023)
Browse files Browse the repository at this point in the history
# What this PR does

Related to grafana/irm#99

## Which issue(s) this PR closes

Closes #4991
  • Loading branch information
joeyorlando authored Sep 13, 2024
1 parent 091dc68 commit 1558f58
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
10 changes: 5 additions & 5 deletions grafana-plugin/e2e-tests/schedules/schedulesList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
29 changes: 24 additions & 5 deletions grafana-plugin/e2e-tests/schedules/timezones.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(
Expand Down

0 comments on commit 1558f58

Please sign in to comment.