]> source.dussan.org Git - sonarqube.git/commitdiff
fix rule tags change
authorStas Vilchik <stas.vilchik@sonarsource.com>
Tue, 8 May 2018 09:05:54 +0000 (11:05 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 9 May 2018 18:20:47 +0000 (20:20 +0200)
server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsMeta.tsx
server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsTagsPopup.tsx
server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsMeta-test.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsTagsPopup-test.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/RuleDetailsMeta-test.tsx.snap [new file with mode: 0644]
server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/RuleDetailsTagsPopup-test.tsx.snap [new file with mode: 0644]

index 60d51aae6bda1ce6eca6fe23120a3fa400fd2a67..524174513714d17e447eab2370608c7c18eae1ed 100644 (file)
@@ -103,7 +103,7 @@ export default class RuleDetailsMeta extends React.PureComponent<Props> {
                 organization={this.props.organization}
                 setTags={this.props.onTagsChange}
                 sysTags={sysTags}
-                tags={allTags}
+                tags={tags}
               />
             }
             overlayPlacement={PopupPlacement.BottomLeft}>
index 72e0c7a8fa0ed61b344f1a4b2d789cc5583af472..55fa98a14d85a98e34063be400ccaa9f0dd39bea 100644 (file)
@@ -22,7 +22,7 @@ import { without, uniq, difference } from 'lodash';
 import TagsSelector from '../../../components/tags/TagsSelector';
 import { getRuleTags } from '../../../api/rules';
 
-interface Props {
+export interface Props {
   organization: string | undefined;
   setTags: (tags: string[]) => void;
   sysTags: string[];
diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsMeta-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsMeta-test.tsx
new file mode 100644 (file)
index 0000000..0a725bc
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+import * as React from 'react';
+import { shallow } from 'enzyme';
+import RuleDetailsMeta from '../RuleDetailsMeta';
+import { RuleDetails } from '../../../../app/types';
+import RuleDetailsTagsPopup from '../RuleDetailsTagsPopup';
+
+const ruleDetails: RuleDetails = {
+  createdAt: '',
+  repo: '',
+  key: 'key',
+  lang: '',
+  langName: '',
+  name: '',
+  severity: '',
+  status: '',
+  type: ''
+};
+
+it('should edit tags', () => {
+  const onTagsChange = jest.fn();
+  const wrapper = shallow(
+    <RuleDetailsMeta
+      canWrite={true}
+      onFilterChange={jest.fn()}
+      onTagsChange={onTagsChange}
+      organization={undefined}
+      referencedRepositories={{}}
+      ruleDetails={ruleDetails}
+    />
+  );
+  expect(wrapper.find('[data-meta="tags"]')).toMatchSnapshot();
+  const overlay = wrapper
+    .find('[data-meta="tags"]')
+    .find('Dropdown')
+    .prop('overlay') as RuleDetailsTagsPopup;
+
+  overlay.props.setTags(['foo', 'bar']);
+  expect(onTagsChange).toBeCalledWith(['foo', 'bar']);
+});
diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsTagsPopup-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsTagsPopup-test.tsx
new file mode 100644 (file)
index 0000000..7a235e2
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+/* eslint-disable import/order */
+import * as React from 'react';
+import { shallow } from 'enzyme';
+import RuleDetailsTagsPopup, { Props } from '../RuleDetailsTagsPopup';
+
+jest.mock('../../../../api/rules', () => ({
+  getRuleTags: jest.fn(() => Promise.resolve(['system', 'foo', 'bar', 'not-system']))
+}));
+
+const getRuleTags = require('../../../../api/rules').getRuleTags as jest.Mock<any>;
+
+it('should render tags', () => {
+  expect(shallowRender()).toMatchSnapshot();
+});
+
+it('should search tags', async () => {
+  const wrapper = shallowRender();
+  wrapper.prop<Function>('onSearch')('sys');
+  expect(getRuleTags).toBeCalledWith({ organization: 'org', ps: 11, q: 'sys' });
+  await new Promise(setImmediate);
+  wrapper.update();
+  // should not contain system tags
+  expect(wrapper.prop('tags')).toEqual(['bar', 'not-system']);
+});
+
+it('should select & unselect tags', () => {
+  const setTags = jest.fn();
+  const wrapper = shallowRender({ setTags });
+
+  wrapper.prop<Function>('onSelect')('another');
+  expect(setTags).lastCalledWith(['foo', 'another']);
+
+  wrapper.prop<Function>('onUnselect')('foo');
+  expect(setTags).lastCalledWith([]);
+});
+
+function shallowRender(props?: Partial<Props>) {
+  return shallow(
+    <RuleDetailsTagsPopup
+      organization="org"
+      setTags={jest.fn()}
+      sysTags={['system']}
+      tags={['foo']}
+      {...props}
+    />
+  );
+}
diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/RuleDetailsMeta-test.tsx.snap b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/RuleDetailsMeta-test.tsx.snap
new file mode 100644 (file)
index 0000000..8e50177
--- /dev/null
@@ -0,0 +1,35 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should edit tags 1`] = `
+<li
+  className="coding-rules-detail-property"
+  data-meta="tags"
+>
+  <Dropdown
+    closeOnClick={false}
+    closeOnClickOutside={true}
+    overlay={
+      <RuleDetailsTagsPopup
+        organization={undefined}
+        setTags={[MockFunction]}
+        sysTags={Array []}
+        tags={Array []}
+      />
+    }
+    overlayPlacement="bottom-left"
+  >
+    <Button
+      className="button-link"
+    >
+      <TagsList
+        allowUpdate={true}
+        tags={
+          Array [
+            "coding_rules.no_tags",
+          ]
+        }
+      />
+    </Button>
+  </Dropdown>
+</li>
+`;
diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/RuleDetailsTagsPopup-test.tsx.snap b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/RuleDetailsTagsPopup-test.tsx.snap
new file mode 100644 (file)
index 0000000..9b97b5d
--- /dev/null
@@ -0,0 +1,16 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render tags 1`] = `
+<TagsSelector
+  listSize={10}
+  onSearch={[Function]}
+  onSelect={[Function]}
+  onUnselect={[Function]}
+  selectedTags={
+    Array [
+      "foo",
+    ]
+  }
+  tags={Array []}
+/>
+`;