mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: Add unit test to TimeSyncButton (#19836)
This commit is contained in:
parent
84609abdfa
commit
f8c474fa1b
23
public/app/features/explore/TimeSyncButton.test.tsx
Normal file
23
public/app/features/explore/TimeSyncButton.test.tsx
Normal file
@ -0,0 +1,23 @@
|
||||
import React from 'react';
|
||||
import { TimeSyncButton } from './TimeSyncButton';
|
||||
import { mount } from 'enzyme';
|
||||
|
||||
const setup = (isSynced: boolean) => {
|
||||
const onClick = () => {};
|
||||
return mount(<TimeSyncButton onClick={onClick} isSynced={isSynced} />);
|
||||
};
|
||||
|
||||
describe('TimeSyncButton', () => {
|
||||
it('should render component', () => {
|
||||
const wrapper = setup(true);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
it('should change style when synced', () => {
|
||||
const wrapper = setup(true);
|
||||
expect(wrapper.find('button').props()['aria-label']).toEqual('Synced times');
|
||||
});
|
||||
it('should not change style when not synced', () => {
|
||||
const wrapper = setup(false);
|
||||
expect(wrapper.find('button').props()['aria-label']).toEqual('Unsynced times');
|
||||
});
|
||||
});
|
@ -51,6 +51,7 @@ export function TimeSyncButton(props: TimeSyncButtonProps) {
|
||||
className={classNames('btn navbar-button navbar-button--attached', {
|
||||
[styles.timePickerSynced]: isSynced,
|
||||
})}
|
||||
aria-label={isSynced ? 'Synced times' : 'Unsynced times'}
|
||||
onClick={() => onClick()}
|
||||
>
|
||||
<i className="fa fa-link" />
|
||||
|
@ -0,0 +1,30 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`TimeSyncButton should render component 1`] = `
|
||||
<TimeSyncButton
|
||||
isSynced={true}
|
||||
onClick={[Function]}
|
||||
>
|
||||
<Component
|
||||
content={[Function]}
|
||||
placement="bottom"
|
||||
>
|
||||
<PopoverController
|
||||
content={[Function]}
|
||||
placement="bottom"
|
||||
>
|
||||
<button
|
||||
aria-label="Synced times"
|
||||
className="btn navbar-button navbar-button--attached css-14r9fpj-timePickerSynced"
|
||||
onClick={[Function]}
|
||||
onMouseEnter={[Function]}
|
||||
onMouseLeave={[Function]}
|
||||
>
|
||||
<i
|
||||
className="fa fa-link"
|
||||
/>
|
||||
</button>
|
||||
</PopoverController>
|
||||
</Component>
|
||||
</TimeSyncButton>
|
||||
`;
|
Loading…
Reference in New Issue
Block a user