grafana/public/app/features/explore/RunButton.test.tsx
Torkel Ödegaard 2a21f067b7
ButtonSelect & RefreshPicker: Rewrite of components to use new emotion based ToolbarButton & Menu (#30510)
* ButtonSelect: Trying to rewrite the button select to use ToggleButtonGroup & Menu

* minor update

* Progress

* Updated

* Moving all the explore scenarios into the refresh picker component

* Minor fixes

* Fixed responsive part of run button

* More minor fixes

* typescript fix

* Update packages/grafana-ui/src/components/Icon/Icon.tsx

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>

* Update packages/grafana-ui/src/components/Menu/Menu.tsx

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>

* Review feedback fixes and more

* Fixes small ts issue

* Updated return to dashboard button and tests, moved ButtonSelect out of LegacyForms

* fixed ts issue

* Fixed test

Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
2021-01-23 08:17:50 +01:00

48 lines
1.3 KiB
TypeScript

import React from 'react';
import { RunButton, Props } from './RunButton';
import { RefreshPicker } from '@grafana/ui';
import { shallow } from 'enzyme';
import { getTimeSrv, TimeSrv } from 'app/features/dashboard/services/TimeSrv';
const setup = (propOverrides?: object) => {
const props: Props = {
isSmall: false,
loading: false,
isLive: false,
onRun: jest.fn(),
refreshInterval: '5m',
onChangeRefreshInterval: jest.fn(),
showDropdown: false,
};
Object.assign(props, propOverrides);
const wrapper = shallow(<RunButton {...props} />);
return wrapper;
};
const validIntervals = ['1d'];
jest.mock('app/features/dashboard/services/TimeSrv', () => ({
getTimeSrv: jest.fn().mockReturnValue({
getValidIntervals(intervals: string[]): string[] {
return validIntervals;
},
}),
}));
const getTimeSrvMock = (getTimeSrv as any) as jest.Mock<TimeSrv>;
beforeEach(() => {
getTimeSrvMock.mockClear();
});
describe('RunButton', () => {
describe('if showdropdown is set', () => {
it('should render a RefreshPicker with only valid intervals', () => {
const wrapper = setup({ showDropdown: true });
expect(wrapper.find(RefreshPicker)).toHaveLength(1);
expect(wrapper.find(RefreshPicker).props().intervals).toEqual(validIntervals);
});
});
});