3 * Copyright (C) 2009-2021 SonarSource SA
4 * mailto:info AT sonarsource DOT com
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.
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.
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.
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';
25 it('should render correctly', () => {
26 expect(shallowRender()).toMatchSnapshot();
29 branchesEnabled: false,
30 generalSetting: { type: 'NUMBER_OF_DAYS', value: '23' }
34 shallowRender({ branchesEnabled: false, generalSetting: { type: 'NUMBER_OF_DAYS', value: '' } })
38 it('should not show save button when unchanged', () => {
39 const wrapper = shallowRender({
40 currentSetting: 'PREVIOUS_VERSION',
41 selected: 'PREVIOUS_VERSION',
42 overrideGeneralSetting: true
48 .hasClass('invisible')
52 it('should show save button when changed', () => {
53 const wrapper = shallowRender({
54 currentSetting: 'PREVIOUS_VERSION',
55 selected: 'NUMBER_OF_DAYS',
56 overrideGeneralSetting: true
58 expect(wrapper.find('SubmitButton')).toHaveLength(1);
61 it('should show save button when value changed', () => {
62 const wrapper = shallowRender({
63 currentSetting: 'NUMBER_OF_DAYS',
64 currentSettingValue: '23',
66 selected: 'NUMBER_OF_DAYS',
67 overrideGeneralSetting: true
69 expect(wrapper.find('SubmitButton')).toHaveLength(1);
72 it('should disable the save button when saving', () => {
73 const wrapper = shallowRender({
74 currentSetting: 'NUMBER_OF_DAYS',
75 currentSettingValue: '25',
77 selected: 'PREVIOUS_VERSION',
78 overrideGeneralSetting: true
89 it('should disable the save button when date is invalid', () => {
90 const wrapper = shallowRender({
91 currentSetting: 'PREVIOUS_VERSION',
93 selected: 'NUMBER_OF_DAYS',
94 overrideGeneralSetting: true
105 function shallowRender(props: Partial<ProjectBaselineSelectorProps> = {}) {
107 <ProjectBaselineSelector
108 branchList={[mockMainBranch()]}
109 branchesEnabled={true}
114 onSelectAnalysis={jest.fn()}
115 onSelectDays={jest.fn()}
116 onSelectReferenceBranch={jest.fn()}
117 onSelectSetting={jest.fn()}
119 onToggleSpecificSetting={jest.fn()}
120 overrideGeneralSetting={false}
121 referenceBranch="master"