BottomNavLinks.test.tsx 2.1 KB

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