diff --git a/CHANGELOG.md b/CHANGELOG.md index 818ca68bd6..3da694c759 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Fix bug with override creation ([1515](https://github.com/grafana/oncall/pull/1515)) + ## v1.1.35 (2023-03-09) ### Added diff --git a/grafana-plugin/integration-tests/schedules/addOverride.test.ts b/grafana-plugin/integration-tests/schedules/addOverride.test.ts new file mode 100644 index 0000000000..f682c581b1 --- /dev/null +++ b/grafana-plugin/integration-tests/schedules/addOverride.test.ts @@ -0,0 +1,24 @@ +import { test, expect } from '@playwright/test'; +import { openOnCallPlugin } from '../utils'; +import { clickButton, generateRandomValue } from '../utils/forms'; +import { createOnCallSchedule, getOverrideFormDateInputs } from '../utils/schedule'; +import dayjs from "dayjs"; + +test.beforeEach(async ({ page }) => { + await openOnCallPlugin(page); +}); + +test('default dates in override creation modal are correct', async ({ page }) => { + const onCallScheduleName = generateRandomValue(); + await createOnCallSchedule(page, onCallScheduleName); + + await clickButton({ page, buttonText: 'Add override' }); + + const overrideFormDateInputs = await getOverrideFormDateInputs(page); + + const expectedStart = dayjs().startOf('day'); // start of today + const expectedEnd = expectedStart.add(1, 'day'); // end of today + + expect(overrideFormDateInputs.start.isSame(expectedStart)).toBe(true); + expect(overrideFormDateInputs.end.isSame(expectedEnd)).toBe(true); +}); diff --git a/grafana-plugin/integration-tests/utils/schedule.ts b/grafana-plugin/integration-tests/utils/schedule.ts index 11dfefb868..d41afbe816 100644 --- a/grafana-plugin/integration-tests/utils/schedule.ts +++ b/grafana-plugin/integration-tests/utils/schedule.ts @@ -2,6 +2,7 @@ import { Page } from '@playwright/test'; import { GRAFANA_USERNAME } from './constants'; import { clickButton, fillInInput, selectDropdownValue, selectValuePickerValue } from './forms'; import { goToOnCallPageByClickingOnTab } from './navigation'; +import dayjs from "dayjs"; export const createOnCallSchedule = async (page: Page, scheduleName: string): Promise => { // go to the escalation chains page @@ -29,3 +30,29 @@ export const createOnCallSchedule = async (page: Page, scheduleName: string): Pr await clickButton({ page, buttonText: 'Create' }); }; + +export interface OverrideFormDateInputs { + start: dayjs.Dayjs; + end: dayjs.Dayjs; +} + +export const getOverrideFormDateInputs = async (page: Page): Promise => { + const getInputValue = async (inputNumber: number): Promise => { + const element = await page.waitForSelector(`div[data-testid=\"override-inputs\"] >> input >> nth=${inputNumber}`) + return await element.inputValue(); + } + + const startDate = await getInputValue(0); + const startTime = await getInputValue(1); + + const endDate = await getInputValue(2); + const endTime = await getInputValue(3); + + const startDateTime = dayjs(`${startDate} ${startTime}`, 'MM/DD/YYYY HH:mm'); + const endDateTime = dayjs(`${endDate} ${endTime}`, 'MM/DD/YYYY HH:mm'); + + return { + start: startDateTime, + end: endDateTime, + }; +}; diff --git a/grafana-plugin/src/containers/RotationForm/ScheduleOverrideForm.tsx b/grafana-plugin/src/containers/RotationForm/ScheduleOverrideForm.tsx index 88b0f83e6c..82a736eb3e 100644 --- a/grafana-plugin/src/containers/RotationForm/ScheduleOverrideForm.tsx +++ b/grafana-plugin/src/containers/RotationForm/ScheduleOverrideForm.tsx @@ -205,7 +205,7 @@ const ScheduleOverrideForm: FC = (props) => { -
+
{ - const { startMoment, disabled } = this.props; + const { store, disabled } = this.props; if (disabled) { return; } + // use start of current day as default start time for override + const startMoment = getStartOfDay(store.currentTimezone); + this.setState({ shiftMomentToShowOverrideForm: startMoment }, () => { this.onShowRotationForm('new'); }); diff --git a/grafana-plugin/src/pages/schedule/Schedule.helpers.ts b/grafana-plugin/src/pages/schedule/Schedule.helpers.ts index c1c7b7e104..2c9f1019f3 100644 --- a/grafana-plugin/src/pages/schedule/Schedule.helpers.ts +++ b/grafana-plugin/src/pages/schedule/Schedule.helpers.ts @@ -7,8 +7,17 @@ import { Timezone } from 'models/timezone/timezone.types'; import { RootStore } from 'state'; import { SelectOption } from 'state/types'; +export const getNow = (tz: Timezone) => { + const now = dayjs().tz(tz); + return now.utcOffset() === 0 ? now.utc() : now; +}; + +export const getStartOfDay = (tz: Timezone) => { + return getNow(tz).startOf('day'); +}; + export const getStartOfWeek = (tz: Timezone) => { - return dayjs().tz(tz).utcOffset() === 0 ? dayjs().utc().startOf('isoWeek') : dayjs().tz(tz).startOf('isoWeek'); + return getNow(tz).startOf('isoWeek'); }; export const getUTCString = (moment: dayjs.Dayjs) => {