organization={this.props.organization}
setTags={this.props.onTagsChange}
sysTags={sysTags}
- tags={allTags}
+ tags={tags}
/>
}
overlayPlacement={PopupPlacement.BottomLeft}>
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[];
--- /dev/null
+/*
+ * 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']);
+});
--- /dev/null
+/*
+ * 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}
+ />
+ );
+}
--- /dev/null
+// 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>
+`;
--- /dev/null
+// 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 []}
+/>
+`;