BottomNavLinks.test.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import BottomNavLinks from './BottomNavLinks';
  4. import appEvents from '../../app_events';
  5. jest.mock('../../app_events', () => ({
  6. emit: jest.fn(),
  7. }));
  8. const setup = (propOverrides?: object) => {
  9. const props = Object.assign(
  10. {
  11. link: {},
  12. user: {
  13. id: 1,
  14. isGrafanaAdmin: false,
  15. isSignedIn: false,
  16. orgCount: 2,
  17. orgRole: '',
  18. orgId: 1,
  19. orgName: 'Grafana',
  20. timezone: 'UTC',
  21. helpFlags1: 1,
  22. lightTheme: false,
  23. hasEditPermissionInFolders: false,
  24. },
  25. },
  26. propOverrides
  27. );
  28. return shallow(<BottomNavLinks {...props} />);
  29. };
  30. describe('Render', () => {
  31. it('should render component', () => {
  32. const wrapper = setup();
  33. expect(wrapper).toMatchSnapshot();
  34. });
  35. it('should render organization switcher', () => {
  36. const wrapper = setup({
  37. link: {
  38. showOrgSwitcher: true,
  39. },
  40. });
  41. expect(wrapper).toMatchSnapshot();
  42. });
  43. it('should render subtitle', () => {
  44. const wrapper = setup({
  45. link: {
  46. subTitle: 'subtitle',
  47. },
  48. });
  49. expect(wrapper).toMatchSnapshot();
  50. });
  51. it('should render children', () => {
  52. const wrapper = setup({
  53. link: {
  54. children: [
  55. {
  56. id: '1',
  57. },
  58. {
  59. id: '2',
  60. },
  61. {
  62. id: '3',
  63. },
  64. {
  65. id: '4',
  66. hideFromMenu: true,
  67. },
  68. ],
  69. },
  70. });
  71. expect(wrapper).toMatchSnapshot();
  72. });
  73. });
  74. describe('Functions', () => {
  75. describe('item clicked', () => {
  76. const wrapper = setup();
  77. const mockEvent = { preventDefault: jest.fn() };
  78. it('should emit show modal event if url matches shortcut', () => {
  79. const child = { url: '/shortcuts' };
  80. const instance = wrapper.instance() as BottomNavLinks;
  81. instance.itemClicked(mockEvent, child);
  82. expect(appEvents.emit).toHaveBeenCalledWith('show-modal', { templateHtml: '<help-modal></help-modal>' });
  83. });
  84. });
  85. });