+++ /dev/null
-/*
- * 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 * as React from 'react';
-import { ComponentContext } from '../../../app/components/componentContext/ComponentContext';
-import { mockComponent } from '../../../helpers/mocks/component';
-import { renderApp } from '../../../helpers/testReactTestingUtils';
-import { ComponentContextShape } from '../../../types/component';
-import { Component } from '../../../types/types';
-import App from '../App';
-
-it('should render with component', () => {
- renderProjectDeletionApp(mockComponent({ key: 'foo', name: 'Foo', qualifier: 'TRK' }));
-
- expect(screen.getByText('deletion.page')).toBeInTheDocument();
-});
-
-it('should render with no component', () => {
- renderProjectDeletionApp();
-
- expect(screen.queryByText('deletion.page')).not.toBeInTheDocument();
-});
-
-function renderProjectDeletionApp(component?: Component) {
- renderApp(
- 'project-delete',
- <ComponentContext.Provider value={{ component } as ComponentContextShape}>
- <App />
- </ComponentContext.Provider>
- );
-}
+++ /dev/null
-/*
- * 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 { deleteApplication } from '../../../api/application';
-import { deletePortfolio, deleteProject } from '../../../api/project-management';
-import { mockRouter } from '../../../helpers/testMocks';
-import { Form } from '../Form';
-
-jest.mock('../../../api/project-management', () => ({
- deleteProject: jest.fn().mockResolvedValue(undefined),
- deletePortfolio: jest.fn().mockResolvedValue(undefined),
-}));
-
-jest.mock('../../../api/application', () => ({
- deleteApplication: jest.fn().mockResolvedValue(undefined),
-}));
-
-beforeEach(() => {
- jest.clearAllMocks();
-});
-
-it('should render', () => {
- const component = { key: 'foo', name: 'Foo', qualifier: 'TRK' };
- const form = shallow(<Form component={component} router={mockRouter()} />);
- expect(form).toMatchSnapshot();
- expect(form.prop<Function>('children')({ onClick: jest.fn() })).toMatchSnapshot();
-});
-
-it('should delete project', async () => {
- const component = { key: 'foo', name: 'Foo', qualifier: 'TRK' };
- const router = mockRouter();
- const form = shallow(<Form component={component} router={router} />);
- form.prop<Function>('onConfirm')();
- expect(deleteProject).toHaveBeenCalledWith('foo');
- await new Promise(setImmediate);
- expect(router.replace).toHaveBeenCalledWith('/');
-});
-
-it('should delete portfolio', async () => {
- const component = { key: 'foo', name: 'Foo', qualifier: 'VW' };
- const router = mockRouter();
- const form = shallow(<Form component={component} router={router} />);
- form.prop<Function>('onConfirm')();
- expect(deletePortfolio).toHaveBeenCalledWith('foo');
- expect(deleteProject).not.toHaveBeenCalled();
- expect(deleteApplication).not.toHaveBeenCalled();
- await new Promise(setImmediate);
- expect(router.replace).toHaveBeenCalledWith('/portfolios');
-});
-
-it('should delete application', async () => {
- const component = { key: 'foo', name: 'Foo', qualifier: 'APP' };
- const router = mockRouter();
- const form = shallow(<Form component={component} router={router} />);
- form.prop<Function>('onConfirm')();
- expect(deleteApplication).toHaveBeenCalledWith('foo');
- expect(deleteProject).not.toHaveBeenCalled();
- expect(deletePortfolio).not.toHaveBeenCalled();
- await new Promise(setImmediate);
- expect(router.replace).toHaveBeenCalledWith('/');
-});
+++ /dev/null
-/*
- * 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 Header from '../Header';
-
-it('should render', () => {
- expect(shallow(<Header component={{ qualifier: 'TRK' }} />)).toMatchSnapshot();
- expect(shallow(<Header component={{ qualifier: 'VW' }} />)).toMatchSnapshot();
- expect(shallow(<Header component={{ qualifier: 'APP' }} />)).toMatchSnapshot();
-});
--- /dev/null
+/*
+ * 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 userEvent from '@testing-library/user-event';
+import * as React from 'react';
+import { deleteApplication } from '../../../api/application';
+import { deletePortfolio, deleteProject } from '../../../api/project-management';
+import { ComponentContext } from '../../../app/components/componentContext/ComponentContext';
+import { mockComponent } from '../../../helpers/mocks/component';
+import { renderApp } from '../../../helpers/testReactTestingUtils';
+import { byRole, byText } from '../../../helpers/testSelector';
+import { ComponentContextShape, ComponentQualifier } from '../../../types/component';
+import { Component } from '../../../types/types';
+import App from '../App';
+
+jest.mock('../../../api/project-management');
+jest.mock('../../../api/application');
+
+beforeEach(() => {
+ jest.clearAllMocks();
+});
+
+it('should be able to delete project', async () => {
+ const user = userEvent.setup();
+
+ jest.mock('../../../api/project-management', () => {
+ return {
+ ...jest.requireActual('../../../api/project-management'),
+ deleteProject: jest.fn().mockResolvedValue(undefined),
+ };
+ });
+
+ renderProjectDeletionApp(
+ mockComponent({ key: 'foo', name: 'Foo', qualifier: ComponentQualifier.Project })
+ );
+
+ expect(byText('deletion.page').get()).toBeInTheDocument();
+ expect(byText('project_deletion.page.description').get()).toBeInTheDocument();
+ user.click(byRole('button', { name: 'delete' }).get());
+ expect(await byRole('dialog', { name: 'qualifier.delete.TRK' }).find()).toBeInTheDocument();
+ user.click(
+ byRole('dialog', { name: 'qualifier.delete.TRK' }).byRole('button', { name: 'delete' }).get()
+ );
+
+ expect(await byText(/project_deletion.resource_dele/).find()).toBeInTheDocument();
+ expect(deleteProject).toHaveBeenCalledWith('foo');
+});
+
+it('should be able to delete Portfolio', async () => {
+ const user = userEvent.setup();
+
+ jest.mock('../../../api/project-management', () => {
+ return {
+ ...jest.requireActual('../../../api/project-management'),
+ deletePortfolio: jest.fn().mockResolvedValue(undefined),
+ };
+ });
+
+ renderProjectDeletionApp(
+ mockComponent({ key: 'foo', name: 'Foo', qualifier: ComponentQualifier.Portfolio })
+ );
+
+ expect(byText('deletion.page').get()).toBeInTheDocument();
+ expect(byText('portfolio_deletion.page.description').get()).toBeInTheDocument();
+
+ user.click(byRole('button', { name: 'delete' }).get());
+
+ expect(await byRole('dialog', { name: 'qualifier.delete.VW' }).find()).toBeInTheDocument();
+ user.click(
+ byRole('dialog', { name: 'qualifier.delete.VW' }).byRole('button', { name: 'delete' }).get()
+ );
+
+ expect(await byText(/project_deletion.resource_dele/).find()).toBeInTheDocument();
+ expect(deletePortfolio).toHaveBeenCalledWith('foo');
+});
+
+it('should be able to delete Application', async () => {
+ const user = userEvent.setup();
+
+ jest.mock('../../../api/application', () => {
+ return {
+ ...jest.requireActual('../../../api/application'),
+ deleteApplication: jest.fn().mockResolvedValue(undefined),
+ };
+ });
+
+ renderProjectDeletionApp(
+ mockComponent({ key: 'foo', name: 'Foo', qualifier: ComponentQualifier.Application })
+ );
+
+ expect(byText('deletion.page').get()).toBeInTheDocument();
+ expect(byText('application_deletion.page.description').get()).toBeInTheDocument();
+
+ user.click(byRole('button', { name: 'delete' }).get());
+ expect(await byRole('dialog', { name: 'qualifier.delete.APP' }).find()).toBeInTheDocument();
+ user.click(
+ byRole('dialog', { name: 'qualifier.delete.APP' }).byRole('button', { name: 'delete' }).get()
+ );
+
+ expect(await byText(/project_deletion.resource_dele/).find()).toBeInTheDocument();
+ expect(deleteApplication).toHaveBeenCalledWith('foo');
+});
+
+it('should render with no component', () => {
+ renderProjectDeletionApp();
+
+ expect(byText('deletion.page').query()).not.toBeInTheDocument();
+});
+
+function renderProjectDeletionApp(component?: Component) {
+ renderApp(
+ 'project-delete',
+ <ComponentContext.Provider value={{ component } as ComponentContextShape}>
+ <App />
+ </ComponentContext.Provider>
+ );
+}
+++ /dev/null
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`should render 1`] = `
-<ConfirmButton
- confirmButtonText="delete"
- isDestructive={true}
- modalBody="project_deletion.delete_resource_confirmation.Foo"
- modalHeader="qualifier.delete.TRK"
- onConfirm={[Function]}
->
- <Component />
-</ConfirmButton>
-`;
-
-exports[`should render 2`] = `
-<Button
- className="button-red"
- id="delete-project"
- onClick={[MockFunction]}
->
- delete
-</Button>
-`;
+++ /dev/null
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`should render 1`] = `
-<header
- className="page-header"
->
- <h1
- className="page-title"
- >
- deletion.page
- </h1>
- <div
- className="page-description"
- >
- project_deletion.page.description
- </div>
-</header>
-`;
-
-exports[`should render 2`] = `
-<header
- className="page-header"
->
- <h1
- className="page-title"
- >
- deletion.page
- </h1>
- <div
- className="page-description"
- >
- portfolio_deletion.page.description
- </div>
-</header>
-`;
-
-exports[`should render 3`] = `
-<header
- className="page-header"
->
- <h1
- className="page-title"
- >
- deletion.page
- </h1>
- <div
- className="page-description"
- >
- application_deletion.page.description
- </div>
-</header>
-`;