From b737d758747454148bbbdd475d504235e7961a60 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Mon, 28 Oct 2019 13:07:20 +0100 Subject: Refactor for duplications --- .../pullRequestDecoration/AlmPRDecorationTable.tsx | 88 ++++++++++++ .../components/pullRequestDecoration/AzureTab.tsx | 7 +- .../pullRequestDecoration/AzureTabRenderer.tsx | 15 ++- .../pullRequestDecoration/AzureTable.tsx | 73 ---------- .../pullRequestDecoration/BitbucketTab.tsx | 5 +- .../pullRequestDecoration/BitbucketTabRenderer.tsx | 18 ++- .../pullRequestDecoration/BitbucketTable.tsx | 77 ----------- .../components/pullRequestDecoration/GithubTab.tsx | 5 +- .../pullRequestDecoration/GithubTabRenderer.tsx | 19 ++- .../pullRequestDecoration/GithubTable.tsx | 81 ----------- .../__tests__/AlmPRDecorationTable-test.tsx | 69 ++++++++++ .../__tests__/AzureTab-test.tsx | 11 ++ .../__tests__/AzureTable-test.tsx | 34 ----- .../__tests__/BitbucketTab-test.tsx | 4 +- .../__tests__/BitbucketTable-test.tsx | 34 ----- .../__tests__/GithubTab-test.tsx | 13 ++ .../__tests__/GithubTable-test.tsx | 34 ----- .../AlmPRDecorationTable-test.tsx.snap | 150 +++++++++++++++++++++ .../__snapshots__/AzureTabRenderer-test.tsx.snap | 12 +- .../__snapshots__/AzureTable-test.tsx.snap | 86 ------------ .../BitbucketTabRenderer-test.tsx.snap | 24 +++- .../__snapshots__/BitbucketTable-test.tsx.snap | 98 -------------- .../__snapshots__/GithubTabRenderer-test.tsx.snap | 27 +++- .../__snapshots__/GithubTable-test.tsx.snap | 110 --------------- 24 files changed, 440 insertions(+), 654 deletions(-) create mode 100644 server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AlmPRDecorationTable.tsx delete mode 100644 server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTable.tsx delete mode 100644 server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/BitbucketTable.tsx delete mode 100644 server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/GithubTable.tsx create mode 100644 server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/AlmPRDecorationTable-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/AzureTable-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/BitbucketTable-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/GithubTable-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/AlmPRDecorationTable-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/AzureTable-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/BitbucketTable-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/GithubTable-test.tsx.snap (limited to 'server/sonar-web/src') diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AlmPRDecorationTable.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AlmPRDecorationTable.tsx new file mode 100644 index 00000000000..7aebe33e42e --- /dev/null +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AlmPRDecorationTable.tsx @@ -0,0 +1,88 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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 { ButtonIcon, DeleteButton } from 'sonar-ui-common/components/controls/buttons'; +import EditIcon from 'sonar-ui-common/components/icons/EditIcon'; +import { translate } from 'sonar-ui-common/helpers/l10n'; +import { ALM_KEYS } from '../../../../types/alm-settings'; + +export interface AlmPRDecorationTableProps { + additionalColumnsHeaders: Array; + alm: ALM_KEYS; + definitions: Array<{ + key: string; + additionalColumns: Array; + }>; + onDelete: (definitionKey: string) => void; + onEdit: (definitionKey: string) => void; +} + +export default function AlmPRDecorationTable(props: AlmPRDecorationTableProps) { + const { additionalColumnsHeaders, alm, definitions } = props; + + return ( + + + + + {additionalColumnsHeaders.map(h => ( + + ))} + + + + + + {definitions.length === 0 ? ( + + + + ) : ( + definitions.map(({ key, additionalColumns }) => ( + + + {additionalColumns.map(value => ( + + ))} + + + + )) + )} + +
{translate('settings.pr_decoration.table.column.name')}{h} + {translate('settings.pr_decoration.table.column.edit')} + + {translate('settings.pr_decoration.table.column.delete')} +
+ {translate('settings.pr_decoration.table.empty', alm)} +
+ {key} + + {value} + + props.onEdit(key)}> + + + + props.onDelete(key)} /> +
+ ); +} diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTab.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTab.tsx index e2ceeb2c585..22e7f0c2664 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTab.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTab.tsx @@ -19,8 +19,8 @@ */ import * as React from 'react'; import { createAzureConfiguration, updateAzureConfiguration } from '../../../../api/almSettings'; -import AzureTabRenderer from './AzureTabRenderer'; import { AzureBindingDefinition } from '../../../../types/alm-settings'; +import AzureTabRenderer from './AzureTabRenderer'; interface Props { definitions: AzureBindingDefinition[]; @@ -56,8 +56,9 @@ export default class AzureTab extends React.PureComponent { this.setState({ editedDefinition: { key: '', personalAccessToken: '' } }); }; - handleEdit = (config: AzureBindingDefinition) => { - this.setState({ editedDefinition: config }); + handleEdit = (definitionKey: string) => { + const editedDefinition = this.props.definitions.find(d => d.key === definitionKey); + this.setState({ editedDefinition }); }; handleSubmit = (config: AzureBindingDefinition, originalKey: string) => { diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTabRenderer.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTabRenderer.tsx index 5435f791243..6d977223c61 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTabRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTabRenderer.tsx @@ -21,8 +21,8 @@ import * as React from 'react'; import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner'; import { ALM_KEYS, AzureBindingDefinition } from '../../../../types/alm-settings'; import AlmPRDecorationFormModal from './AlmPRDecorationFormModal'; +import AlmPRDecorationTable from './AlmPRDecorationTable'; import AzureFormModal from './AzureFormModal'; -import AzureTable from './AzureTable'; import TabHeader from './TabHeader'; export interface AzureTabRendererProps { @@ -32,7 +32,7 @@ export interface AzureTabRendererProps { onCancel: () => void; onCreate: () => void; onDelete: (definitionKey: string) => void; - onEdit: (config: AzureBindingDefinition) => void; + onEdit: (definitionKey: string) => void; onSubmit: (config: AzureBindingDefinition, originalKey: string) => void; } @@ -43,7 +43,16 @@ export default function AzureTabRenderer(props: AzureTabRendererProps) { - + ({ + key, + additionalColumns: [] + }))} + onDelete={props.onDelete} + onEdit={props.onEdit} + /> {editedDefinition && ( diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTable.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTable.tsx deleted file mode 100644 index 066da515e1a..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/AzureTable.tsx +++ /dev/null @@ -1,73 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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 { ButtonIcon, DeleteButton } from 'sonar-ui-common/components/controls/buttons'; -import EditIcon from 'sonar-ui-common/components/icons/EditIcon'; -import { translate } from 'sonar-ui-common/helpers/l10n'; -import { AzureBindingDefinition } from '../../../../types/alm-settings'; - -export interface AzureTableProps { - definitions: AzureBindingDefinition[]; - onDelete: (definitionKey: string) => void; - onEdit: (config: AzureBindingDefinition) => void; -} - -export default function AzureTable(props: AzureTableProps) { - const { definitions } = props; - - return ( - - - - - - - - - - {definitions.length === 0 ? ( - - - - ) : ( - definitions.map(definition => ( - - - - - - )) - )} - -
{translate('settings.pr_decoration.table.column.name')} - {translate('settings.pr_decoration.table.column.edit')} - - {translate('settings.pr_decoration.table.column.delete')} -
{translate('settings.pr_decoration.table.empty.azure')}
- {definition.key} - - props.onEdit(definition)}> - - - - props.onDelete(definition.key)} /> -
- ); -} diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/BitbucketTab.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/BitbucketTab.tsx index 47b48305434..13a37742c8e 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/BitbucketTab.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/BitbucketTab.tsx @@ -59,8 +59,9 @@ export default class BitbucketTab extends React.PureComponent { this.setState({ editedDefinition: { key: '', url: '', personalAccessToken: '' } }); }; - handleEdit = (config: BitbucketBindingDefinition) => { - this.setState({ editedDefinition: config }); + handleEdit = (definitionKey: string) => { + const editedDefinition = this.props.definitions.find(d => d.key === definitionKey); + this.setState({ editedDefinition }); }; handleSubmit = (config: BitbucketBindingDefinition, originalKey: string) => { diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/BitbucketTabRenderer.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/BitbucketTabRenderer.tsx index c24b30b4120..10540fcf851 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/BitbucketTabRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/BitbucketTabRenderer.tsx @@ -19,10 +19,11 @@ */ import * as React from 'react'; import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner'; +import { translate } from 'sonar-ui-common/helpers/l10n'; import { ALM_KEYS, BitbucketBindingDefinition } from '../../../../types/alm-settings'; import AlmPRDecorationFormModal from './AlmPRDecorationFormModal'; +import AlmPRDecorationTable from './AlmPRDecorationTable'; import BitbucketFormModal from './BitbucketFormModal'; -import BitbucketTable from './BitbucketTable'; import TabHeader from './TabHeader'; export interface BitbucketTabRendererProps { @@ -32,7 +33,7 @@ export interface BitbucketTabRendererProps { onCancel: () => void; onCreate: () => void; onDelete: (definitionKey: string) => void; - onEdit: (config: BitbucketBindingDefinition) => void; + onEdit: (definitionKey: string) => void; onSubmit: (config: BitbucketBindingDefinition, originalKey: string) => void; } @@ -43,7 +44,18 @@ export default function BitbucketTabRenderer(props: BitbucketTabRendererProps) { - + ({ + key, + additionalColumns: [url] + }))} + onDelete={props.onDelete} + onEdit={props.onEdit} + /> {editedDefinition && ( diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/BitbucketTable.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/BitbucketTable.tsx deleted file mode 100644 index dc173e19788..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/BitbucketTable.tsx +++ /dev/null @@ -1,77 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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 { ButtonIcon, DeleteButton } from 'sonar-ui-common/components/controls/buttons'; -import EditIcon from 'sonar-ui-common/components/icons/EditIcon'; -import { translate } from 'sonar-ui-common/helpers/l10n'; -import { BitbucketBindingDefinition } from '../../../../types/alm-settings'; - -export interface BitbucketTableProps { - definitions: BitbucketBindingDefinition[]; - onDelete: (definitionKey: string) => void; - onEdit: (config: BitbucketBindingDefinition) => void; -} - -export default function BitbucketTable(props: BitbucketTableProps) { - const { definitions } = props; - - return ( - - - - - - - - - - - {definitions.length === 0 ? ( - - - - ) : ( - definitions.map(definition => ( - - - - - - - )) - )} - -
{translate('settings.pr_decoration.table.column.name')}{translate(`settings.pr_decoration.table.column.bitbucket.url`)} - {translate('settings.pr_decoration.table.column.edit')} - - {translate('settings.pr_decoration.table.column.delete')} -
{translate('settings.pr_decoration.table.empty.bitbucket')}
- {definition.key} - - {definition.url} - - props.onEdit(definition)}> - - - - props.onDelete(definition.key)} /> -
- ); -} diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/GithubTab.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/GithubTab.tsx index 05c2200af2c..9c35ad18b89 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/GithubTab.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/GithubTab.tsx @@ -56,8 +56,9 @@ export default class GithubTab extends React.PureComponent { this.setState({ editedDefinition: { key: '', appId: '', url: '', privateKey: '' } }); }; - handleEdit = (config: GithubBindingDefinition) => { - this.setState({ editedDefinition: config }); + handleEdit = (definitionKey: string) => { + const editedDefinition = this.props.definitions.find(d => d.key === definitionKey); + this.setState({ editedDefinition }); }; handleSubmit = (config: GithubBindingDefinition, originalKey: string) => { diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/GithubTabRenderer.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/GithubTabRenderer.tsx index e135049b98d..b33fe013bda 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/GithubTabRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/GithubTabRenderer.tsx @@ -19,10 +19,11 @@ */ import * as React from 'react'; import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner'; +import { translate } from 'sonar-ui-common/helpers/l10n'; import { ALM_KEYS, GithubBindingDefinition } from '../../../../types/alm-settings'; import AlmPRDecorationFormModal from './AlmPRDecorationFormModal'; +import AlmPRDecorationTable from './AlmPRDecorationTable'; import GithubFormModal from './GithubFormModal'; -import GithubTable from './GithubTable'; import TabHeader from './TabHeader'; export interface GithubTabRendererProps { @@ -32,7 +33,7 @@ export interface GithubTabRendererProps { onCancel: () => void; onCreate: () => void; onDelete: (definitionKey: string) => void; - onEdit: (config: GithubBindingDefinition) => void; + onEdit: (definitionKey: string) => void; onSubmit: (config: GithubBindingDefinition, originalKey: string) => void; } @@ -43,7 +44,19 @@ export default function GithubTabRenderer(props: GithubTabRendererProps) { - + ({ + key, + additionalColumns: [url, appId] + }))} + onDelete={props.onDelete} + onEdit={props.onEdit} + /> {editedDefinition && ( diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/GithubTable.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/GithubTable.tsx deleted file mode 100644 index 6c992dac1f8..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/GithubTable.tsx +++ /dev/null @@ -1,81 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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 { ButtonIcon, DeleteButton } from 'sonar-ui-common/components/controls/buttons'; -import EditIcon from 'sonar-ui-common/components/icons/EditIcon'; -import { translate } from 'sonar-ui-common/helpers/l10n'; -import { GithubBindingDefinition } from '../../../../types/alm-settings'; - -export interface GithubTableProps { - definitions: GithubBindingDefinition[]; - onDelete: (definitionKey: string) => void; - onEdit: (config: GithubBindingDefinition) => void; -} - -export default function GithubTable(props: GithubTableProps) { - const { definitions } = props; - - return ( - - - - - - - - - - - - {definitions.length === 0 ? ( - - - - ) : ( - definitions.map(definition => ( - - - - - - - - )) - )} - -
{translate('settings.pr_decoration.table.column.name')}{translate(`settings.pr_decoration.table.column.github.url`)}{translate('settings.pr_decoration.table.column.app_id')} - {translate('settings.pr_decoration.table.column.edit')} - - {translate('settings.pr_decoration.table.column.delete')} -
{translate('settings.pr_decoration.table.empty.github')}
- {definition.key} - - {definition.url} - - {definition.appId} - - props.onEdit(definition)}> - - - - props.onDelete(definition.key)} /> -
- ); -} diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/AlmPRDecorationTable-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/AlmPRDecorationTable-test.tsx new file mode 100644 index 00000000000..758d1964804 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/AlmPRDecorationTable-test.tsx @@ -0,0 +1,69 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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 { shallow } from 'enzyme'; +import * as React from 'react'; +import { ALM_KEYS } from '../../../../../types/alm-settings'; +import AlmPRDecorationTable, { AlmPRDecorationTableProps } from '../AlmPRDecorationTable'; + +it('should render correctly', () => { + expect(shallowRender()).toMatchSnapshot(); + expect( + shallowRender({ + additionalColumnsHeaders: ['additional1', 'additional2'], + alm: ALM_KEYS.GITHUB, + definitions: [ + { key: 'definition1', additionalColumns: ['def1-v1', 'def1-v2'] }, + { key: 'definition2', additionalColumns: ['def2-v1', 'def2-v2'] } + ] + }) + ).toMatchSnapshot(); +}); + +it('should callback', () => { + const onDelete = jest.fn(); + const onEdit = jest.fn(); + + const wrapper = shallowRender({ + additionalColumnsHeaders: [], + alm: ALM_KEYS.BITBUCKET, + definitions: [{ key: 'defKey', additionalColumns: [] }], + onDelete, + onEdit + }); + + wrapper.find('DeleteButton').simulate('click'); + expect(onDelete).toBeCalledWith('defKey'); + + wrapper.find('ButtonIcon').simulate('click'); + expect(onEdit).toBeCalledWith('defKey'); +}); + +function shallowRender(props: Partial = {}) { + return shallow( + + ); +} diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/AzureTab-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/AzureTab-test.tsx index e98737b7cd0..4f394a34214 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/AzureTab-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/AzureTab-test.tsx @@ -53,6 +53,17 @@ it('should handle cancel', async () => { expect(wrapper.state().editedDefinition).toBeUndefined(); }); +it('should handle edit', async () => { + const config = { + key: 'key', + personalAccessToken: 'asdf14' + }; + const wrapper = shallowRender({ definitions: [config] }); + wrapper.instance().handleEdit(config.key); + await waitAndUpdate(wrapper); + expect(wrapper.state().editedDefinition).toEqual(config); +}); + it('should create config', async () => { const onUpdateDefinitions = jest.fn(); const config = mockAzureDefinition(); diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/AzureTable-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/AzureTable-test.tsx deleted file mode 100644 index d8d26b387f6..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/AzureTable-test.tsx +++ /dev/null @@ -1,34 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockAzureDefinition } from '../../../../../helpers/testMocks'; -import AzureTable, { AzureTableProps } from '../AzureTable'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); - expect(shallowRender({ definitions: [mockAzureDefinition()] })).toMatchSnapshot(); -}); - -function shallowRender(props: Partial = {}) { - return shallow( - - ); -} diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/BitbucketTab-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/BitbucketTab-test.tsx index 577c0886fd5..7131b243ec8 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/BitbucketTab-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/BitbucketTab-test.tsx @@ -99,8 +99,8 @@ it('should handle edit', async () => { url: 'url', personalAccessToken: 'PAT' }; - const wrapper = shallowRender(); - wrapper.instance().handleEdit(config); + const wrapper = shallowRender({ definitions: [config] }); + wrapper.instance().handleEdit(config.key); await waitAndUpdate(wrapper); expect(wrapper.state().editedDefinition).toEqual(config); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/BitbucketTable-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/BitbucketTable-test.tsx deleted file mode 100644 index 11cd6eb13b0..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/BitbucketTable-test.tsx +++ /dev/null @@ -1,34 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockBitbucketDefinition } from '../../../../../helpers/testMocks'; -import BitbucketTable, { BitbucketTableProps } from '../BitbucketTable'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); - expect(shallowRender({ definitions: [mockBitbucketDefinition()] })).toMatchSnapshot(); -}); - -function shallowRender(props: Partial = {}) { - return shallow( - - ); -} diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/GithubTab-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/GithubTab-test.tsx index dac085c21ba..2e422a0fbc5 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/GithubTab-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/GithubTab-test.tsx @@ -56,6 +56,19 @@ it('should handle cancel', async () => { expect(wrapper.state().editedDefinition).toBeUndefined(); }); +it('should handle edit', async () => { + const config = { + key: 'key', + url: 'url', + appId: 'appid', + privateKey: 'PAT' + }; + const wrapper = shallowRender({ definitions: [config] }); + wrapper.instance().handleEdit(config.key); + await waitAndUpdate(wrapper); + expect(wrapper.state().editedDefinition).toEqual(config); +}); + it('should create config', async () => { const onUpdateDefinitions = jest.fn(); const config = mockGithubDefinition(); diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/GithubTable-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/GithubTable-test.tsx deleted file mode 100644 index cce1d966f56..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/GithubTable-test.tsx +++ /dev/null @@ -1,34 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockGithubDefinition } from '../../../../../helpers/testMocks'; -import GithubTable, { GithubTableProps } from '../GithubTable'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); - expect(shallowRender({ definitions: [mockGithubDefinition()] })).toMatchSnapshot(); -}); - -function shallowRender(props: Partial = {}) { - return shallow( - - ); -} diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/AlmPRDecorationTable-test.tsx.snap b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/AlmPRDecorationTable-test.tsx.snap new file mode 100644 index 00000000000..8e7fab9dfe0 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/AlmPRDecorationTable-test.tsx.snap @@ -0,0 +1,150 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly 1`] = ` + + + + + + + + + + + + + +
+ settings.pr_decoration.table.column.name + + settings.pr_decoration.table.column.edit + + settings.pr_decoration.table.column.delete +
+ settings.pr_decoration.table.empty.azure +
+`; + +exports[`should render correctly 2`] = ` + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ settings.pr_decoration.table.column.name + + additional1 + + additional2 + + settings.pr_decoration.table.column.edit + + settings.pr_decoration.table.column.delete +
+ definition1 + + def1-v1 + + def1-v2 + + + + + + +
+ definition2 + + def2-v1 + + def2-v2 + + + + + + +
+`; diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/AzureTabRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/AzureTabRenderer-test.tsx.snap index 8e5d8722a57..2318d371dac 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/AzureTabRenderer-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/AzureTabRenderer-test.tsx.snap @@ -10,7 +10,9 @@ exports[`should render correctly 1`] = ` loading={true} timeout={100} > - - - - - - - settings.pr_decoration.table.column.name - - - settings.pr_decoration.table.column.edit - - - settings.pr_decoration.table.column.delete - - - - - - - settings.pr_decoration.table.empty.azure - - - - -`; - -exports[`should render correctly 2`] = ` - - - - - - - - - - - - - - - -
- settings.pr_decoration.table.column.name - - settings.pr_decoration.table.column.edit - - settings.pr_decoration.table.column.delete -
- key - - - - - - -
-`; diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/BitbucketTabRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/BitbucketTabRenderer-test.tsx.snap index e8d9c8283b9..53fbc57bff4 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/BitbucketTabRenderer-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/BitbucketTabRenderer-test.tsx.snap @@ -10,7 +10,13 @@ exports[`should render correctly 1`] = ` loading={true} timeout={100} > - - - - - - - settings.pr_decoration.table.column.name - - - settings.pr_decoration.table.column.bitbucket.url - - - settings.pr_decoration.table.column.edit - - - settings.pr_decoration.table.column.delete - - - - - - - settings.pr_decoration.table.empty.bitbucket - - - - -`; - -exports[`should render correctly 2`] = ` - - - - - - - - - - - - - - - - - -
- settings.pr_decoration.table.column.name - - settings.pr_decoration.table.column.bitbucket.url - - settings.pr_decoration.table.column.edit - - settings.pr_decoration.table.column.delete -
- key - - http://bbs.enterprise.com - - - - - - -
-`; diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/GithubTabRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/GithubTabRenderer-test.tsx.snap index f37d1b20090..2722fbecd81 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/GithubTabRenderer-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecoration/__tests__/__snapshots__/GithubTabRenderer-test.tsx.snap @@ -10,7 +10,14 @@ exports[`should render correctly 1`] = ` loading={true} timeout={100} > - - - - - - - settings.pr_decoration.table.column.name - - - settings.pr_decoration.table.column.github.url - - - settings.pr_decoration.table.column.app_id - - - settings.pr_decoration.table.column.edit - - - settings.pr_decoration.table.column.delete - - - - - - - settings.pr_decoration.table.empty.github - - - - -`; - -exports[`should render correctly 2`] = ` - - - - - - - - - - - - - - - - - - - -
- settings.pr_decoration.table.column.name - - settings.pr_decoration.table.column.github.url - - settings.pr_decoration.table.column.app_id - - settings.pr_decoration.table.column.edit - - settings.pr_decoration.table.column.delete -
- key - - http://github.enterprise.com - - 123456 - - - - - - -
-`; -- cgit v1.2.3