mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 02:23:31 -06:00
* Add global week start option to shared preferences * Add default_week_start to configuration docs * Add week start option to dashboards * Add week start argument to tsdb time range parser * Fix strict check issues * Add tests for week start * Change wording on default_week_start documentation Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update week_start column to be a nullable field Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com> * Update configuration to include browser option * Update WeekStartPicker container selector Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com> * Add menuShouldPortal to WeekStartPicker to remove deprecation warning Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com> * Add inputId to WeekStartPicker * Use e2e selector on WeekStartPicker aria-label * Simplify WeekStartPicker onChange condition * Specify value type on WeekStartPicker weekStarts * Remove setWeekStart side effect from reducer * Fix updateLocale failing to reset week start * Store week start as string to handle empty values Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com> Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com> Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
import React from 'react';
|
|
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { selectOptionInTest } from '@grafana/ui';
|
|
|
|
import { byRole } from 'testing-library-selector';
|
|
import { GeneralSettingsUnconnected as GeneralSettings, Props } from './GeneralSettings';
|
|
import { DashboardModel } from '../../state';
|
|
|
|
const setupTestContext = (options: Partial<Props>) => {
|
|
const defaults: Props = {
|
|
dashboard: ({
|
|
title: 'test dashboard title',
|
|
description: 'test dashboard description',
|
|
timepicker: {
|
|
refresh_intervals: ['5s', '10s', '30s', '1m', '5m', '15m', '30m', '1h', '2h', '1d', '2d'],
|
|
time_options: ['5m', '15m', '1h', '6h', '12h', '24h', '2d', '7d', '30d'],
|
|
},
|
|
meta: {
|
|
folderId: 1,
|
|
folderTitle: 'test',
|
|
},
|
|
timezone: 'utc',
|
|
} as unknown) as DashboardModel,
|
|
updateTimeZone: jest.fn(),
|
|
updateWeekStart: jest.fn(),
|
|
};
|
|
|
|
const props = { ...defaults, ...options };
|
|
const { rerender } = render(<GeneralSettings {...props} />);
|
|
|
|
return { rerender, props };
|
|
};
|
|
|
|
describe('General Settings', () => {
|
|
describe('when component is mounted with timezone', () => {
|
|
it('should render correctly', () => {
|
|
setupTestContext({});
|
|
screen.getByDisplayValue('test dashboard title');
|
|
screen.getByDisplayValue('test dashboard description');
|
|
expect(screen.getByLabelText('Time zone picker select container')).toHaveTextContent(
|
|
'Coordinated Universal Time'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('when timezone is changed', () => {
|
|
it('should call update function', async () => {
|
|
const { props } = setupTestContext({});
|
|
userEvent.click(screen.getByLabelText('Time zone picker select container'));
|
|
const timeZonePicker = screen.getByLabelText('Time zone picker select container');
|
|
userEvent.click(byRole('textbox').get(timeZonePicker));
|
|
await selectOptionInTest(timeZonePicker, 'Browser Time');
|
|
expect(props.updateTimeZone).toHaveBeenCalledWith('browser');
|
|
expect(props.dashboard.timezone).toBe('browser');
|
|
});
|
|
});
|
|
});
|