From: Stas Vilchik Date: Tue, 8 May 2018 09:05:54 +0000 (+0200) Subject: fix rule tags change X-Git-Tag: 7.5~1242 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ab1de296500a74f8e456669188f92f04a3d622bc;p=sonarqube.git fix rule tags change --- diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsMeta.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsMeta.tsx index 60d51aae6bd..52417451371 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsMeta.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsMeta.tsx @@ -103,7 +103,7 @@ export default class RuleDetailsMeta extends React.PureComponent { organization={this.props.organization} setTags={this.props.onTagsChange} sysTags={sysTags} - tags={allTags} + tags={tags} /> } overlayPlacement={PopupPlacement.BottomLeft}> diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsTagsPopup.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsTagsPopup.tsx index 72e0c7a8fa0..55fa98a14d8 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsTagsPopup.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsTagsPopup.tsx @@ -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 index 00000000000..0a725bc6d02 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsMeta-test.tsx @@ -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( + + ); + 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 index 00000000000..7a235e28516 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsTagsPopup-test.tsx @@ -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; + +it('should render tags', () => { + expect(shallowRender()).toMatchSnapshot(); +}); + +it('should search tags', async () => { + const wrapper = shallowRender(); + wrapper.prop('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('onSelect')('another'); + expect(setTags).lastCalledWith(['foo', 'another']); + + wrapper.prop('onUnselect')('foo'); + expect(setTags).lastCalledWith([]); +}); + +function shallowRender(props?: Partial) { + return shallow( + + ); +} 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 index 00000000000..8e501772a23 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/RuleDetailsMeta-test.tsx.snap @@ -0,0 +1,35 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should edit tags 1`] = ` +
  • + + } + overlayPlacement="bottom-left" + > + + +
  • +`; 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 index 00000000000..9b97b5d01f4 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/RuleDetailsTagsPopup-test.tsx.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render tags 1`] = ` + +`;