diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2018-05-08 11:05:54 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-05-09 20:20:47 +0200 |
commit | ab1de296500a74f8e456669188f92f04a3d622bc (patch) | |
tree | 67fd4b515bc96698781224507b915b61cbcc868f /server/sonar-web | |
parent | 56f312c22751268126bc3a5e60cd3c7a83b0c696 (diff) | |
download | sonarqube-ab1de296500a74f8e456669188f92f04a3d622bc.tar.gz sonarqube-ab1de296500a74f8e456669188f92f04a3d622bc.zip |
fix rule tags change
Diffstat (limited to 'server/sonar-web')
6 files changed, 177 insertions, 2 deletions
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<Props> { 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( + <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 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<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 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`] = ` +<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 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`] = ` +<TagsSelector + listSize={10} + onSearch={[Function]} + onSelect={[Function]} + onUnselect={[Function]} + selectedTags={ + Array [ + "foo", + ] + } + tags={Array []} +/> +`; |