You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SettingsApp-test.tsx 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import { shallow } from 'enzyme';
  21. import * as React from 'react';
  22. import ScreenPositionHelper from '../../../../components/common/ScreenPositionHelper';
  23. import {
  24. addSideBarClass,
  25. addWhitePageClass,
  26. removeSideBarClass,
  27. removeWhitePageClass
  28. } from '../../../../helpers/pages';
  29. import { mockLocation, mockRouter } from '../../../../helpers/testMocks';
  30. import { waitAndUpdate } from '../../../../helpers/testUtils';
  31. import {
  32. ALM_INTEGRATION,
  33. ANALYSIS_SCOPE_CATEGORY,
  34. LANGUAGES_CATEGORY,
  35. NEW_CODE_PERIOD_CATEGORY,
  36. PULL_REQUEST_DECORATION_BINDING_CATEGORY
  37. } from '../AdditionalCategoryKeys';
  38. import { SettingsApp } from '../SettingsApp';
  39. jest.mock('../../../../helpers/pages', () => ({
  40. addSideBarClass: jest.fn(),
  41. addWhitePageClass: jest.fn(),
  42. removeSideBarClass: jest.fn(),
  43. removeWhitePageClass: jest.fn()
  44. }));
  45. it('should render default view correctly', async () => {
  46. const wrapper = shallowRender();
  47. expect(addSideBarClass).toBeCalled();
  48. expect(addWhitePageClass).toBeCalled();
  49. await waitAndUpdate(wrapper);
  50. expect(wrapper).toMatchSnapshot();
  51. expect(wrapper.find(ScreenPositionHelper).dive()).toMatchSnapshot();
  52. wrapper.unmount();
  53. expect(removeSideBarClass).toBeCalled();
  54. expect(removeWhitePageClass).toBeCalled();
  55. });
  56. it('should render newCodePeriod correctly', async () => {
  57. const wrapper = shallowRender({
  58. location: mockLocation({ query: { category: NEW_CODE_PERIOD_CATEGORY } })
  59. });
  60. await waitAndUpdate(wrapper);
  61. expect(wrapper).toMatchSnapshot();
  62. });
  63. it('should render languages correctly', async () => {
  64. const wrapper = shallowRender({
  65. location: mockLocation({ query: { category: LANGUAGES_CATEGORY } })
  66. });
  67. await waitAndUpdate(wrapper);
  68. expect(wrapper).toMatchSnapshot();
  69. });
  70. it('should render analysis scope correctly', async () => {
  71. const wrapper = shallowRender({
  72. location: mockLocation({ query: { category: ANALYSIS_SCOPE_CATEGORY } })
  73. });
  74. await waitAndUpdate(wrapper);
  75. expect(wrapper).toMatchSnapshot();
  76. });
  77. it('should render ALM integration correctly', async () => {
  78. const wrapper = shallowRender({
  79. location: mockLocation({ query: { category: ALM_INTEGRATION } })
  80. });
  81. await waitAndUpdate(wrapper);
  82. expect(wrapper).toMatchSnapshot();
  83. });
  84. it('should render pull request decoration binding correctly', async () => {
  85. const wrapper = shallowRender({
  86. location: mockLocation({ query: { category: PULL_REQUEST_DECORATION_BINDING_CATEGORY } })
  87. });
  88. await waitAndUpdate(wrapper);
  89. expect(wrapper).toMatchSnapshot();
  90. });
  91. function shallowRender(props: Partial<SettingsApp['props']> = {}) {
  92. return shallow(
  93. <SettingsApp
  94. defaultCategory="general"
  95. fetchSettings={jest.fn().mockResolvedValue({})}
  96. location={mockLocation()}
  97. params={{}}
  98. router={mockRouter()}
  99. routes={[]}
  100. {...props}
  101. />
  102. );
  103. }