Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-vl committed Jun 14, 2021
1 parent fde733d commit cf23cca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
38 changes: 8 additions & 30 deletions src/components/config/config.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { shallow } from 'enzyme';
import React from 'react';
import { config, setLocationSrv } from '@grafana/runtime';
import { setLocationSrv } from '@grafana/runtime';
import { ApplicationRoot } from '../../constants';
import { Config } from './config';

Expand All @@ -19,8 +19,6 @@ const getPlugin = (overridePlugin: any = { meta: {} }) => ({
Config
*/
describe('Config', () => {
let initialDataSources = config.datasources;

beforeAll(() => {
jest.spyOn(Config, 'getLocation').mockImplementation((): any => ({
assign: jest.fn(),
Expand All @@ -32,31 +30,20 @@ describe('Config', () => {
Initialization
*/
describe('Initialization', () => {
it('If plugin is not enabled, state should have isEnabled = false', () => {
const plugin = getPlugin({ meta: { enabled: false } });
config.datasources = {
redis: {
type: 'redis-datasource',
} as any,
};
it('If plugin is not enabled and meta is not set, state should have isEnabled = false', () => {
const plugin = getPlugin({});
const wrapper = shallow<Config>(<Config plugin={plugin} query={null as any} />);
expect(wrapper.state().isEnabled).toBeFalsy();
expect(wrapper.state().isEnabled).toBeTruthy();
});

it('If plugin is enabled but config does not have needed datasources, state should have isEnabled = true', () => {
const plugin = getPlugin({ meta: { enabled: true } });
config.datasources = {};
it('If plugin is not enabled, state should have isEnabled = false', () => {
const plugin = getPlugin({ meta: { enabled: false } });
const wrapper = shallow<Config>(<Config plugin={plugin} query={null as any} />);
expect(wrapper.state().isEnabled).toBeTruthy();
expect(wrapper.state().isEnabled).toBeFalsy();
});

it('If plugin is enabled and config has needed datasources, state should have isEnabled = true', () => {
it('If plugin is enabled, state should have isEnabled = true', () => {
const plugin = getPlugin({ meta: { enabled: true } });
config.datasources = {
redis: {
type: 'redis-datasource',
} as any,
};
const wrapper = shallow<Config>(<Config plugin={plugin} query={null as any} />);
expect(wrapper.state().isEnabled).toBeTruthy();
});
Expand All @@ -66,14 +53,6 @@ describe('Config', () => {
Rendering
*/
describe('rendering', () => {
beforeAll(() => {
config.datasources = {
redis: {
type: 'redis-datasource',
} as any,
};
});

it('If plugin is not configured, should show enable button', () => {
const plugin = getPlugin({ meta: { enabled: false } });
const wrapper = shallow<Config>(<Config plugin={plugin} query={null as any} />);
Expand Down Expand Up @@ -161,7 +140,6 @@ describe('Config', () => {
});

afterAll(() => {
config.datasources = initialDataSources;
jest.resetAllMocks();
});
});
1 change: 0 additions & 1 deletion src/components/root-page/root-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export class RootPage extends PureComponent<Props, State> {
} as DataQueryRequest<RedisQuery>) as unknown;

const query = dsQuery as Observable<DataQueryResponse>;

if (!query.toPromise) {
return;
}
Expand Down

0 comments on commit cf23cca

Please sign in to comment.