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.

ProjectBaselineSelector-test.tsx 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 { mockMainBranch } from '../../../../helpers/mocks/branch-like';
  23. import ProjectBaselineSelector, { ProjectBaselineSelectorProps } from '../ProjectBaselineSelector';
  24. it('should render correctly', () => {
  25. expect(shallowRender()).toMatchSnapshot();
  26. expect(
  27. shallowRender({
  28. branchesEnabled: false,
  29. generalSetting: { type: 'NUMBER_OF_DAYS', value: '23' }
  30. })
  31. ).toMatchSnapshot();
  32. expect(
  33. shallowRender({ branchesEnabled: false, generalSetting: { type: 'NUMBER_OF_DAYS', value: '' } })
  34. ).toMatchSnapshot();
  35. });
  36. it('should not show save button when unchanged', () => {
  37. const wrapper = shallowRender({
  38. currentSetting: 'PREVIOUS_VERSION',
  39. selected: 'PREVIOUS_VERSION',
  40. overrideGeneralSetting: true
  41. });
  42. expect(
  43. wrapper
  44. .find('SubmitButton')
  45. .parent()
  46. .hasClass('invisible')
  47. ).toBe(true);
  48. });
  49. it('should show save button when changed', () => {
  50. const wrapper = shallowRender({
  51. currentSetting: 'PREVIOUS_VERSION',
  52. selected: 'NUMBER_OF_DAYS',
  53. overrideGeneralSetting: true
  54. });
  55. expect(wrapper.find('SubmitButton')).toHaveLength(1);
  56. });
  57. it('should show save button when value changed', () => {
  58. const wrapper = shallowRender({
  59. currentSetting: 'NUMBER_OF_DAYS',
  60. currentSettingValue: '23',
  61. days: '25',
  62. selected: 'NUMBER_OF_DAYS',
  63. overrideGeneralSetting: true
  64. });
  65. expect(wrapper.find('SubmitButton')).toHaveLength(1);
  66. });
  67. it('should disable the save button when saving', () => {
  68. const wrapper = shallowRender({
  69. currentSetting: 'NUMBER_OF_DAYS',
  70. currentSettingValue: '25',
  71. saving: true,
  72. selected: 'PREVIOUS_VERSION',
  73. overrideGeneralSetting: true
  74. });
  75. expect(
  76. wrapper
  77. .find('SubmitButton')
  78. .first()
  79. .prop('disabled')
  80. ).toBe(true);
  81. });
  82. it('should disable the save button when date is invalid', () => {
  83. const wrapper = shallowRender({
  84. currentSetting: 'PREVIOUS_VERSION',
  85. days: 'hello',
  86. selected: 'NUMBER_OF_DAYS',
  87. overrideGeneralSetting: true
  88. });
  89. expect(
  90. wrapper
  91. .find('SubmitButton')
  92. .first()
  93. .prop('disabled')
  94. ).toBe(true);
  95. });
  96. function shallowRender(props: Partial<ProjectBaselineSelectorProps> = {}) {
  97. return shallow(
  98. <ProjectBaselineSelector
  99. branchList={[mockMainBranch()]}
  100. branchesEnabled={true}
  101. component=""
  102. days="12"
  103. generalSetting={{}}
  104. onCancel={jest.fn()}
  105. onSelectAnalysis={jest.fn()}
  106. onSelectDays={jest.fn()}
  107. onSelectReferenceBranch={jest.fn()}
  108. onSelectSetting={jest.fn()}
  109. onSubmit={jest.fn()}
  110. onToggleSpecificSetting={jest.fn()}
  111. overrideGeneralSetting={false}
  112. referenceBranch="master"
  113. saving={false}
  114. {...props}
  115. />
  116. );
  117. }