remove 4th batch of unmount() calls

This commit is contained in:
Keith J. Grant 2021-07-09 11:36:23 -07:00
parent 81c16f4fa7
commit 0185269d97
33 changed files with 53 additions and 128 deletions

View File

@ -16,7 +16,6 @@ jest.mock('../../api/models/Users');
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useHistory: () => ({ push: jest.fn(), location: { pathname: {} } }),
}));
// TODO: Once error handling is functional in

View File

@ -5,10 +5,6 @@ import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
import ScreenHeader from './ScreenHeader';
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
}));
describe('<ScreenHeader />', () => {
let breadcrumbWrapper;
let breadcrumb;

View File

@ -15,6 +15,7 @@ jest.mock('react-router-dom', () => ({
}),
useParams: () => ({ id: 1 }),
}));
const options = {
data: {
actions: {

View File

@ -11,10 +11,6 @@ import Settings from './Settings';
jest.mock('../../api');
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
}));
describe('<Settings />', () => {
let wrapper;

View File

@ -50,10 +50,11 @@ describe('<WorkflowJobTemplate />', () => {
},
});
});
afterEach(() => {
jest.clearAllMocks();
wrapper.unmount();
});
test('initially renders successfully', async () => {
await act(async () => {
wrapper = mountWithContexts(
@ -61,6 +62,7 @@ describe('<WorkflowJobTemplate />', () => {
);
});
});
test('When component mounts API is called and the response is put in state', async () => {
await act(async () => {
wrapper = mountWithContexts(
@ -70,6 +72,7 @@ describe('<WorkflowJobTemplate />', () => {
expect(WorkflowJobTemplatesAPI.readDetail).toBeCalled();
expect(OrganizationsAPI.read).toBeCalled();
});
test('notifications tab shown for admins', async () => {
await act(async () => {
wrapper = mountWithContexts(
@ -84,6 +87,7 @@ describe('<WorkflowJobTemplate />', () => {
);
expect(tabs.at(3).text()).toEqual('Notifications');
});
test('notifications tab hidden with reduced permissions', async () => {
OrganizationsAPI.read.mockResolvedValue({
data: {
@ -135,6 +139,7 @@ describe('<WorkflowJobTemplate />', () => {
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
});
test('should call to get webhook key', async () => {
const history = createMemoryHistory({
initialEntries: ['/templates/workflow_job_template/1/foobar'],
@ -161,6 +166,7 @@ describe('<WorkflowJobTemplate />', () => {
});
expect(WorkflowJobTemplatesAPI.readWebhookKey).toHaveBeenCalled();
});
test('should not call to get webhook key', async () => {
WorkflowJobTemplatesAPI.readWorkflowJobTemplateOptions.mockResolvedValueOnce(
{

View File

@ -15,10 +15,6 @@ describe('DeleteAllNodesModal', () => {
);
});
afterAll(() => {
wrapper.unmount();
});
test('Delete All button dispatches as expected', () => {
wrapper.find('button#confirm-delete-all-nodes').simulate('click');
expect(dispatch).toHaveBeenCalledWith({

View File

@ -32,10 +32,6 @@ describe('LinkDeleteModal', () => {
);
});
afterAll(() => {
wrapper.unmount();
});
test('Confirm button dispatches as expected', () => {
wrapper.find('button#confirm-link-removal').simulate('click');
expect(dispatch).toHaveBeenCalledWith({

View File

@ -27,10 +27,6 @@ describe('LinkModal', () => {
);
});
afterAll(() => {
wrapper.unmount();
});
test('Dropdown defaults to success when adding new link', () => {
expect(wrapper.find('AnsibleSelect').prop('value')).toBe('success');
});
@ -57,6 +53,7 @@ describe('LinkModal', () => {
expect(onConfirm).toHaveBeenCalledWith('always');
});
});
describe('Editing existing link', () => {
test('Dropdown defaults to existing link type when editing link', () => {
wrapper = mountWithContexts(
@ -79,7 +76,6 @@ describe('LinkModal', () => {
</WorkflowDispatchContext.Provider>
);
expect(wrapper.find('AnsibleSelect').prop('value')).toBe('failure');
wrapper.unmount();
});
});
});

View File

@ -32,10 +32,6 @@ describe('NodeDeleteModal', () => {
);
});
afterAll(() => {
wrapper.unmount();
});
test('Mounts successfully', () => {
expect(wrapper.length).toBe(1);
});
@ -63,6 +59,7 @@ describe('NodeDeleteModal', () => {
});
});
});
describe('Node without unified job template', () => {
test('Mounts successfully', () => {
wrapper = mountWithContexts(
@ -79,7 +76,6 @@ describe('NodeDeleteModal', () => {
</WorkflowDispatchContext.Provider>
);
expect(wrapper.length).toBe(1);
wrapper.unmount();
});
});
});

View File

@ -28,10 +28,6 @@ describe('NodeNextButton', () => {
);
});
afterAll(() => {
wrapper.unmount();
});
test('Button text matches', () => {
expect(wrapper.find('button').text()).toBe(buttonText);
});

View File

@ -15,9 +15,6 @@ const onUpdateNodeResource = jest.fn();
describe('InventorySourcesList', () => {
let wrapper;
afterEach(() => {
wrapper.unmount();
});
test('Row selected when nodeResource id matches row id and clicking new row makes expected callback', async () => {
InventorySourcesAPI.read.mockResolvedValueOnce({
data: {
@ -74,6 +71,7 @@ describe('InventorySourcesList', () => {
url: '/api/v2/inventory_sources/2',
});
});
test('Error shown when read() request errors', async () => {
InventorySourcesAPI.read.mockRejectedValue(new Error());
await act(async () => {

View File

@ -17,8 +17,8 @@ describe('JobTemplatesList', () => {
let wrapper;
afterEach(() => {
jest.clearAllMocks();
wrapper.unmount();
});
test('Row selected when nodeResource id matches row id and clicking new row makes expected callback', async () => {
JobTemplatesAPI.read.mockResolvedValueOnce({
data: {
@ -81,6 +81,7 @@ describe('JobTemplatesList', () => {
project: 2,
});
});
test('Error shown when read() request errors', async () => {
JobTemplatesAPI.read.mockRejectedValue(new Error());
JobTemplatesAPI.readOptions.mockResolvedValue({

View File

@ -15,9 +15,7 @@ const onUpdateNodeResource = jest.fn();
describe('ProjectsList', () => {
let wrapper;
afterEach(() => {
wrapper.unmount();
});
test('Row selected when nodeResource id matches row id and clicking new row makes expected callback', async () => {
ProjectsAPI.read.mockResolvedValueOnce({
data: {
@ -70,6 +68,7 @@ describe('ProjectsList', () => {
url: '/api/v2/projects/2',
});
});
test('Error shown when read() request errors', async () => {
ProjectsAPI.read.mockRejectedValue(new Error());
await act(async () => {

View File

@ -15,9 +15,7 @@ const onUpdateNodeResource = jest.fn();
describe('WorkflowJobTemplatesList', () => {
let wrapper;
afterEach(() => {
wrapper.unmount();
});
test('Row selected when nodeResource id matches row id and clicking new row makes expected callback', async () => {
WorkflowJobTemplatesAPI.read.mockResolvedValueOnce({
data: {
@ -76,6 +74,7 @@ describe('WorkflowJobTemplatesList', () => {
url: '/api/v2/workflow_job_templates/2',
});
});
test('Error shown when read() request errors', async () => {
WorkflowJobTemplatesAPI.read.mockRejectedValue(new Error());
await act(async () => {

View File

@ -85,7 +85,6 @@ describe('NodeViewModal', () => {
afterAll(() => {
jest.resetAllMocks();
wrapper.unmount();
});
test('should render prompt detail', () => {
@ -151,7 +150,6 @@ describe('NodeViewModal', () => {
expect(JobTemplatesAPI.readWebhookKey).not.toHaveBeenCalledWith();
expect(JobTemplatesAPI.readLaunch).toHaveBeenCalledWith(1);
expect(JobTemplatesAPI.readInstanceGroups).toHaveBeenCalledTimes(1);
wrapper.unmount();
jest.clearAllMocks();
});
@ -169,7 +167,6 @@ describe('NodeViewModal', () => {
});
waitForLoaded(wrapper);
expect(wrapper.find('ContentError').length).toBe(1);
wrapper.unmount();
jest.clearAllMocks();
});
@ -186,7 +183,6 @@ describe('NodeViewModal', () => {
});
waitForLoaded(wrapper);
expect(wrapper.find('Button#node-view-edit-button').length).toBe(1);
wrapper.unmount();
jest.clearAllMocks();
});
@ -203,7 +199,6 @@ describe('NodeViewModal', () => {
});
waitForLoaded(wrapper);
expect(wrapper.find('Button#node-view-edit-button').length).toBe(0);
wrapper.unmount();
jest.clearAllMocks();
});
});
@ -237,7 +232,6 @@ describe('NodeViewModal', () => {
expect(WorkflowJobTemplatesAPI.readLaunch).not.toHaveBeenCalled();
expect(JobTemplatesAPI.readLaunch).not.toHaveBeenCalled();
expect(JobTemplatesAPI.readInstanceGroups).not.toHaveBeenCalled();
wrapper.unmount();
jest.clearAllMocks();
});
});
@ -271,7 +265,6 @@ describe('NodeViewModal', () => {
expect(WorkflowJobTemplatesAPI.readLaunch).not.toHaveBeenCalled();
expect(JobTemplatesAPI.readLaunch).not.toHaveBeenCalled();
expect(JobTemplatesAPI.readInstanceGroups).not.toHaveBeenCalled();
wrapper.unmount();
jest.clearAllMocks();
});
});
@ -305,7 +298,6 @@ describe('NodeViewModal', () => {
expect(WorkflowJobTemplatesAPI.readLaunch).not.toHaveBeenCalled();
expect(JobTemplatesAPI.readLaunch).not.toHaveBeenCalled();
expect(JobTemplatesAPI.readInstanceGroups).not.toHaveBeenCalled();
wrapper.unmount();
jest.clearAllMocks();
});
});

View File

@ -16,10 +16,6 @@ describe('RunStep', () => {
);
});
afterAll(() => {
wrapper.unmount();
});
test('Default selected card matches default link type when present', () => {
expect(wrapper.find('#link-type-success').props().isSelected).toBe(true);
expect(wrapper.find('#link-type-failure').props().isSelected).toBe(false);

View File

@ -17,10 +17,6 @@ describe('UnsavedChangesModal', () => {
);
});
afterAll(() => {
wrapper.unmount();
});
test('Exit Without Saving button dispatches as expected', () => {
wrapper.find('button#confirm-exit-without-saving').simulate('click');
expect(onExit).toHaveBeenCalled();

View File

@ -141,7 +141,6 @@ describe('Visualizer', () => {
});
afterAll(() => {
wrapper.unmount();
delete window.SVGElement.prototype.getBBox;
delete window.SVGElement.prototype.getBoundingClientRect;
delete window.SVGElement.prototype.height;

View File

@ -62,9 +62,6 @@ describe('VisualizerLink', () => {
</WorkflowDispatchContext.Provider>
);
});
afterAll(() => {
wrapper.unmount();
});
test('Displays action tooltip on hover and updates help text on hover', () => {
expect(wrapper.find('WorkflowActionTooltip').length).toBe(0);

View File

@ -73,12 +73,11 @@ describe('VisualizerNode', () => {
afterEach(() => {
jest.clearAllMocks();
});
afterAll(() => {
wrapper.unmount();
});
test('Displays unified job template name inside node', () => {
expect(wrapper.find('NodeResourceName').text()).toBe('Automation JT');
});
test('Displays action tooltip on hover and updates help text on hover', () => {
expect(wrapper.find('WorkflowActionTooltip').length).toBe(0);
wrapper.find('g').simulate('mouseenter');
@ -234,9 +233,7 @@ describe('VisualizerNode', () => {
</WorkflowDispatchContext.Provider>
);
});
afterAll(() => {
wrapper.unmount();
});
test('Displays correct help text when hovering over node while adding link', () => {
expect(wrapper.find('WorkflowActionTooltip').length).toBe(0);
wrapper.find('g').simulate('mouseenter');
@ -248,6 +245,7 @@ describe('VisualizerNode', () => {
expect(wrapper.find('WorkflowActionTooltip').length).toBe(0);
expect(updateHelpText).toHaveBeenCalledWith(null);
});
test('Dispatches properly when node is clicked', () => {
wrapper
.find('foreignObject')
@ -259,6 +257,7 @@ describe('VisualizerNode', () => {
});
});
});
describe('Node without unified job template', () => {
test('Displays DELETED text inside node when unified job template is missing', () => {
const wrapper = mountWithContexts(
@ -279,6 +278,7 @@ describe('VisualizerNode', () => {
expect(wrapper.find('NodeResourceName').text()).toBe('DELETED');
});
});
describe('Node without full unified job template', () => {
let wrapper;
beforeEach(() => {
@ -336,9 +336,7 @@ describe('VisualizerNode', () => {
</WorkflowDispatchContext.Provider>
);
});
afterEach(() => {
wrapper.unmount();
});
test('Attempts to fetch full unified job template on view', async () => {
wrapper.find('g').simulate('mouseenter');
await act(async () => {
@ -348,6 +346,7 @@ describe('VisualizerNode', () => {
});
expect(JobTemplatesAPI.readDetail).toHaveBeenCalledWith(7);
});
test('Displays error fetching full unified job template', async () => {
JobTemplatesAPI.readDetail.mockRejectedValueOnce(
new Error({
@ -371,6 +370,7 @@ describe('VisualizerNode', () => {
wrapper.update();
expect(wrapper.find('AlertModal').length).toBe(1);
});
test('Attempts to fetch credentials on view', async () => {
JobTemplatesAPI.readDetail.mockResolvedValueOnce({
data: {

View File

@ -54,10 +54,6 @@ describe('VisualizerToolbar', () => {
);
});
afterAll(() => {
wrapper.unmount();
});
test('Shows correct number of nodes', () => {
// The start node (id=1) and deleted nodes (isDeleted=true) should be ignored
expect(wrapper.find('Badge').text()).toBe('1');

View File

@ -16,10 +16,6 @@ i18n.activate('en');
let wrapper;
afterEach(() => {
wrapper.unmount();
});
describe('UserListItem with full permissions', () => {
beforeEach(() => {
wrapper = mountWithContexts(
@ -39,9 +35,11 @@ describe('UserListItem with full permissions', () => {
</I18nProvider>
);
});
test('initially renders successfully', () => {
expect(wrapper.length).toBe(1);
});
test('edit button shown to users with edit capabilities', () => {
expect(wrapper.find('PencilAltIcon').exists()).toBeTruthy();
});

View File

@ -94,6 +94,7 @@ const roles = {
};
describe('<UserRolesList />', () => {
let wrapper;
beforeEach(() => {
UsersAPI.readOptions.mockResolvedValue({
data: {
@ -102,11 +103,11 @@ describe('<UserRolesList />', () => {
},
});
});
let wrapper;
afterEach(() => {
jest.clearAllMocks();
wrapper.unmount();
});
test('should render properly', async () => {
UsersAPI.readRoles.mockResolvedValue(roles);

View File

@ -118,7 +118,6 @@ describe('<UserTeamList />', () => {
afterEach(() => {
jest.clearAllMocks();
wrapper.unmount();
});
test('should load and render teams', async () => {

View File

@ -22,9 +22,9 @@ const onSuccessfulAdd = jest.fn();
describe('<UserTokenAdd />', () => {
afterEach(() => {
wrapper.unmount();
jest.clearAllMocks();
});
test('handleSubmit should post to api', async () => {
await act(async () => {
wrapper = mountWithContexts(

View File

@ -8,10 +8,6 @@ import UserTokens from './UserTokens';
describe('<UserTokens />', () => {
let wrapper;
afterEach(() => {
wrapper.unmount();
});
test('renders successfully', () => {
wrapper = mountWithContexts(<UserTokens />);
expect(wrapper.length).toBe(1);

View File

@ -1,38 +1,23 @@
import React from 'react';
import { createMemoryHistory } from 'history';
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
import { shallow } from 'enzyme';
import Users from './Users';
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useRouteMatch: () => ({
path: 'users',
}),
}));
describe('<Users />', () => {
test('initially renders successfully', () => {
const wrapper = mountWithContexts(<Users />);
wrapper.unmount();
});
test('should set breadcrumbs', () => {
const wrapper = shallow(<Users />);
test('should display a breadcrumb heading', () => {
const history = createMemoryHistory({
initialEntries: ['/users'],
const header = wrapper.find('ScreenHeader');
expect(header.prop('streamType')).toBe('user');
expect(header.prop('breadcrumbConfig')).toEqual({
'/users': 'Users',
'/users/add': 'Create New User',
});
const match = { path: '/users', url: '/users', isExact: true };
const wrapper = mountWithContexts(<Users />, {
context: {
router: {
history,
route: {
location: history.location,
match,
},
},
},
});
expect(wrapper.find('Title').length).toBe(1);
wrapper.unmount();
});
});

View File

@ -27,7 +27,6 @@ describe('<UserForm />', () => {
});
afterEach(() => {
wrapper.unmount();
jest.clearAllMocks();
});

View File

@ -28,9 +28,7 @@ const applications = {
};
describe('<UserTokenForm />', () => {
let wrapper;
beforeEach(() => {});
afterEach(() => {
wrapper.unmount();
jest.clearAllMocks();
});

View File

@ -29,7 +29,6 @@ describe('<WorkflowApprovalList />', () => {
});
afterEach(() => {
wrapper.unmount();
jest.clearAllMocks();
});

View File

@ -9,9 +9,6 @@ jest.mock('../../../api/models/WorkflowApprovals');
describe('<WorkflowApprovalListItem />', () => {
let wrapper;
afterEach(() => {
wrapper.unmount();
});
test('should display never expires status', () => {
wrapper = mountWithContexts(
@ -28,6 +25,7 @@ describe('<WorkflowApprovalListItem />', () => {
);
expect(wrapper.find('Label[children="Never expires"]').length).toBe(1);
});
test('should display timed out status', () => {
wrapper = mountWithContexts(
<table>
@ -47,6 +45,7 @@ describe('<WorkflowApprovalListItem />', () => {
);
expect(wrapper.find('Label[children="Timed out"]').length).toBe(1);
});
test('should display canceled status', () => {
wrapper = mountWithContexts(
<table>
@ -66,6 +65,7 @@ describe('<WorkflowApprovalListItem />', () => {
);
expect(wrapper.find('Label[children="Canceled"]').length).toBe(1);
});
test('should display approved status', () => {
wrapper = mountWithContexts(
<table>
@ -93,6 +93,7 @@ describe('<WorkflowApprovalListItem />', () => {
);
expect(wrapper.find('Label[children="Approved"]').length).toBe(1);
});
test('should display denied status', () => {
wrapper = mountWithContexts(
<table>

View File

@ -11,10 +11,6 @@ import mockWorkflowApprovals from './data.workflowApprovals.json';
jest.mock('../../api');
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
}));
describe('<WorkflowApprovals />', () => {
beforeEach(() => {
WorkflowApprovalsAPI.read.mockResolvedValue({
@ -70,6 +66,5 @@ describe('<WorkflowApprovals />', () => {
await waitForElement(wrapper, 'ContentLoading', el => el.length === 0);
expect(wrapper.find('Title').length).toBe(1);
wrapper.unmount();
});
});

View File

@ -8,15 +8,14 @@ const workflowApproval = mockWorkflowApprovals.results[0];
describe('<WorkflowApprovalStatus />', () => {
let wrapper;
afterEach(() => {
wrapper.unmount();
});
test('shows no expiration when approval status is pending and no approval_expiration', () => {
wrapper = mountWithContexts(
<WorkflowApprovalStatus workflowApproval={workflowApproval} />
);
expect(wrapper.text()).toBe('Never expires');
});
test('shows expiration date/time when approval status is pending and approval_expiration present', () => {
wrapper = mountWithContexts(
<WorkflowApprovalStatus
@ -30,6 +29,7 @@ describe('<WorkflowApprovalStatus />', () => {
`Expires on ${formatDateString('2020-10-10T17:13:12.067947Z')}`
);
});
test('shows when an approval has timed out', () => {
wrapper = mountWithContexts(
<WorkflowApprovalStatus
@ -42,6 +42,7 @@ describe('<WorkflowApprovalStatus />', () => {
);
expect(wrapper.find('Label').text()).toBe('Timed out');
});
test('shows when an approval has canceled', () => {
wrapper = mountWithContexts(
<WorkflowApprovalStatus
@ -54,6 +55,7 @@ describe('<WorkflowApprovalStatus />', () => {
);
expect(wrapper.find('Label').text()).toBe('Canceled');
});
test('shows when an approval has approved', () => {
wrapper = mountWithContexts(
<WorkflowApprovalStatus
@ -73,6 +75,7 @@ describe('<WorkflowApprovalStatus />', () => {
);
expect(wrapper.find('Label').text()).toBe('Approved');
});
test('shows when an approval has denied', () => {
wrapper = mountWithContexts(
<WorkflowApprovalStatus