grafana/public/app/features/explore/ExploreToolbar.test.tsx
Marcus Andersson 1abbb477cf
TimeZone: unify the time zone pickers to one that can rule them all. (#24803)
* draft on a unified TimeZonePicker.

* most of the data structures is in place.

* wip.

* wip.

* wip: timezone selector in progress.2

* fixed so we have proper data on all timezones.

* started to add timezone into time picker.

* addeing time zone footer.

* footer is working.

* fixed so we use the timeZone picker in shared preferences.

* Added so we can change timeZone from picker.

* did some styling changes.

* will update timezone on all places that we need to update it.

* removed console.log

* removed magic string.

* fixed border on calendar.

* ignoring eslint cache.

* cleaned up the code a bit.

* made the default selectable.

* corrected so the behaviour about default works as expected.

* excluded timezone from change tracker.

* revert so default will always be the intial value.

* default will always fallback to the one in the config.

* do the country mapping on startup.

* fixed nit.

* updated snapshots for timepicker.

* fixed build errors.

* updating so snapshot tests is in sync.

* removed Date.now from prop since it will change each run in the snapshot tests.

* fixed so e2e tests works as before.

* moved files into separate folders.
2020-06-26 09:08:15 +02:00

70 lines
2.0 KiB
TypeScript

import React from 'react';
import { shallow, ShallowWrapper } from 'enzyme';
import { UnConnectedExploreToolbar } from './ExploreToolbar';
import { ExploreMode } from '@grafana/data';
import { ExploreId } from '../../types';
import { ToggleButtonGroup } from '@grafana/ui';
jest.mock('./state/selectors', () => {
return {
__esModule: true,
getExploreDatasources: () => [] as any,
};
});
describe('ExploreToolbar', () => {
it('displays correct modes', () => {
let wrapper = shallow(createToolbar([ExploreMode.Tracing, ExploreMode.Logs]));
checkModes(wrapper, ['Logs', 'Tracing']);
wrapper = shallow(createToolbar([ExploreMode.Logs]));
checkModes(wrapper, []);
wrapper = shallow(createToolbar([ExploreMode.Logs, ExploreMode.Tracing, ExploreMode.Metrics]));
checkModes(wrapper, ['Metrics', 'Logs', 'Tracing']);
});
});
function checkModes(wrapper: ShallowWrapper, modes: string[]) {
expect(
wrapper
.find(ToggleButtonGroup)
.children()
.map(node => node.children().text())
).toEqual(modes);
}
function createToolbar(supportedModes: ExploreMode[]) {
return (
<UnConnectedExploreToolbar
datasourceMissing={false}
loading={false}
range={{} as any}
timeZone={'UTC'}
splitted={false}
syncedTimes={false}
supportedModes={supportedModes}
selectedMode={ExploreMode.Tracing}
hasLiveOption={false}
isLive={false}
isPaused={false}
queries={[]}
containerWidth={0}
changeDatasource={(() => {}) as any}
clearAll={(() => {}) as any}
cancelQueries={(() => {}) as any}
runQueries={(() => {}) as any}
closeSplit={(() => {}) as any}
split={(() => {}) as any}
syncTimes={(() => {}) as any}
changeRefreshInterval={(() => {}) as any}
changeMode={(() => {}) as any}
updateLocation={(() => {}) as any}
setDashboardQueriesToUpdateOnLoad={(() => {}) as any}
exploreId={ExploreId.left}
onChangeTime={(() => {}) as any}
onChangeTimeZone={(() => {}) as any}
/>
);
}