]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12333 Write IT, improve existing ITs
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Fri, 23 Aug 2019 13:45:40 +0000 (15:45 +0200)
committerSonarTech <sonartech@sonarsource.com>
Tue, 27 Aug 2019 18:21:04 +0000 (20:21 +0200)
server/sonar-web/src/main/js/apps/quality-profiles/components/ProfileActions.tsx
server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileActions-test.tsx
server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/__snapshots__/ProfileActions-test.tsx.snap
server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileInheritance.tsx
server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileInheritanceBox.tsx

index c1a9b343552a51c6893db66ff7aa9a6e8af82f37..29ba03a6321707980116147211d1352297ed2e9c 100644 (file)
@@ -155,60 +155,55 @@ export class ProfileActions extends React.PureComponent<Props, State> {
       <>
         <ActionsDropdown className={this.props.className}>
           {actions.edit && (
-            <ActionsDropdownItem id="quality-profile-activate-more-rules" to={activateMoreUrl}>
-              {translate('quality_profiles.activate_more_rules')}
+            <ActionsDropdownItem to={activateMoreUrl}>
+              <span data-test="quality-profiles__activate-more-rules">
+                {translate('quality_profiles.activate_more_rules')}
+              </span>
             </ActionsDropdownItem>
           )}
 
           {!profile.isBuiltIn && (
-            <ActionsDropdownItem
-              download={`${profile.key}.xml`}
-              id="quality-profile-backup"
-              to={backupUrl}>
-              {translate('backup_verb')}
+            <ActionsDropdownItem download={`${profile.key}.xml`} to={backupUrl}>
+              <span data-test="quality-profiles__backup">{translate('backup_verb')}</span>
             </ActionsDropdownItem>
           )}
 
           <ActionsDropdownItem
-            id="quality-profile-compare"
             to={getProfileComparePath(profile.name, profile.language, this.props.organization)}>
-            {translate('compare')}
+            <span data-test="quality-profiles__compare">{translate('compare')}</span>
           </ActionsDropdownItem>
 
           {actions.copy && (
             <>
-              <ActionsDropdownItem id="quality-profile-copy" onClick={this.handleCopyClick}>
-                {translate('copy')}
+              <ActionsDropdownItem onClick={this.handleCopyClick}>
+                <span data-test="quality-profiles__copy">{translate('copy')}</span>
               </ActionsDropdownItem>
 
-              <ActionsDropdownItem id="quality-profile-extend" onClick={this.handleExtendClick}>
-                {translate('extend')}
+              <ActionsDropdownItem onClick={this.handleExtendClick}>
+                <span data-test="quality-profiles__extend">{translate('extend')}</span>
               </ActionsDropdownItem>
             </>
           )}
 
           {actions.edit && (
-            <ActionsDropdownItem id="quality-profile-rename" onClick={this.handleRenameClick}>
-              {translate('rename')}
+            <ActionsDropdownItem onClick={this.handleRenameClick}>
+              <span data-test="quality-profiles__rename">{translate('rename')}</span>
             </ActionsDropdownItem>
           )}
 
           {actions.setAsDefault && (
-            <ActionsDropdownItem
-              id="quality-profile-set-as-default"
-              onClick={this.handleSetDefaultClick}>
-              {translate('set_as_default')}
+            <ActionsDropdownItem onClick={this.handleSetDefaultClick}>
+              <span data-test="quality-profiles__set-as-default">
+                {translate('set_as_default')}
+              </span>
             </ActionsDropdownItem>
           )}
 
           {actions.delete && <ActionsDropdownDivider />}
 
           {actions.delete && (
-            <ActionsDropdownItem
-              destructive={true}
-              id="quality-profile-delete"
-              onClick={this.handleDeleteClick}>
-              {translate('delete')}
+            <ActionsDropdownItem destructive={true} onClick={this.handleDeleteClick}>
+              <span data-test="quality-profiles__delete">{translate('delete')}</span>
             </ActionsDropdownItem>
           )}
         </ActionsDropdown>
index 5e037a560c52e3f0942495cd5f9f147a90bad376..0af06aa6a8410df8bc538dd98ba63c6806d3f655 100644 (file)
@@ -67,7 +67,7 @@ it('should copy profile', async () => {
     updateProfiles
   });
 
-  click(wrapper.find('[id="quality-profile-copy"]'));
+  click(wrapper.find('[data-test="quality-profiles__copy"]').parent());
   expect(wrapper.find('CopyProfileForm').exists()).toBe(true);
 
   wrapper.find('CopyProfileForm').prop<Function>('onCopy')(name);
@@ -91,7 +91,7 @@ it('should extend profile', async () => {
     updateProfiles
   });
 
-  click(wrapper.find('[id="quality-profile-extend"]'));
+  click(wrapper.find('[data-test="quality-profiles__extend"]').parent());
   expect(wrapper.find('ExtendProfileForm').exists()).toBe(true);
 
   wrapper.find('ExtendProfileForm').prop<Function>('onExtend')(name);
index 0066c498c61f61762adcbc1204098453bb6cae94..b7c5aff79f91a687f798650444dc14dd35567332 100644 (file)
@@ -4,7 +4,6 @@ exports[`renders with all permissions 1`] = `
 <Fragment>
   <ActionsDropdown>
     <ActionsDropdownItem
-      id="quality-profile-activate-more-rules"
       to={
         Object {
           "pathname": "/organizations/org/rules",
@@ -15,17 +14,23 @@ exports[`renders with all permissions 1`] = `
         }
       }
     >
-      quality_profiles.activate_more_rules
+      <span
+        data-test="quality-profiles__activate-more-rules"
+      >
+        quality_profiles.activate_more_rules
+      </span>
     </ActionsDropdownItem>
     <ActionsDropdownItem
       download="key.xml"
-      id="quality-profile-backup"
       to="/api/qualityprofiles/backup?profileKey=key"
     >
-      backup_verb
+      <span
+        data-test="quality-profiles__backup"
+      >
+        backup_verb
+      </span>
     </ActionsDropdownItem>
     <ActionsDropdownItem
-      id="quality-profile-compare"
       to={
         Object {
           "pathname": "/organizations/org/quality_profiles/compare",
@@ -36,39 +41,58 @@ exports[`renders with all permissions 1`] = `
         }
       }
     >
-      compare
+      <span
+        data-test="quality-profiles__compare"
+      >
+        compare
+      </span>
     </ActionsDropdownItem>
     <ActionsDropdownItem
-      id="quality-profile-copy"
       onClick={[Function]}
     >
-      copy
+      <span
+        data-test="quality-profiles__copy"
+      >
+        copy
+      </span>
     </ActionsDropdownItem>
     <ActionsDropdownItem
-      id="quality-profile-extend"
       onClick={[Function]}
     >
-      extend
+      <span
+        data-test="quality-profiles__extend"
+      >
+        extend
+      </span>
     </ActionsDropdownItem>
     <ActionsDropdownItem
-      id="quality-profile-rename"
       onClick={[Function]}
     >
-      rename
+      <span
+        data-test="quality-profiles__rename"
+      >
+        rename
+      </span>
     </ActionsDropdownItem>
     <ActionsDropdownItem
-      id="quality-profile-set-as-default"
       onClick={[Function]}
     >
-      set_as_default
+      <span
+        data-test="quality-profiles__set-as-default"
+      >
+        set_as_default
+      </span>
     </ActionsDropdownItem>
     <ActionsDropdownDivider />
     <ActionsDropdownItem
       destructive={true}
-      id="quality-profile-delete"
       onClick={[Function]}
     >
-      delete
+      <span
+        data-test="quality-profiles__delete"
+      >
+        delete
+      </span>
     </ActionsDropdownItem>
   </ActionsDropdown>
 </Fragment>
@@ -79,13 +103,15 @@ exports[`renders with no permissions 1`] = `
   <ActionsDropdown>
     <ActionsDropdownItem
       download="key.xml"
-      id="quality-profile-backup"
       to="/api/qualityprofiles/backup?profileKey=key"
     >
-      backup_verb
+      <span
+        data-test="quality-profiles__backup"
+      >
+        backup_verb
+      </span>
     </ActionsDropdownItem>
     <ActionsDropdownItem
-      id="quality-profile-compare"
       to={
         Object {
           "pathname": "/organizations/org/quality_profiles/compare",
@@ -96,7 +122,11 @@ exports[`renders with no permissions 1`] = `
         }
       }
     >
-      compare
+      <span
+        data-test="quality-profiles__compare"
+      >
+        compare
+      </span>
     </ActionsDropdownItem>
   </ActionsDropdown>
 </Fragment>
@@ -106,7 +136,6 @@ exports[`renders with permission to edit only 1`] = `
 <Fragment>
   <ActionsDropdown>
     <ActionsDropdownItem
-      id="quality-profile-activate-more-rules"
       to={
         Object {
           "pathname": "/organizations/org/rules",
@@ -117,17 +146,23 @@ exports[`renders with permission to edit only 1`] = `
         }
       }
     >
-      quality_profiles.activate_more_rules
+      <span
+        data-test="quality-profiles__activate-more-rules"
+      >
+        quality_profiles.activate_more_rules
+      </span>
     </ActionsDropdownItem>
     <ActionsDropdownItem
       download="key.xml"
-      id="quality-profile-backup"
       to="/api/qualityprofiles/backup?profileKey=key"
     >
-      backup_verb
+      <span
+        data-test="quality-profiles__backup"
+      >
+        backup_verb
+      </span>
     </ActionsDropdownItem>
     <ActionsDropdownItem
-      id="quality-profile-compare"
       to={
         Object {
           "pathname": "/organizations/org/quality_profiles/compare",
@@ -138,13 +173,20 @@ exports[`renders with permission to edit only 1`] = `
         }
       }
     >
-      compare
+      <span
+        data-test="quality-profiles__compare"
+      >
+        compare
+      </span>
     </ActionsDropdownItem>
     <ActionsDropdownItem
-      id="quality-profile-rename"
       onClick={[Function]}
     >
-      rename
+      <span
+        data-test="quality-profiles__rename"
+      >
+        rename
+      </span>
     </ActionsDropdownItem>
   </ActionsDropdown>
 </Fragment>
index 40940d493e1cb66d6e4b047e8aee99526dd71efb..745583c979bb300b2b222c6adb5dc5d8ad461c90 100644 (file)
@@ -122,10 +122,6 @@ export default class ProfileInheritance extends React.PureComponent<Props, State
       this.state.children != null &&
       (ancestors.length > 0 || this.state.children.length > 0);
 
-    const currentClassName = classNames('js-inheritance-current', {
-      selected: highlightCurrent
-    });
-
     const extendsBuiltIn = ancestors != null && ancestors.some(profile => profile.isBuiltIn);
 
     return (
@@ -151,36 +147,39 @@ export default class ProfileInheritance extends React.PureComponent<Props, State
                 {ancestors != null &&
                   ancestors.map((ancestor, index) => (
                     <ProfileInheritanceBox
-                      className="js-inheritance-ancestor"
                       depth={index}
                       key={ancestor.key}
                       language={profile.language}
                       organization={this.props.organization}
                       profile={ancestor}
+                      type="ancestor"
                     />
                   ))}
 
                 {this.state.profile != null && (
                   <ProfileInheritanceBox
-                    className={currentClassName}
+                    className={classNames({
+                      selected: highlightCurrent
+                    })}
                     depth={ancestors ? ancestors.length : 0}
                     displayLink={false}
                     extendsBuiltIn={extendsBuiltIn}
                     language={profile.language}
                     organization={this.props.organization}
                     profile={this.state.profile}
+                    type="current"
                   />
                 )}
 
                 {this.state.children != null &&
                   this.state.children.map(child => (
                     <ProfileInheritanceBox
-                      className="js-inheritance-child"
                       depth={ancestors ? ancestors.length + 1 : 0}
                       key={child.key}
                       language={profile.language}
                       organization={this.props.organization}
                       profile={child}
+                      type="child"
                     />
                   ))}
               </tbody>
index a2d5db6cff1142debfd30922c4cc1b64f4a27b2c..29c8e6ccc3e5faf5ed25b1262875f31b2774dcfe 100644 (file)
@@ -38,14 +38,15 @@ interface Props {
     name: string;
     overridingRuleCount?: number;
   };
+  type: string;
 }
 
-export default function ProfileInheritanceBox({ displayLink = true, ...props }: Props) {
+export default function ProfileInheritanceBox({ type, displayLink = true, ...props }: Props) {
   const { profile, className, extendsBuiltIn } = props;
   const offset = 25 * props.depth;
 
   return (
-    <tr className={className}>
+    <tr className={className} data-test={`quality-profiles__inheritance-${type}`}>
       <td>
         <div style={{ paddingLeft: offset }}>
           {displayLink ? (