]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13309 Do not jump to first issue location when only pressing ALT
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Tue, 6 Apr 2021 11:16:57 +0000 (13:16 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 9 Apr 2021 20:03:53 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/issues/__tests__/actions-test.ts
server/sonar-web/src/main/js/apps/issues/actions.ts
server/sonar-web/src/main/js/apps/issues/components/App.tsx

index bba4121229cf8e343943d600ca6885091bb7e6aa..0d1d3c321685c5deb20d1fcb8f4d2873816291b8 100644 (file)
@@ -18,7 +18,8 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import { mockIssue } from '../../../helpers/testMocks';
-import { selectFlow, selectLocation } from '../actions';
+import { enableLocationsNavigator, selectFlow, selectLocation } from '../actions';
+import { State } from '../components/App';
 
 describe('selectFlow', () => {
   it('should select flow and enable locations navigator', () => {
@@ -30,6 +31,73 @@ describe('selectFlow', () => {
   });
 });
 
+describe('enableLocationsNavigator', () => {
+  it('should compute the correct flow index', () => {
+    expect(
+      enableLocationsNavigator({ openIssue: mockIssue(true), selectedFlowIndex: 20 } as State)
+    ).toEqual(
+      expect.objectContaining({
+        locationsNavigator: true,
+        selectedFlowIndex: 20
+      })
+    );
+    expect(enableLocationsNavigator({ openIssue: mockIssue(true) } as State)).toEqual(
+      expect.objectContaining({
+        locationsNavigator: true,
+        selectedFlowIndex: 0
+      })
+    );
+    expect(
+      enableLocationsNavigator({ openIssue: mockIssue(true, { flows: [] }) } as State)
+    ).toEqual(
+      expect.objectContaining({
+        locationsNavigator: true,
+        selectedFlowIndex: undefined
+      })
+    );
+  });
+
+  it('should compute the correct selected location index', () => {
+    expect(enableLocationsNavigator({ openIssue: mockIssue(true) } as State)).toEqual(
+      expect.objectContaining({
+        locationsNavigator: true,
+        selectedLocationIndex: undefined
+      })
+    );
+
+    expect(
+      enableLocationsNavigator({ openIssue: mockIssue(true), selectedLocationIndex: -1 } as State)
+    ).toEqual(
+      expect.objectContaining({
+        locationsNavigator: true,
+        selectedLocationIndex: 0
+      })
+    );
+
+    expect(
+      enableLocationsNavigator({ openIssue: mockIssue(true), selectedLocationIndex: 20 } as State)
+    ).toEqual(
+      expect.objectContaining({
+        locationsNavigator: true,
+        selectedLocationIndex: 20
+      })
+    );
+  });
+
+  it('should do nothing if the open issue has no secondary locations or any flows', () => {
+    expect(enableLocationsNavigator({ openIssue: mockIssue() } as State)).toBeNull();
+    expect(
+      enableLocationsNavigator({
+        openIssue: mockIssue(true, { flows: [], secondaryLocations: [] })
+      } as State)
+    ).toBeNull();
+  });
+
+  it('should do nothing if there is no open issue', () => {
+    expect(enableLocationsNavigator({} as State)).toBeNull();
+  });
+});
+
 describe('selectLocation', () => {
   it('should select location and enable locations navigator', () => {
     expect(selectLocation(5)({ openIssue: mockIssue() })).toEqual({
index e2cae9cfa392708d55e96b42da0fc21e14a298f4..5458a267cc9fb6cee5c90c4e0ec5cbeaec54f36f 100644 (file)
@@ -30,7 +30,7 @@ export function enableLocationsNavigator(state: State) {
       selectedFlowIndex,
       // Also reset index = -1 to 0, we don't want to start on the issue when enabling the location navigator
       selectedLocationIndex:
-        !selectedLocationIndex || selectedLocationIndex < 0 ? 0 : selectedLocationIndex
+        selectedLocationIndex && selectedLocationIndex < 0 ? 0 : selectedLocationIndex
     };
   }
   return null;
@@ -61,7 +61,7 @@ export function selectLocation(nextIndex: number) {
 export function selectNextLocation(
   state: Pick<State, 'selectedFlowIndex' | 'selectedLocationIndex' | 'openIssue'>
 ) {
-  const { selectedFlowIndex, selectedLocationIndex: index, openIssue } = state;
+  const { selectedFlowIndex, selectedLocationIndex: index = -1, openIssue } = state;
   if (openIssue) {
     const locations =
       selectedFlowIndex !== undefined
index b3d8ce3ee684b0d3b53445b9a1676a7df715699a..ed5155c767fed45f708fa563813b681cf5ace259 100644 (file)
@@ -1124,8 +1124,7 @@ export default class App extends React.PureComponent<Props, State> {
   }
 
   render() {
-    const { openIssue, paging } = this.state;
-    const selectedIndex = this.getSelectedIndex();
+    const { openIssue } = this.state;
     return (
       <div className="layout-page issues" id="issues-page">
         <Suggestions suggestions="issues" />