]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18434 RTL Migration Project Dump
authorViktor Vorona <viktor.vorona@sonarsource.com>
Mon, 12 Jun 2023 10:18:33 +0000 (12:18 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 12 Jun 2023 20:02:49 +0000 (20:02 +0000)
server/sonar-web/src/main/js/api/mocks/ProjectDumpServiceMock.ts [new file with mode: 0644]
server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-it.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-test.tsx [deleted file]
server/sonar-web/src/main/js/apps/projectDump/__tests__/__snapshots__/ProjectDumpApp-test.tsx.snap [deleted file]
server/sonar-web/src/main/js/apps/projectDump/components/__tests__/Export-test.tsx [deleted file]
server/sonar-web/src/main/js/apps/projectDump/components/__tests__/Import-test.tsx [deleted file]
server/sonar-web/src/main/js/apps/projectDump/components/__tests__/__snapshots__/Export-test.tsx.snap [deleted file]
server/sonar-web/src/main/js/apps/projectDump/components/__tests__/__snapshots__/Import-test.tsx.snap [deleted file]
server/sonar-web/src/main/js/types/project-dump.ts

diff --git a/server/sonar-web/src/main/js/api/mocks/ProjectDumpServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/ProjectDumpServiceMock.ts
new file mode 100644 (file)
index 0000000..88124a9
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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 { cloneDeep } from 'lodash';
+import { TaskStatuses, TaskTypes } from '../../types/tasks';
+import { doExport, doImport, getStatus } from '../project-dump';
+import ComputeEngineServiceMock from './ComputeEngineServiceMock';
+
+jest.mock('../project-dump');
+
+export class ProjectDumpServiceMock {
+  #ceService: ComputeEngineServiceMock;
+  canBeExported = true;
+  canBeImported = false;
+  #customTasks = false;
+  exportedDump: string | undefined = undefined;
+  dumpToImport: string | undefined = undefined;
+
+  constructor(ceService: ComputeEngineServiceMock) {
+    this.#ceService = ceService;
+
+    jest.mocked(doExport).mockImplementation(this.doExportHandler);
+    jest.mocked(doImport).mockImplementation(this.doImportHandler);
+    jest.mocked(getStatus).mockImplementation(this.getStatusHandler);
+  }
+
+  reset = () => {
+    this.canBeImported = false;
+    this.canBeExported = true;
+    this.#customTasks = false;
+    this.exportedDump = undefined;
+    this.dumpToImport = undefined;
+  };
+
+  setImportState = () => {
+    this.canBeImported = true;
+    this.canBeExported = false;
+    this.dumpToImport = 'tmp/test.zip';
+  };
+
+  useCustomTasks = () => {
+    this.#customTasks = true;
+  };
+
+  doExportHandler = (componentKey: string) => {
+    if (!this.#customTasks) {
+      this.#ceService.addTask({
+        componentKey,
+        type: TaskTypes.ProjectExport,
+        status: TaskStatuses.Success,
+        executedAt: '2023-06-08T12:00:00Z',
+      });
+    }
+    this.exportedDump = `/tmp/${componentKey}.zip`;
+    return this.reply({});
+  };
+
+  doImportHandler = (componentKey: string) => {
+    if (!this.#customTasks) {
+      this.#ceService.addTask({
+        componentKey,
+        type: TaskTypes.ProjectImport,
+        status: TaskStatuses.Success,
+        executedAt: '2023-06-08T12:00:00Z',
+      });
+    }
+    return this.reply({});
+  };
+
+  getStatusHandler = () => {
+    return this.reply({
+      canBeExported: this.canBeExported,
+      canBeImported: this.canBeImported,
+      exportedDump: this.exportedDump,
+      dumpToImport: this.dumpToImport,
+    });
+  };
+
+  reply<T>(response: T): Promise<T> {
+    return Promise.resolve(cloneDeep(response));
+  }
+}
diff --git a/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-it.tsx b/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-it.tsx
new file mode 100644 (file)
index 0000000..6343f5a
--- /dev/null
@@ -0,0 +1,198 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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 { screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { byRole, byText } from 'testing-library-selector';
+import ComputeEngineServiceMock from '../../../api/mocks/ComputeEngineServiceMock';
+import { ProjectDumpServiceMock } from '../../../api/mocks/ProjectDumpServiceMock';
+import { mockComponent } from '../../../helpers/mocks/component';
+import { renderAppWithComponentContext } from '../../../helpers/testReactTestingUtils';
+import { Feature } from '../../../types/features';
+import { TaskStatuses, TaskTypes } from '../../../types/tasks';
+import routes from '../routes';
+
+const computeEngineHandler = new ComputeEngineServiceMock();
+const handler = new ProjectDumpServiceMock(computeEngineHandler);
+
+const COMPONENT_KEY = 'test';
+
+const ui = {
+  pageDescriptionWithImport: byText('project_dump.page.description'),
+  pageDescriptionWithoutImport: byText('project_dump.page.description_without_import'),
+
+  disabledImportFeatureMsg: byText('project_dump.import_form_description_disabled'),
+
+  exportBtn: byRole('button', { name: 'project_dump.do_export' }),
+  importBtn: byRole('button', { name: 'project_dump.do_import' }),
+
+  successExport: byText('project_dump.latest_export_available.June 8, 2023 at', { exact: false }),
+  pendingExport: byText('project_dump.pending_export.June 8, 2023 at', { exact: false }),
+  inProgressExport: byText('project_dump.in_progress_export.1 hour ago'),
+  failedExport: byText('project_dump.failed_export'),
+  cantExportMsg: byText('project_dump.can_not_export'),
+
+  successImport: byText('project_dump.import_success.June 8, 2023 at', { exact: false }),
+  pendingImport: byText('project_dump.pending_import.June 8, 2023 at', { exact: false }),
+  inProgressImport: byText('project_dump.in_progress_import.1 hour ago'),
+  failedImport: byText('project_dump.failed_import'),
+  cantImportMsg: byText('project_dump.can_not_import'),
+  noDumpImportMsg: byText('project_dump.no_file_to_import'),
+};
+
+afterAll(() => {
+  jest.useRealTimers();
+});
+
+beforeEach(() => {
+  computeEngineHandler.reset();
+  handler.reset();
+  jest.useFakeTimers({
+    advanceTimers: true,
+    now: new Date('2023-06-08T13:00:00Z'),
+  });
+});
+
+it('can export project, but can not import', async () => {
+  renderProjectKeyApp([Feature.ProjectImport]);
+  expect(await ui.exportBtn.find()).toBeInTheDocument();
+  expect(ui.importBtn.query()).not.toBeInTheDocument();
+  expect(ui.pageDescriptionWithImport.get()).toBeInTheDocument();
+  expect(ui.pageDescriptionWithoutImport.query()).not.toBeInTheDocument();
+  expect(ui.cantImportMsg.get()).toBeInTheDocument();
+  await userEvent.click(ui.exportBtn.get());
+  expect(await ui.successExport.find()).toBeInTheDocument();
+  expect(screen.getByText(`/tmp/${COMPONENT_KEY}.zip`)).toBeInTheDocument();
+});
+
+it('can export project without import feature', async () => {
+  renderProjectKeyApp([]);
+  expect(await ui.exportBtn.find()).toBeInTheDocument();
+  expect(ui.importBtn.query()).not.toBeInTheDocument();
+  expect(ui.pageDescriptionWithoutImport.get()).toBeInTheDocument();
+  expect(ui.pageDescriptionWithImport.query()).not.toBeInTheDocument();
+  expect(ui.disabledImportFeatureMsg.get()).toBeInTheDocument();
+  await userEvent.click(ui.exportBtn.get());
+  expect(await ui.successExport.find()).toBeInTheDocument();
+  expect(screen.getByText(`/tmp/${COMPONENT_KEY}.zip`)).toBeInTheDocument();
+});
+
+it('should show pending->in progress->failed export', async () => {
+  handler.useCustomTasks();
+  renderProjectKeyApp([]);
+  computeEngineHandler.addTask({
+    componentKey: COMPONENT_KEY,
+    type: TaskTypes.ProjectExport,
+    status: TaskStatuses.Pending,
+    submittedAt: '2023-06-08T11:55:00Z',
+  });
+  await userEvent.click(await ui.exportBtn.find());
+  expect(await ui.pendingExport.find()).toBeInTheDocument();
+  expect(ui.exportBtn.query()).not.toBeInTheDocument();
+
+  computeEngineHandler.addTask({
+    componentKey: COMPONENT_KEY,
+    type: TaskTypes.ProjectExport,
+    status: TaskStatuses.InProgress,
+    startedAt: '2023-06-08T12:00:00Z',
+  });
+  jest.runOnlyPendingTimers();
+  expect(await ui.inProgressExport.find()).toBeInTheDocument();
+  expect(ui.exportBtn.query()).not.toBeInTheDocument();
+
+  computeEngineHandler.addTask({
+    componentKey: COMPONENT_KEY,
+    type: TaskTypes.ProjectExport,
+    status: TaskStatuses.Failed,
+  });
+  jest.runOnlyPendingTimers();
+  expect(await ui.failedExport.find()).toBeInTheDocument();
+  expect(ui.exportBtn.get()).toBeInTheDocument();
+});
+
+it('can import project once, and can not export', async () => {
+  handler.setImportState();
+  renderProjectKeyApp([Feature.ProjectImport]);
+  expect(await ui.importBtn.find()).toBeInTheDocument();
+  expect(ui.exportBtn.query()).not.toBeInTheDocument();
+  expect(ui.cantExportMsg.get()).toBeInTheDocument();
+  await userEvent.click(ui.importBtn.get());
+  expect(await ui.successImport.find()).toBeInTheDocument();
+  expect(ui.importBtn.query()).not.toBeInTheDocument();
+});
+
+it('should show pending->in progress->failed import', async () => {
+  handler.useCustomTasks();
+  handler.setImportState();
+  renderProjectKeyApp([Feature.ProjectImport]);
+  computeEngineHandler.addTask({
+    componentKey: COMPONENT_KEY,
+    type: TaskTypes.ProjectImport,
+    status: TaskStatuses.Pending,
+    submittedAt: '2023-06-08T11:55:00Z',
+  });
+  await userEvent.click(await ui.importBtn.find());
+  expect(await ui.pendingImport.find()).toBeInTheDocument();
+  expect(ui.importBtn.query()).not.toBeInTheDocument();
+
+  computeEngineHandler.addTask({
+    componentKey: COMPONENT_KEY,
+    type: TaskTypes.ProjectImport,
+    status: TaskStatuses.InProgress,
+    startedAt: '2023-06-08T12:00:00Z',
+  });
+  jest.runOnlyPendingTimers();
+  expect(await ui.inProgressImport.find()).toBeInTheDocument();
+  expect(ui.importBtn.query()).not.toBeInTheDocument();
+
+  computeEngineHandler.addTask({
+    componentKey: COMPONENT_KEY,
+    type: TaskTypes.ProjectImport,
+    status: TaskStatuses.Failed,
+  });
+  jest.runOnlyPendingTimers();
+  expect(await ui.failedImport.find()).toBeInTheDocument();
+  expect(ui.importBtn.get()).toBeInTheDocument();
+});
+
+it(`can't import if no dump file`, async () => {
+  handler.setImportState();
+  handler.dumpToImport = undefined;
+  renderProjectKeyApp([Feature.ProjectImport]);
+  expect(await ui.noDumpImportMsg.find()).toBeInTheDocument();
+  expect(ui.importBtn.query()).not.toBeInTheDocument();
+});
+
+it('can do nothing', async () => {
+  handler.setImportState();
+  renderProjectKeyApp([]);
+  expect(await ui.cantExportMsg.find()).toBeInTheDocument();
+  expect(ui.importBtn.query()).not.toBeInTheDocument();
+  expect(ui.exportBtn.query()).not.toBeInTheDocument();
+  expect(ui.disabledImportFeatureMsg.get()).toBeInTheDocument();
+});
+
+function renderProjectKeyApp(featureList: Feature[] = []) {
+  return renderAppWithComponentContext(
+    'import_export',
+    routes,
+    { featureList },
+    { component: mockComponent({ key: COMPONENT_KEY }) }
+  );
+}
diff --git a/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-test.tsx b/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-test.tsx
deleted file mode 100644 (file)
index ca4c049..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 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 { getActivity } from '../../../api/ce';
-import { getStatus } from '../../../api/project-dump';
-import { mockComponent } from '../../../helpers/mocks/component';
-import { mockDumpStatus, mockDumpTask } from '../../../helpers/testMocks';
-import { waitAndUpdate } from '../../../helpers/testUtils';
-import { TaskStatuses } from '../../../types/tasks';
-import { ProjectDumpApp } from '../ProjectDumpApp';
-
-jest.mock('../../../api/ce', () => ({
-  getActivity: jest.fn().mockResolvedValue({ tasks: [] }),
-}));
-
-jest.mock('../../../api/project-dump', () => ({
-  getStatus: jest.fn().mockResolvedValue({}),
-}));
-
-beforeEach(() => {
-  jest.useFakeTimers();
-  jest.clearAllMocks();
-});
-
-afterEach(() => {
-  jest.runOnlyPendingTimers();
-  jest.useRealTimers();
-});
-
-it('should render correctly', async () => {
-  (getActivity as jest.Mock)
-    .mockResolvedValueOnce({ tasks: [mockDumpTask()] })
-    .mockResolvedValueOnce({ tasks: [mockDumpTask()] })
-    .mockResolvedValueOnce({ tasks: [mockDumpTask()] });
-
-  let wrapper = shallowRender();
-  expect(wrapper).toMatchSnapshot('loading');
-
-  await waitAndUpdate(wrapper);
-
-  expect(wrapper).toMatchSnapshot('loaded');
-
-  wrapper = shallowRender({ hasFeature: jest.fn().mockReturnValue(false) });
-  await waitAndUpdate(wrapper);
-  expect(wrapper).toMatchSnapshot('loaded without import');
-});
-
-it('should poll for task status update', async () => {
-  const wrapper = shallowRender();
-  await waitAndUpdate(wrapper);
-
-  jest.clearAllMocks();
-
-  const finalStatus = mockDumpStatus({ exportedDump: 'export-path' });
-  (getStatus as jest.Mock)
-    .mockResolvedValueOnce(mockDumpStatus())
-    .mockResolvedValueOnce(finalStatus);
-  (getActivity as jest.Mock)
-    .mockResolvedValueOnce({ tasks: [mockDumpTask({ status: TaskStatuses.Pending })] })
-    .mockResolvedValueOnce({ tasks: [mockDumpTask({ status: TaskStatuses.Success })] });
-
-  wrapper.instance().poll();
-
-  // wait for all promises
-  await waitAndUpdate(wrapper);
-  jest.runAllTimers();
-  await waitAndUpdate(wrapper);
-
-  expect(getStatus).toHaveBeenCalledTimes(2);
-  expect(wrapper.state().status).toBe(finalStatus);
-});
-
-function shallowRender(overrides: Partial<ProjectDumpApp['props']> = {}) {
-  return shallow<ProjectDumpApp>(
-    <ProjectDumpApp
-      hasFeature={jest.fn().mockReturnValue(true)}
-      component={mockComponent()}
-      {...overrides}
-    />
-  );
-}
diff --git a/server/sonar-web/src/main/js/apps/projectDump/__tests__/__snapshots__/ProjectDumpApp-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectDump/__tests__/__snapshots__/ProjectDumpApp-test.tsx.snap
deleted file mode 100644 (file)
index caba04a..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`should render correctly: loaded 1`] = `
-<div
-  className="page page-limited"
-  id="project-dump"
->
-  <Helmet
-    defer={false}
-    encodeSpecialCharacters={true}
-    prioritizeSeoTags={false}
-    title="project_dump.page"
-  />
-  <header
-    className="page-header"
-  >
-    <h1
-      className="page-title"
-    >
-      project_dump.page
-    </h1>
-    <div
-      className="page-description"
-    >
-      project_dump.page.description
-    </div>
-  </header>
-  <div
-    className="columns"
-  >
-    <div
-      className="column-half"
-    >
-      <Export
-        componentKey="my-project"
-        loadStatus={[Function]}
-        status={{}}
-        task={
-          {
-            "executedAt": "2020-03-12T12:22:20Z",
-            "startedAt": "2020-03-12T12:20:20Z",
-            "status": "SUCCESS",
-            "submittedAt": "2020-03-12T12:15:20Z",
-          }
-        }
-      />
-    </div>
-    <div
-      className="column-half"
-    >
-      <Import
-        analysis={
-          {
-            "executedAt": "2020-03-12T12:22:20Z",
-            "startedAt": "2020-03-12T12:20:20Z",
-            "status": "SUCCESS",
-            "submittedAt": "2020-03-12T12:15:20Z",
-          }
-        }
-        componentKey="my-project"
-        importEnabled={true}
-        loadStatus={[Function]}
-        status={{}}
-        task={
-          {
-            "executedAt": "2020-03-12T12:22:20Z",
-            "startedAt": "2020-03-12T12:20:20Z",
-            "status": "SUCCESS",
-            "submittedAt": "2020-03-12T12:15:20Z",
-          }
-        }
-      />
-    </div>
-  </div>
-</div>
-`;
-
-exports[`should render correctly: loaded without import 1`] = `
-<div
-  className="page page-limited"
-  id="project-dump"
->
-  <Helmet
-    defer={false}
-    encodeSpecialCharacters={true}
-    prioritizeSeoTags={false}
-    title="project_dump.page"
-  />
-  <header
-    className="page-header"
-  >
-    <h1
-      className="page-title"
-    >
-      project_dump.page
-    </h1>
-    <div
-      className="page-description"
-    >
-      project_dump.page.description_without_import
-    </div>
-  </header>
-  <div
-    className="columns"
-  >
-    <div
-      className="column-half"
-    >
-      <Export
-        componentKey="my-project"
-        loadStatus={[Function]}
-        status={{}}
-      />
-    </div>
-    <div
-      className="column-half"
-    >
-      <Import
-        componentKey="my-project"
-        importEnabled={false}
-        loadStatus={[Function]}
-        status={{}}
-      />
-    </div>
-  </div>
-</div>
-`;
-
-exports[`should render correctly: loading 1`] = `
-<div
-  className="page page-limited"
-  id="project-dump"
->
-  <Helmet
-    defer={false}
-    encodeSpecialCharacters={true}
-    prioritizeSeoTags={false}
-    title="project_dump.page"
-  />
-  <header
-    className="page-header"
-  >
-    <h1
-      className="page-title"
-    >
-      project_dump.page
-    </h1>
-    <div
-      className="page-description"
-    >
-      project_dump.page.description
-    </div>
-  </header>
-  <i
-    className="spinner"
-  />
-</div>
-`;
diff --git a/server/sonar-web/src/main/js/apps/projectDump/components/__tests__/Export-test.tsx b/server/sonar-web/src/main/js/apps/projectDump/components/__tests__/Export-test.tsx
deleted file mode 100644 (file)
index e4be5cd..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 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 { mockDumpStatus, mockDumpTask } from '../../../../helpers/testMocks';
-import { TaskStatuses } from '../../../../types/tasks';
-import Export from '../Export';
-
-jest.mock('../../../../api/project-dump', () => ({
-  doExport: jest.fn().mockResolvedValue({}),
-}));
-
-it('should render correctly', () => {
-  expect(shallowRender()).toMatchSnapshot('no task');
-  expect(shallowRender({ status: mockDumpStatus({ canBeExported: false }) })).toMatchSnapshot(
-    'cannot export'
-  );
-  expect(shallowRender({ task: mockDumpTask({ status: TaskStatuses.Pending }) })).toMatchSnapshot(
-    'task pending'
-  );
-  expect(
-    shallowRender({ task: mockDumpTask({ status: TaskStatuses.InProgress }) })
-  ).toMatchSnapshot('task in progress');
-  expect(shallowRender({ task: mockDumpTask({ status: TaskStatuses.Failed }) })).toMatchSnapshot(
-    'task failed'
-  );
-  expect(
-    shallowRender({
-      status: mockDumpStatus({ exportedDump: 'dump-file' }),
-      task: mockDumpTask({ status: TaskStatuses.Success }),
-    })
-  ).toMatchSnapshot('success');
-});
-
-function shallowRender(overrides: Partial<Export['props']> = {}) {
-  return shallow<Export>(
-    <Export
-      componentKey="key"
-      loadStatus={jest.fn()}
-      status={mockDumpStatus()}
-      task={undefined}
-      {...overrides}
-    />
-  );
-}
diff --git a/server/sonar-web/src/main/js/apps/projectDump/components/__tests__/Import-test.tsx b/server/sonar-web/src/main/js/apps/projectDump/components/__tests__/Import-test.tsx
deleted file mode 100644 (file)
index 95f1fdc..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 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 { mockDumpStatus, mockDumpTask } from '../../../../helpers/testMocks';
-import { TaskStatuses } from '../../../../types/tasks';
-import Import from '../Import';
-
-jest.mock('../../../../api/project-dump', () => ({
-  doImport: jest.fn().mockResolvedValue({}),
-}));
-
-it('should render correctly', () => {
-  expect(
-    shallowRender({ status: mockDumpStatus({ dumpToImport: 'import-file.zip' }) })
-  ).toMatchSnapshot('import form');
-  expect(shallowRender()).toMatchSnapshot('no dump to import');
-  expect(shallowRender({ status: mockDumpStatus({ canBeImported: false }) })).toMatchSnapshot(
-    'cannot import'
-  );
-  expect(shallowRender({ task: mockDumpTask({ status: TaskStatuses.Success }) })).toMatchSnapshot(
-    'success'
-  );
-  expect(
-    shallowRender({
-      analysis: mockDumpTask(),
-      task: mockDumpTask({ status: TaskStatuses.Success }),
-    })
-  ).toMatchSnapshot('success, but with analysis -> show form');
-  expect(shallowRender({ task: mockDumpTask({ status: TaskStatuses.Pending }) })).toMatchSnapshot(
-    'pending'
-  );
-  expect(
-    shallowRender({ task: mockDumpTask({ status: TaskStatuses.InProgress }) })
-  ).toMatchSnapshot('in progress');
-  expect(shallowRender({ task: mockDumpTask({ status: TaskStatuses.Failed }) })).toMatchSnapshot(
-    'failed'
-  );
-  expect(shallowRender({ importEnabled: false })).toMatchSnapshot('import disabled');
-});
-
-function shallowRender(overrides: Partial<Import['props']> = {}) {
-  return shallow<Import>(
-    <Import
-      importEnabled
-      analysis={undefined}
-      componentKey="key"
-      loadStatus={jest.fn()}
-      status={mockDumpStatus()}
-      task={undefined}
-      {...overrides}
-    />
-  );
-}
diff --git a/server/sonar-web/src/main/js/apps/projectDump/components/__tests__/__snapshots__/Export-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectDump/components/__tests__/__snapshots__/Export-test.tsx.snap
deleted file mode 100644 (file)
index 8e02d72..0000000
+++ /dev/null
@@ -1,206 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`should render correctly: cannot export 1`] = `
-<div
-  className="boxed-group"
-  id="project-export"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.export
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-  >
-    <Alert
-      id="export-not-possible"
-      variant="warning"
-    >
-      project_dump.can_not_export
-    </Alert>
-  </div>
-</div>
-`;
-
-exports[`should render correctly: no task 1`] = `
-<div
-  className="boxed-group"
-  id="project-export"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.export
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-  >
-    <div>
-      <div
-        className="spacer-bottom"
-      >
-        project_dump.export_form_description
-      </div>
-      <Button
-        onClick={[Function]}
-      >
-        project_dump.do_export
-      </Button>
-    </div>
-  </div>
-</div>
-`;
-
-exports[`should render correctly: success 1`] = `
-<div
-  className="boxed-group"
-  id="project-export"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.export
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-  >
-    <Alert
-      className="export-dump"
-      variant="success"
-    >
-      <DateTimeFormatter
-        date="2020-03-12T12:22:20Z"
-      >
-        <Component />
-      </DateTimeFormatter>
-      <div
-        className="export-dump-path"
-      >
-        <code
-          tabIndex={0}
-        >
-          dump-file
-        </code>
-      </div>
-    </Alert>
-    <div>
-      <div
-        className="spacer-bottom"
-      >
-        project_dump.export_form_description
-      </div>
-      <Button
-        onClick={[Function]}
-      >
-        project_dump.do_export
-      </Button>
-    </div>
-  </div>
-</div>
-`;
-
-exports[`should render correctly: task failed 1`] = `
-<div
-  className="boxed-group"
-  id="project-export"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.export
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-  >
-    <Alert
-      id="export-in-progress"
-      variant="error"
-    >
-      project_dump.failed_export
-      <ForwardRef(Link)
-        className="spacer-left"
-        to="/project/background_tasks?id=key&status=FAILED&taskType=PROJECT_EXPORT"
-      >
-        project_dump.see_details
-      </ForwardRef(Link)>
-    </Alert>
-    <div>
-      <div
-        className="spacer-bottom"
-      >
-        project_dump.export_form_description
-      </div>
-      <Button
-        onClick={[Function]}
-      >
-        project_dump.do_export
-      </Button>
-    </div>
-  </div>
-</div>
-`;
-
-exports[`should render correctly: task in progress 1`] = `
-<div
-  className="boxed-group"
-  id="project-export"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.export
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-    id="export-in-progress"
-  >
-    <i
-      className="spinner spacer-right"
-    />
-    <DateFromNow
-      date="2020-03-12T12:20:20Z"
-    >
-      <Component />
-    </DateFromNow>
-  </div>
-</div>
-`;
-
-exports[`should render correctly: task pending 1`] = `
-<div
-  className="boxed-group"
-  id="project-export"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.export
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-    id="export-pending"
-  >
-    <i
-      className="spinner spacer-right"
-    />
-    <DateTimeFormatter
-      date="2020-03-12T12:15:20Z"
-    >
-      <Component />
-    </DateTimeFormatter>
-  </div>
-</div>
-`;
diff --git a/server/sonar-web/src/main/js/apps/projectDump/components/__tests__/__snapshots__/Import-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectDump/components/__tests__/__snapshots__/Import-test.tsx.snap
deleted file mode 100644 (file)
index 0a0c403..0000000
+++ /dev/null
@@ -1,252 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`should render correctly: cannot import 1`] = `
-<div
-  className="boxed-group"
-  id="project-import"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.import
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-    id="import-not-possible"
-  >
-    project_dump.can_not_import
-  </div>
-</div>
-`;
-
-exports[`should render correctly: failed 1`] = `
-<div
-  className="boxed-group"
-  id="project-import"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.import
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-  >
-    <Alert
-      id="export-in-progress"
-      variant="error"
-    >
-      project_dump.failed_import
-      <ForwardRef(Link)
-        className="spacer-left"
-        to={
-          {
-            "hash": "",
-            "pathname": "/project/background_tasks",
-            "search": "?id=key&status=FAILED&taskType=PROJECT_IMPORT",
-          }
-        }
-      >
-        project_dump.see_details
-      </ForwardRef(Link)>
-    </Alert>
-    <div>
-      <div
-        className="spacer-bottom"
-      >
-        project_dump.import_form_description
-      </div>
-      <Button
-        onClick={[Function]}
-      >
-        project_dump.do_import
-      </Button>
-    </div>
-  </div>
-</div>
-`;
-
-exports[`should render correctly: import disabled 1`] = `
-<div
-  className="boxed-group import-disabled text-muted"
-  id="project-import"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.import
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-  >
-    project_dump.import_form_description_disabled
-  </div>
-</div>
-`;
-
-exports[`should render correctly: import form 1`] = `
-<div
-  className="boxed-group"
-  id="project-import"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.import
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-  >
-    <div>
-      <div
-        className="spacer-bottom"
-      >
-        project_dump.import_form_description
-      </div>
-      <Button
-        onClick={[Function]}
-      >
-        project_dump.do_import
-      </Button>
-    </div>
-  </div>
-</div>
-`;
-
-exports[`should render correctly: in progress 1`] = `
-<div
-  className="boxed-group"
-  id="project-import"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.import
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-    id="import-in-progress"
-  >
-    <i
-      className="spinner spacer-right"
-    />
-    <DateFromNow
-      date="2020-03-12T12:20:20Z"
-    >
-      <Component />
-    </DateFromNow>
-  </div>
-</div>
-`;
-
-exports[`should render correctly: no dump to import 1`] = `
-<div
-  className="boxed-group"
-  id="project-import"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.import
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-  >
-    <Alert
-      id="import-no-file"
-      variant="warning"
-    >
-      project_dump.no_file_to_import
-    </Alert>
-  </div>
-</div>
-`;
-
-exports[`should render correctly: pending 1`] = `
-<div
-  className="boxed-group"
-  id="project-import"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.import
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-    id="import-pending"
-  >
-    <i
-      className="spinner spacer-right"
-    />
-    <DateTimeFormatter
-      date="2020-03-12T12:15:20Z"
-    >
-      <Component />
-    </DateTimeFormatter>
-  </div>
-</div>
-`;
-
-exports[`should render correctly: success 1`] = `
-<div
-  className="boxed-group"
-  id="project-import"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.import
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-  >
-    <DateTimeFormatter
-      date="2020-03-12T12:22:20Z"
-    >
-      <Component />
-    </DateTimeFormatter>
-  </div>
-</div>
-`;
-
-exports[`should render correctly: success, but with analysis -> show form 1`] = `
-<div
-  className="boxed-group"
-  id="project-import"
->
-  <div
-    className="boxed-group-header"
-  >
-    <h2>
-      project_dump.import
-    </h2>
-  </div>
-  <div
-    className="boxed-group-inner"
-  >
-    <Alert
-      id="import-no-file"
-      variant="warning"
-    >
-      project_dump.no_file_to_import
-    </Alert>
-  </div>
-</div>
-`;
index f42c5dc0434b5ae8a26d9568f24175b16763cca1..7295e958d166842f3c289b745f12718a0b46fe96 100644 (file)
@@ -22,8 +22,8 @@ import { TaskStatuses } from './tasks';
 export interface DumpStatus {
   canBeExported: boolean;
   canBeImported: boolean;
-  dumpToImport: string;
-  exportedDump: string;
+  dumpToImport?: string;
+  exportedDump?: string;
 }
 
 export interface DumpTask {