3 * Copyright (C) 2009-2020 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 { click } from 'sonar-ui-common/helpers/testUtils';
23 import CrossFileLocationsNavigator from '../CrossFileLocationsNavigator';
25 const location1: T.FlowLocation = {
27 componentName: 'src/foo.js',
28 msg: 'Do not use foo',
29 textRange: { startLine: 7, endLine: 7, startOffset: 5, endOffset: 8 }
32 const location2: T.FlowLocation = {
34 componentName: 'src/foo.js',
35 msg: 'Do not use foo',
36 textRange: { startLine: 8, endLine: 8, startOffset: 0, endOffset: 5 }
39 const location3: T.FlowLocation = {
41 componentName: 'src/bar.js',
42 msg: 'Do not use bar',
43 textRange: { startLine: 15, endLine: 16, startOffset: 4, endOffset: 6 }
46 it('should render', () => {
47 const wrapper = shallow(
48 <CrossFileLocationsNavigator
49 isTaintAnalysis={false}
50 issue={{ key: 'abcd', type: 'BUG' }}
51 locations={[location1, location2, location3]}
52 onLocationSelect={jest.fn()}
54 selectedLocationIndex={undefined}
57 expect(wrapper).toMatchSnapshot();
58 expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(2);
60 click(wrapper.find('.concise-issue-location-file-more'));
61 expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(3);
64 it('should render all locations', () => {
65 const wrapper = shallow(
66 <CrossFileLocationsNavigator
67 isTaintAnalysis={false}
68 issue={{ key: 'abcd', type: 'BUG' }}
69 locations={[location1, location2]}
70 onLocationSelect={jest.fn()}
72 selectedLocationIndex={undefined}
75 expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(2);
78 it('should expand all locations', () => {
79 const wrapper = shallow(
80 <CrossFileLocationsNavigator
81 isTaintAnalysis={false}
82 issue={{ key: 'abcd', type: 'BUG' }}
83 locations={[location1, location2, location3]}
84 onLocationSelect={jest.fn()}
86 selectedLocationIndex={undefined}
89 expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(2);
91 wrapper.setProps({ selectedLocationIndex: 1 });
92 expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(3);
95 it('should collapse locations when issue changes', () => {
96 const wrapper = shallow(
97 <CrossFileLocationsNavigator
98 isTaintAnalysis={false}
99 issue={{ key: 'abcd', type: 'BUG' }}
100 locations={[location1, location2, location3]}
101 onLocationSelect={jest.fn()}
103 selectedLocationIndex={undefined}
106 wrapper.setProps({ selectedLocationIndex: 1 });
107 expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(3);
109 wrapper.setProps({ issue: { key: 'def' }, selectedLocationIndex: undefined });
110 expect(wrapper.find('ConciseIssueLocationsNavigatorLocation').length).toBe(2);