grafana/public/app/features/datasources/settings/DataSourceSettingsPage.test.tsx

67 lines
1.7 KiB
TypeScript
Raw Normal View History

2018-11-01 07:45:52 -05:00
import React from 'react';
import { shallow } from 'enzyme';
import { DataSourceSettingsPage, Props } from './DataSourceSettingsPage';
import { NavModel } from 'app/types';
import { DataSourceSettings } from '@grafana/ui';
2018-11-01 07:45:52 -05:00
import { getMockDataSource } from '../__mocks__/dataSourcesMocks';
import { getMockPlugin } from '../../plugins/__mocks__/pluginMocks';
2019-01-30 13:07:14 -06:00
import { setDataSourceName, setIsDefault } from '../state/actions';
2018-11-01 07:45:52 -05:00
const setup = (propOverrides?: object) => {
const props: Props = {
navModel: {} as NavModel,
dataSource: getMockDataSource(),
dataSourceMeta: getMockPlugin(),
pageId: 1,
deleteDataSource: jest.fn(),
loadDataSource: jest.fn(),
2019-01-30 13:07:14 -06:00
setDataSourceName,
2018-11-01 07:45:52 -05:00
updateDataSource: jest.fn(),
2019-01-30 13:07:14 -06:00
setIsDefault,
2018-11-01 07:45:52 -05:00
};
Object.assign(props, propOverrides);
return shallow(<DataSourceSettingsPage {...props} />);
2018-11-01 07:45:52 -05:00
};
describe('Render', () => {
it('should render component', () => {
const wrapper = setup();
expect(wrapper).toMatchSnapshot();
});
it('should render loader', () => {
const wrapper = setup({
dataSource: {} as DataSourceSettings,
2018-11-01 07:45:52 -05:00
});
expect(wrapper).toMatchSnapshot();
});
it('should render beta info text', () => {
const wrapper = setup({
dataSourceMeta: { ...getMockPlugin(), state: 'beta' },
});
expect(wrapper).toMatchSnapshot();
});
it('should render alpha info text', () => {
const wrapper = setup({
dataSourceMeta: { ...getMockPlugin(), state: 'alpha' },
});
expect(wrapper).toMatchSnapshot();
});
it('should render is ready only message', () => {
const wrapper = setup({
dataSource: { ...getMockDataSource(), readOnly: true },
});
expect(wrapper).toMatchSnapshot();
});
});