grafana/public/app/features/dashboard/components/DashNav/DashNavTimeControls.test.tsx
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

69 lines
2.2 KiB
TypeScript

import { render } from '@testing-library/react';
import React from 'react';
import { getDashboardModel } from '../../../../../test/helpers/getDashboardModel';
import { DashboardModel } from '../../state/DashboardModel';
import { DashNavTimeControls } from './DashNavTimeControls';
describe('DashNavTimeControls', () => {
let dashboardModel: DashboardModel;
beforeEach(() => {
const json = {
panels: [
{
datasource: null,
gridPos: {
h: 3,
w: 24,
x: 0,
y: 8,
},
id: 1,
type: 'welcome',
},
],
refresh: '',
templating: {
list: [],
},
};
dashboardModel = getDashboardModel(json);
});
it('renders RefreshPicker with run button in panel view', () => {
const container = render(
<DashNavTimeControls dashboard={dashboardModel} onChangeTimeZone={jest.fn()} key="time-controls" />
);
expect(container.queryByLabelText(/Refresh dashboard/i)).toBeInTheDocument();
});
it('renders RefreshPicker with interval button in panel view', () => {
const container = render(
<DashNavTimeControls dashboard={dashboardModel} onChangeTimeZone={jest.fn()} key="time-controls" />
);
expect(container.queryByLabelText(/Choose refresh time interval/i)).toBeInTheDocument();
});
it('should not render RefreshPicker interval button in panel edit', () => {
const panel: any = { destroy: jest.fn(), isEditing: true };
dashboardModel.startRefresh = jest.fn();
dashboardModel.panelInEdit = panel;
const container = render(
<DashNavTimeControls dashboard={dashboardModel} onChangeTimeZone={jest.fn()} key="time-controls" />
);
expect(container.queryByLabelText(/Choose refresh time interval/i)).not.toBeInTheDocument();
});
it('should render RefreshPicker run button in panel edit', () => {
const panel: any = { destroy: jest.fn(), isEditing: true };
dashboardModel.startRefresh = jest.fn();
dashboardModel.panelInEdit = panel;
const container = render(
<DashNavTimeControls dashboard={dashboardModel} onChangeTimeZone={jest.fn()} key="time-controls" />
);
expect(container.queryByLabelText(/Refresh dashboard/i)).toBeInTheDocument();
});
});