]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16489 Security Hotspot assignee field interacts with hotspot selection
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Tue, 14 Jun 2022 10:06:03 +0000 (12:06 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 14 Jun 2022 20:02:51 +0000 (20:02 +0000)
server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/AssigneeSelection.tsx
server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelection-test.tsx
server/sonar-web/src/main/js/components/activity-graph/__tests__/__snapshots__/GraphsTooltips-test.tsx.snap
server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/RadioCard-test.tsx.snap
server/sonar-web/src/main/js/helpers/testUtils.ts

index 5d08d591408d5118aa2c9edf3badd1cb7a0c6757..8aef280c1820844d8fd67f4ce7e989f408f905d1 100644 (file)
@@ -111,10 +111,12 @@ export default class AssigneeSelection extends React.PureComponent<Props, State>
         break;
       case KeyboardKeys.UpArrow:
         event.preventDefault();
+        event.nativeEvent.stopImmediatePropagation();
         this.highlightPrevious();
         break;
       case KeyboardKeys.DownArrow:
         event.preventDefault();
+        event.nativeEvent.stopImmediatePropagation();
         this.highlightNext();
         break;
     }
index e7dcd4c72386c9d9f610a4d71789080152231c1c..c659d52582d6a8b2f065f73e2d45e756fdc6f297 100644 (file)
@@ -22,7 +22,7 @@ import * as React from 'react';
 import { searchUsers } from '../../../../../api/users';
 import { KeyboardKeys } from '../../../../../helpers/keycodes';
 import { mockLoggedInUser, mockUser } from '../../../../../helpers/testMocks';
-import { waitAndUpdate } from '../../../../../helpers/testUtils';
+import { mockEvent, waitAndUpdate } from '../../../../../helpers/testUtils';
 import { UserActive } from '../../../../../types/users';
 import AssigneeSelection from '../AssigneeSelection';
 
@@ -35,7 +35,6 @@ it('should render correctly', () => {
 });
 
 it('should handle keydown', () => {
-  const mockEvent = (key: KeyboardKeys) => ({ preventDefault: jest.fn(), nativeEvent: { key } });
   const suggestedUsers = [
     mockUser({ login: '1' }) as UserActive,
     mockUser({ login: '2' }) as UserActive,
@@ -45,29 +44,29 @@ it('should handle keydown', () => {
   const onSelect = jest.fn();
   const wrapper = shallowRender({ onSelect });
 
-  wrapper.instance().handleKeyDown(mockEvent(KeyboardKeys.UpArrow) as any);
+  wrapper.instance().handleKeyDown(mockKeyboardEvent(KeyboardKeys.UpArrow));
   expect(wrapper.state().highlighted).toEqual({ login: '', name: 'unassigned' });
 
   wrapper.setState({ suggestedUsers });
 
   // press down to highlight the first
-  wrapper.instance().handleKeyDown(mockEvent(KeyboardKeys.DownArrow) as any);
+  wrapper.instance().handleKeyDown(mockKeyboardEvent(KeyboardKeys.DownArrow));
   expect(wrapper.state().highlighted).toBe(suggestedUsers[0]);
 
   // press up to loop around to last
-  wrapper.instance().handleKeyDown(mockEvent(KeyboardKeys.UpArrow) as any);
+  wrapper.instance().handleKeyDown(mockKeyboardEvent(KeyboardKeys.UpArrow));
   expect(wrapper.state().highlighted).toBe(suggestedUsers[2]);
 
   // press down to loop around to first
-  wrapper.instance().handleKeyDown(mockEvent(KeyboardKeys.DownArrow) as any);
+  wrapper.instance().handleKeyDown(mockKeyboardEvent(KeyboardKeys.DownArrow));
   expect(wrapper.state().highlighted).toBe(suggestedUsers[0]);
 
   // press down highlight the next
-  wrapper.instance().handleKeyDown(mockEvent(KeyboardKeys.DownArrow) as any);
+  wrapper.instance().handleKeyDown(mockKeyboardEvent(KeyboardKeys.DownArrow));
   expect(wrapper.state().highlighted).toBe(suggestedUsers[1]);
 
   // press enter to select the highlighted user
-  wrapper.instance().handleKeyDown(mockEvent(KeyboardKeys.Enter) as any);
+  wrapper.instance().handleKeyDown(mockKeyboardEvent(KeyboardKeys.Enter));
   expect(onSelect).toBeCalledWith(suggestedUsers[1]);
 });
 
@@ -115,6 +114,10 @@ it('should allow current user selection', async () => {
   expect(wrapper.state().suggestedUsers[0]).toBe(loggedInUser);
 });
 
+function mockKeyboardEvent(key: KeyboardKeys): React.KeyboardEvent {
+  return mockEvent({ nativeEvent: mockEvent({ key }) });
+}
+
 function shallowRender(props?: Partial<AssigneeSelection['props']>) {
   return shallow<AssigneeSelection>(
     <AssigneeSelection
index c3183f63400dbcc22dc9f7abf0a95231e28dbb8d..c4f775ce43154a4a5f9ea6a3790a742efeb18402 100644 (file)
@@ -129,6 +129,7 @@ exports[`should render correctly for issues graphs: with events 1`] = `
                 "blur": [Function],
               },
               "preventDefault": [Function],
+              "stopImmediatePropagation": [Function],
               "stopPropagation": [Function],
               "target": Object {
                 "blur": [Function],
index e58f9d73597dd3c48457ba12ec1d70db1462fa08..26a5307243d972c29410d3e8f909fee72b65f64b 100644 (file)
@@ -42,6 +42,7 @@ exports[`should be actionable 2`] = `
               "blur": [Function],
             },
             "preventDefault": [Function],
+            "stopImmediatePropagation": [Function],
             "stopPropagation": [Function],
             "target": Object {
               "blur": [Function],
index 603c3f32a025a77ad228739523586232fa16262f..5447d52f898e84fc1b7ccd0f23e3f0a605e0f1bd 100644 (file)
@@ -23,10 +23,25 @@ import { KeyboardKeys } from './keycodes';
 
 export function mockEvent(overrides = {}) {
   return {
-    target: { blur() {} },
-    currentTarget: { blur() {} },
-    preventDefault() {},
-    stopPropagation() {},
+    target: {
+      blur() {
+        /* noop */
+      }
+    },
+    currentTarget: {
+      blur() {
+        /* noop */
+      }
+    },
+    preventDefault() {
+      /* noop */
+    },
+    stopPropagation() {
+      /* noop */
+    },
+    stopImmediatePropagation() {
+      /* noop */
+    },
     ...overrides
   } as any;
 }