diff options
-rw-r--r-- | server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotList.tsx | 9 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotList-test.tsx | 7 |
2 files changed, 7 insertions, 9 deletions
diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotList.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotList.tsx index 610aa769544..3bac3c57ebe 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotList.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotList.tsx @@ -87,11 +87,12 @@ export default class HotspotList extends React.Component<Props, State> { this.setState({ groupedHotspots }); } - if (this.props.selectedHotspotLocation !== prevProps.selectedHotspotLocation) { + if ( + this.props.selectedHotspotLocation !== undefined && + this.props.selectedHotspotLocation !== prevProps.selectedHotspotLocation + ) { const { selectedHotspot } = this.props; - this.setState({ - expandedCategories: { [selectedHotspot.securityCategory]: true } - }); + this.handleToggleCategory(selectedHotspot.securityCategory, true); } } diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotList-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotList-test.tsx index 2d9aa8ea056..574d0d4df6c 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotList-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotList-test.tsx @@ -101,14 +101,11 @@ it('should update grouped hotspots when the list changes', () => { it('should expand the categories for which the location is selected', () => { const wrapper = shallowRender({ hotspots, selectedHotspot: hotspots[0] }); - expect(wrapper.state().expandedCategories).toEqual({ cat2: true }); - - wrapper.instance().handleToggleCategory('cat2', false); - expect(wrapper.state().expandedCategories).toEqual({ cat2: false }); + wrapper.setState({ expandedCategories: { cat1: true, cat2: false } }); wrapper.setProps({ selectedHotspotLocation: 1 }); - expect(wrapper.state().expandedCategories).toEqual({ cat2: true }); + expect(wrapper.state().expandedCategories).toEqual({ cat1: true, cat2: true }); }); function shallowRender(props: Partial<HotspotList['props']> = {}) { |