EditDataSourcePage.test.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import { EditDataSourcePage, Props } from './EditDataSourcePage';
  4. import { DataSource, NavModel } from '../../types';
  5. const setup = (propOverrides?: object) => {
  6. const props: Props = {
  7. navModel: {} as NavModel,
  8. dataSource: {} as DataSource,
  9. dataSourceId: 1,
  10. pageName: '',
  11. loadDataSource: jest.fn(),
  12. };
  13. Object.assign(props, propOverrides);
  14. const wrapper = shallow(<EditDataSourcePage {...props} />);
  15. const instance = wrapper.instance() as EditDataSourcePage;
  16. return {
  17. wrapper,
  18. instance,
  19. };
  20. };
  21. describe('Render', () => {
  22. it('should render component', () => {
  23. const { wrapper } = setup();
  24. expect(wrapper).toMatchSnapshot();
  25. });
  26. it('should render permissions page', () => {
  27. const { wrapper } = setup({
  28. pageName: 'permissions',
  29. });
  30. expect(wrapper).toMatchSnapshot();
  31. });
  32. });
  33. describe('Functions', () => {
  34. describe('is page valid', () => {
  35. it('should be a valid page', () => {
  36. const { instance } = setup();
  37. expect(instance.isValidPage('permissions')).toBeTruthy();
  38. });
  39. it('should not be a valid page', () => {
  40. const { instance } = setup();
  41. expect(instance.isValidPage('asdf')).toBeFalsy();
  42. });
  43. });
  44. describe('get current page', () => {
  45. it('should return permissions', () => {
  46. const { instance } = setup({
  47. pageName: 'permissions',
  48. });
  49. expect(instance.getCurrentPage()).toEqual('permissions');
  50. });
  51. it('should return settings if bogus route', () => {
  52. const { instance } = setup({
  53. pageName: 'asdf',
  54. });
  55. expect(instance.getCurrentPage()).toEqual('settings');
  56. });
  57. });
  58. });