BottomNavLinks.test.tsx 2.0 KB

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