From 6ef7ca151ecd602ca8e9cea21743a895a81e89ba Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Tue, 17 Aug 2021 15:50:55 +0200 Subject: SONAR-15297 Move sonar-ui-common code to sonar-web --- .../ui/update-center/__tests__/MetaData-test.tsx | 86 ------------- .../__tests__/MetaDataVersion-test.tsx | 45 ------- .../__tests__/MetaDataVersions-test.tsx | 51 -------- .../__tests__/__snapshots__/MetaData-test.tsx.snap | 133 --------------------- .../__snapshots__/MetaDataVersion-test.tsx.snap | 113 ----------------- .../__snapshots__/MetaDataVersions-test.tsx.snap | 28 ----- 6 files changed, 456 deletions(-) delete mode 100644 server/sonar-ui-common/components/ui/update-center/__tests__/MetaData-test.tsx delete mode 100644 server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersion-test.tsx delete mode 100644 server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersions-test.tsx delete mode 100644 server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaData-test.tsx.snap delete mode 100644 server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersion-test.tsx.snap delete mode 100644 server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersions-test.tsx.snap (limited to 'server/sonar-ui-common/components/ui/update-center/__tests__') diff --git a/server/sonar-ui-common/components/ui/update-center/__tests__/MetaData-test.tsx b/server/sonar-ui-common/components/ui/update-center/__tests__/MetaData-test.tsx deleted file mode 100644 index 85c6ce0ac71..00000000000 --- a/server/sonar-ui-common/components/ui/update-center/__tests__/MetaData-test.tsx +++ /dev/null @@ -1,86 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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 { waitAndUpdate } from '../../../../helpers/testUtils'; -import MetaData from '../MetaData'; -import { mockMetaDataInformation } from '../mocks/update-center-metadata'; -import { MetaDataInformation } from '../update-center-metadata'; -import { HttpStatus } from '../../../../helpers/request'; - -beforeAll(() => { - window.fetch = jest.fn(); -}); - -beforeEach(() => { - jest.resetAllMocks(); -}); - -it('should render correctly', async () => { - const metaDataInfo = mockMetaDataInformation(); - mockFetchReturnValue(metaDataInfo); - - const wrapper = shallowRender(); - await waitAndUpdate(wrapper); - expect(wrapper).toMatchSnapshot(); -}); - -it('should render correctly with organization', async () => { - const metaDataInfo = mockMetaDataInformation({ - organization: { name: 'test-org', url: 'test-org-url' }, - }); - mockFetchReturnValue(metaDataInfo); - - const wrapper = shallowRender(); - await waitAndUpdate(wrapper); - expect(wrapper).toMatchSnapshot(); -}); - -it('should not render anything if call for metadata fails', async () => { - const metaDataInfo = mockMetaDataInformation(); - mockFetchReturnValue(metaDataInfo, HttpStatus.NotFound); - - const wrapper = shallowRender(); - await waitAndUpdate(wrapper); - expect(wrapper.type()).toBeNull(); -}); - -it('should fetch metadata again if the update center key if modified', async () => { - const metaDataInfo = mockMetaDataInformation(); - mockFetchReturnValue(metaDataInfo); - - const wrapper = shallowRender(); - await waitAndUpdate(wrapper); - - expect(window.fetch).toHaveBeenCalledTimes(1); - - mockFetchReturnValue(metaDataInfo); - wrapper.setProps({ updateCenterKey: 'abap' }); - - expect(window.fetch).toHaveBeenCalledTimes(2); -}); - -function shallowRender(props?: Partial) { - return shallow(); -} - -function mockFetchReturnValue(metaDataInfo: MetaDataInformation, status = HttpStatus.Ok) { - (window.fetch as jest.Mock).mockResolvedValueOnce({ status, json: () => metaDataInfo }); -} diff --git a/server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersion-test.tsx b/server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersion-test.tsx deleted file mode 100644 index f1e5b947224..00000000000 --- a/server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersion-test.tsx +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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 MetaDataVersion, { MetaDataVersionProps } from '../MetaDataVersion'; -import { mockMetaDataVersionInformation } from '../mocks/update-center-metadata'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); - expect( - shallowRender({ - versionInformation: mockMetaDataVersionInformation({ - downloadURL: [{ label: 'macos 64 bits', url: '' }], - }), - }) - ).toMatchSnapshot('with advanced downloadUrl'); - expect( - shallowRender({ - versionInformation: { version: '2.0' }, - }) - ).toMatchSnapshot('with very few info'); -}); - -function shallowRender(props?: Partial) { - return shallow( - - ); -} diff --git a/server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersions-test.tsx b/server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersions-test.tsx deleted file mode 100644 index 0648c0fd59d..00000000000 --- a/server/sonar-ui-common/components/ui/update-center/__tests__/MetaDataVersions-test.tsx +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2021 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 { click } from '../../../../helpers/testUtils'; -import MetaDataVersion from '../MetaDataVersion'; -import MetaDataVersions from '../MetaDataVersions'; -import { mockMetaDataVersionInformation } from '../mocks/update-center-metadata'; - -it('should render correctly', () => { - const wrapper = shallowRender(); - expect(wrapper).toMatchSnapshot(); -}); - -it('should properly handle show more / show less', () => { - const wrapper = shallowRender(); - expect(wrapper.find(MetaDataVersion).length).toBe(1); - - click(wrapper.find('.update-center-meta-data-versions-show-more')); - expect(wrapper.find(MetaDataVersion).length).toBe(3); -}); - -function shallowRender(props?: Partial) { - return shallow( - - ); -} diff --git a/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaData-test.tsx.snap b/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaData-test.tsx.snap deleted file mode 100644 index 89e8d74a6d1..00000000000 --- a/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaData-test.tsx.snap +++ /dev/null @@ -1,133 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -
-
- - By - - SonarSource - - - - SonarSource - - - - Issue Tracker - - - - Supported by SonarSource - -
- -
-`; - -exports[`should render correctly with organization 1`] = ` -
-
- - By - - test-org - - - - SonarSource - - - - Issue Tracker - - - - Supported by SonarSource - -
- -
-`; diff --git a/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersion-test.tsx.snap b/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersion-test.tsx.snap deleted file mode 100644 index 7fd964fe2ab..00000000000 --- a/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersion-test.tsx.snap +++ /dev/null @@ -1,113 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -
-
- 5.13 -
-
- - - 6.7 - -
- -
-`; - -exports[`should render correctly: with advanced downloadUrl 1`] = ` -
-
- 5.13 -
-
- - - 6.7 - -
- -
-`; - -exports[`should render correctly: with very few info 1`] = ` -
-
- 2.0 -
-
-
-
-`; diff --git a/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersions-test.tsx.snap b/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersions-test.tsx.snap deleted file mode 100644 index 109fe964473..00000000000 --- a/server/sonar-ui-common/components/ui/update-center/__tests__/__snapshots__/MetaDataVersions-test.tsx.snap +++ /dev/null @@ -1,28 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -
- - -
-`; -- cgit v1.2.3