]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20989 Improving "can set tags" test inside CodingRules-it
authorRevanshu Paliwal <revanshu.paliwal@sonarsource.com>
Thu, 9 Nov 2023 13:50:26 +0000 (14:50 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 9 Nov 2023 20:02:40 +0000 (20:02 +0000)
server/sonar-web/design-system/src/components/DropdownMenu.tsx
server/sonar-web/design-system/src/components/input/MultiSelectMenuOption.tsx
server/sonar-web/src/main/js/apps/coding-rules/__tests__/CodingRules-it.ts
server/sonar-web/src/main/js/apps/coding-rules/utils-tests.tsx

index 3076fd7e535bffa247dec45cdf95cf2655aec4b5..10144a7244b74cf3ef3fcf4584f91ee0dfece5bd 100644 (file)
@@ -164,12 +164,23 @@ interface ItemCheckboxProps extends ListItemProps {
   checked: boolean;
   disabled?: boolean;
   id?: string;
+  label?: string;
   onCheck: (checked: boolean, id?: string) => void;
 }
 
 export function ItemCheckbox(props: ItemCheckboxProps) {
-  const { checked, children, className, disabled, id, innerRef, onCheck, onFocus, ...liProps } =
-    props;
+  const {
+    checked,
+    children,
+    className,
+    disabled,
+    id,
+    innerRef,
+    label,
+    onCheck,
+    onFocus,
+    ...liProps
+  } = props;
   return (
     <li ref={innerRef} role="none" {...liProps}>
       <ItemCheckboxStyled
@@ -177,6 +188,7 @@ export function ItemCheckbox(props: ItemCheckboxProps) {
         className={classNames(className, { disabled })}
         disabled={disabled}
         id={id}
+        label={label}
         onCheck={onCheck}
         onFocus={onFocus}
       >
index 0c1bd1c9e1ef50c0d85d661708f1455716a44e16..c6865149eb72b726a5d8e69fe5d194629c5f1bf8 100644 (file)
@@ -62,6 +62,7 @@ export function MultiSelectMenuOption(props: MultiSelectOptionProps) {
         className={classNames('sw-flex sw-py-2 sw-px-4', { active })}
         disabled={disabled}
         id={element}
+        label={element}
         onCheck={onSelectChange}
         onFocus={onHover}
         onPointerEnter={onHover}
index 625feb6b9fa7a24bfc6b61c6d82e4dfd81a5eff7..f2f5703dba4b6e53c9949c2168e0429edc67ad92 100644 (file)
@@ -666,13 +666,16 @@ describe('Rule app details', () => {
       expect(ui.tagCheckbox(tag).get()).toBeInTheDocument();
     });
 
-    // Rule already has this tag
     expect(ui.tagCheckbox(RULE_TAGS_MOCK[0]).get()).toBeChecked();
 
     // Set tag
     await user.click(ui.tagCheckbox(RULE_TAGS_MOCK[1]).get());
-    expect(ui.tagCheckbox(RULE_TAGS_MOCK[1]).get()).toBeChecked();
-    await user.click(ui.tagCheckbox(RULE_TAGS_MOCK[1]).get());
+    await user.keyboard('{Escape}');
+    await expect(ui.tagsDropdown.byText('multi-threading').get()).toHaveATooltipWithContent(
+      'multi-threading, awesome, cute',
+    );
+
+    await user.click(ui.tagsDropdown.get());
 
     // Search for specific tag
     await user.type(ui.tagSearch.get(), RULE_TAGS_MOCK[2]);
index cb8a484168f8bfeb5536eda1eeb3b9004fd0170a..b2bb9d640028200924bb641cd17f2a4a079737d1 100644 (file)
@@ -121,7 +121,7 @@ const selectors = {
 
   // Rule tags
   tagsDropdown: byLabelText(/tags_list_x/).byRole('button'),
-  tagCheckbox: (tag: string) => byRole('checkbox', { name: tag }),
+  tagCheckbox: (tag: string) => byLabelText(tag),
   tagSearch: byRole('searchbox', { name: 'search.search_for_tags' }),
 
   // Rule tabs