Files
grafana/public/app/features/org/OrgDetailsPage.test.tsx
T

82 lines
2.0 KiB
TypeScript
Raw Normal View History

import { render } from '@testing-library/react';
2022-04-22 14:33:13 +01:00
import React from 'react';
import { mockToolkitActionCreator } from 'test/core/redux/mocks';
import { NavModel } from '@grafana/data';
import { backendSrv } from '../../core/services/backend_srv';
import { Organization } from '../../types';
2022-04-22 14:33:13 +01:00
import { OrgDetailsPage, Props } from './OrgDetailsPage';
import { setOrganizationName } from './state/reducers';
2018-10-29 13:46:12 +01:00
jest.mock('app/core/core', () => {
return {
contextSrv: {
hasPermission: () => true,
},
};
});
jest.mock('@grafana/runtime', () => {
const originalModule = jest.requireActual('@grafana/runtime');
return {
...originalModule,
config: {
...originalModule.config,
featureToggles: {
internationalization: true,
},
},
};
});
2018-10-29 13:46:12 +01:00
const setup = (propOverrides?: object) => {
jest.clearAllMocks();
// needed because SharedPreferences is rendered in the test
jest.spyOn(backendSrv, 'put');
jest.spyOn(backendSrv, 'get').mockResolvedValue({ timezone: 'UTC', homeDashboardId: 0, theme: 'dark' });
jest.spyOn(backendSrv, 'search').mockResolvedValue([]);
2018-10-29 13:46:12 +01:00
const props: Props = {
organization: {} as Organization,
2019-01-16 16:29:07 +01:00
navModel: {
main: {
text: 'Configuration',
2019-01-16 16:29:07 +01:00
},
node: {
text: 'Org details',
},
2019-01-16 16:29:07 +01:00
} as NavModel,
2018-10-29 13:46:12 +01:00
loadOrganization: jest.fn(),
setOrganizationName: mockToolkitActionCreator(setOrganizationName),
2018-10-29 13:46:12 +01:00
updateOrganization: jest.fn(),
};
Object.assign(props, propOverrides);
render(<OrgDetailsPage {...props} />);
2018-10-29 13:46:12 +01:00
};
describe('Render', () => {
it('should render component', () => {
expect(() => setup()).not.toThrow();
2018-10-29 13:46:12 +01:00
});
it('should render organization and preferences', () => {
expect(() =>
setup({
organization: {
name: 'Cool org',
id: 1,
},
preferences: {
homeDashboardId: 1,
theme: 'Default',
timezone: 'Default',
locale: '',
},
})
).not.toThrow();
2018-10-29 13:46:12 +01:00
});
});