oncall-engine/grafana-plugin/e2e-tests/schedules/timezones.test.ts
Dominik Broj 3a125e004f
test: use 4 workers, disable timezone test (#5044)
# What this PR does
Toggle off timezone test temporarily
Use 4 workers always

## Which issue(s) this PR closes

Related to [issue link here]

<!--
*Note*: If you want the issue to be auto-closed once the PR is merged,
change "Related to" to "Closes" in the line above.
If you have more than one GitHub issue that this PR closes, be sure to
preface
each issue link with a [closing
keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue).
This ensures that the issue(s) are auto-closed once the PR has been
merged.
-->

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-09-19 11:25:17 +00:00

92 lines
4.2 KiB
TypeScript

import { expect } from '@playwright/test';
import dayjs from 'dayjs';
import isoWeek from 'dayjs/plugin/isoWeek';
import utc from 'dayjs/plugin/utc';
import { test } from '../fixtures';
import { MOSCOW_TIMEZONE } from '../utils/constants';
import { clickButton, generateRandomValue } from '../utils/forms';
import { setTimezoneInProfile } from '../utils/grafanaProfile';
import { createOnCallSchedule } from '../utils/schedule';
dayjs.extend(utc);
dayjs.extend(isoWeek);
test.use({ timezoneId: MOSCOW_TIMEZONE }); // GMT+3 the whole year
// The test is skipped because using Clock API breaks several other tests that run in parallel
test.skip('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();
await createOnCallSchedule(page, onCallScheduleName, userName);
// Current timezone is selected by default to currently logged in user timezone
await expect(page.getByTestId('timezone-select')).toHaveText('GMT+3');
// Change timezone to GMT
await page.getByTestId('timezone-select').locator('div').filter({ hasText: 'GMT+' }).nth(1).click();
await page.getByText('GMT', { exact: true }).click();
// 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
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(
new RegExp(currentMoscowTimeHour)
);
await expect(page.getByTestId('schedule-user-details_user-local-time')).toHaveText(new RegExp(MOSCOW_TIMEZONE));
await expect(page.getByTestId('schedule-user-details_user-local-time')).toHaveText(new RegExp(currentMoscowTimeHour));
// Schedule slot shows correct times and timezones
await page.getByTestId('schedule-slot').first().hover();
await page.waitForTimeout(500);
await expect(page.getByTestId('schedule-slot-user-local-time')).toHaveText(
new RegExp(`${currentMoscowDate}, ${currentMoscowTimeHour}`)
);
await expect(page.getByTestId('schedule-slot-user-local-time')).toHaveText(new RegExp(MOSCOW_TIMEZONE));
await expect(page.getByTestId('schedule-slot-current-timezone')).toHaveText(
new RegExp(`${currentUtcDate}, ${currentUtcTimeHour}`)
);
await expect(page.getByTestId('schedule-slot-current-timezone')).toHaveText(/\(GMT\)/);
const firstDayOfTheWeek = dayjs().utc().startOf('isoWeek');
// Rotation form has correct start date and current timezone information
await clickButton({ page, buttonText: 'Add rotation' });
await page.getByText('Layer 1 rotation').click();
await expect(page.getByTestId('rotation-form').getByText('Current timezone: GMT')).toBeVisible();
await expect(page.getByTestId('rotation-form').getByPlaceholder('Date')).toHaveValue(
firstDayOfTheWeek.format('MM/DD/YYYY')
);
await expect(page.getByTestId('rotation-form').getByTestId('date-time-picker').getByRole('textbox')).toHaveValue(
'00:00'
);
});