TeamPages.test.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import { shallow } from 'enzyme';
  2. import React from 'react';
  3. import { NavModel, createTheme } from '@grafana/data';
  4. import { getRouteComponentProps } from 'app/core/navigation/__mocks__/routeProps';
  5. import { User } from 'app/core/services/context_srv';
  6. import { OrgRole, Team, TeamMember } from '../../types';
  7. import { Props, TeamPages } from './TeamPages';
  8. import { getMockTeam } from './__mocks__/teamMocks';
  9. jest.mock('@grafana/runtime/src/config', () => ({
  10. ...(jest.requireActual('@grafana/runtime/src/config') as unknown as object),
  11. config: {
  12. licenseInfo: {
  13. enabledFeatures: { teamsync: true },
  14. },
  15. featureToggles: { accesscontrol: false },
  16. },
  17. }));
  18. const setup = (propOverrides?: object) => {
  19. const props: Props = {
  20. ...getRouteComponentProps({
  21. match: {
  22. params: {
  23. id: '1',
  24. page: null,
  25. },
  26. } as any,
  27. }),
  28. navModel: {} as NavModel,
  29. teamId: 1,
  30. loadTeam: jest.fn(),
  31. loadTeamMembers: jest.fn(),
  32. pageName: 'members',
  33. team: {} as Team,
  34. members: [] as TeamMember[],
  35. editorsCanAdmin: false,
  36. theme: createTheme(),
  37. signedInUser: {
  38. id: 1,
  39. isGrafanaAdmin: false,
  40. orgRole: OrgRole.Viewer,
  41. } as User,
  42. };
  43. Object.assign(props, propOverrides);
  44. const wrapper = shallow(<TeamPages {...props} />);
  45. const instance = wrapper.instance();
  46. return {
  47. wrapper,
  48. instance,
  49. };
  50. };
  51. describe('Render', () => {
  52. it('should render component', () => {
  53. const { wrapper } = setup();
  54. expect(wrapper).toMatchSnapshot();
  55. });
  56. it('should render member page if team not empty', () => {
  57. const { wrapper } = setup({
  58. team: getMockTeam(),
  59. });
  60. expect(wrapper).toMatchSnapshot();
  61. });
  62. it('should render settings and preferences page', () => {
  63. const { wrapper } = setup({
  64. team: getMockTeam(),
  65. pageName: 'settings',
  66. preferences: {
  67. homeDashboardId: 1,
  68. theme: 'Default',
  69. timezone: 'Default',
  70. },
  71. });
  72. expect(wrapper).toMatchSnapshot();
  73. });
  74. it('should render group sync page', () => {
  75. const { wrapper } = setup({
  76. team: getMockTeam(),
  77. pageName: 'groupsync',
  78. });
  79. expect(wrapper).toMatchSnapshot();
  80. });
  81. describe('when feature toggle editorsCanAdmin is turned on', () => {
  82. it('should render settings page if user is team admin', () => {
  83. const { wrapper } = setup({
  84. team: getMockTeam(),
  85. pageName: 'settings',
  86. preferences: {
  87. homeDashboardId: 1,
  88. theme: 'Default',
  89. timezone: 'Default',
  90. },
  91. editorsCanAdmin: true,
  92. signedInUser: {
  93. id: 1,
  94. isGrafanaAdmin: false,
  95. orgRole: OrgRole.Admin,
  96. } as User,
  97. });
  98. expect(wrapper).toMatchSnapshot();
  99. });
  100. it('should not render settings page if user is team member', () => {
  101. const { wrapper } = setup({
  102. team: getMockTeam(),
  103. pageName: 'settings',
  104. preferences: {
  105. homeDashboardId: 1,
  106. theme: 'Default',
  107. timezone: 'Default',
  108. },
  109. editorsCanAdmin: true,
  110. signedInUser: {
  111. id: 1,
  112. isGrafanaAdmin: false,
  113. orgRole: OrgRole.Viewer,
  114. } as User,
  115. });
  116. expect(wrapper).toMatchSnapshot();
  117. });
  118. });
  119. });