diff --git a/__tests__/App.test.jsx b/__tests__/App.test.jsx
index 9712833be4..29f0f21fa0 100644
--- a/__tests__/App.test.jsx
+++ b/__tests__/App.test.jsx
@@ -1,50 +1,36 @@
import React from 'react';
-import { MemoryRouter } from 'react-router-dom';
-import { I18nProvider } from '@lingui/react';
-import { mount } from 'enzyme';
+import { mountWithContexts } from './enzymeHelpers';
+
import { asyncFlush } from '../jest.setup';
-import { ConfigProvider } from '../src/contexts/Config';
-import { NetworkProvider } from '../src/contexts/Network';
-
-import App, { _App } from '../src/App';
-
-const networkProviderValue = { api: {}, handleHttpError: () => {} };
+import App from '../src/App';
describe('', () => {
test('expected content is rendered', () => {
- const appWrapper = mount(
-
-
-
-
- (
- routeGroups.map(({ groupId }) => ())
- )}
- />
-
-
-
-
+ const appWrapper = mountWithContexts(
+ (
+ routeGroups.map(({ groupId }) => ())
+ )}
+ />
);
// page components
@@ -69,17 +55,7 @@ describe('', () => {
const config = { ansible_version, version };
- const wrapper = mount(
-
-
-
-
-
-
-
-
-
- );
+ const wrapper = mountWithContexts(, { context: { config } });
// open about modal
const aboutDropdown = 'Dropdown QuestionCircleIcon';
@@ -106,19 +82,8 @@ describe('', () => {
});
test('onNavToggle sets state.isNavOpen to opposite', () => {
- const appWrapper = mount(
-
-
-
-
-
-
-
-
-
- ).find('App');
+ const appWrapper = mountWithContexts().find('App');
const { onNavToggle } = appWrapper.instance();
-
[true, false, true, false, true].forEach(expected => {
expect(appWrapper.state().isNavOpen).toBe(expected);
onNavToggle();
@@ -128,17 +93,9 @@ describe('', () => {
test('onLogout makes expected call to api client', async (done) => {
const logout = jest.fn(() => Promise.resolve());
- const appWrapper = mount(
-
-
-
-
- <_App api={{ logout }} handleHttpError={() => {}} />
-
-
-
-
- ).find('App');
+ const appWrapper = mountWithContexts(, {
+ context: { network: { api: { logout }, handleHttpError: () => {} } }
+ }).find('App');
appWrapper.instance().onLogout();
await asyncFlush();
diff --git a/__tests__/enzymeHelpers.jsx b/__tests__/enzymeHelpers.jsx
index c4e31909a7..b49dcb17f7 100644
--- a/__tests__/enzymeHelpers.jsx
+++ b/__tests__/enzymeHelpers.jsx
@@ -45,6 +45,12 @@ const defaultContexts = {
push: () => {},
replace: () => {},
createHref: () => {},
+ location: {
+ hash: '',
+ pathname: '',
+ search: '',
+ state: '',
+ }
},
route: {
location: {
@@ -58,7 +64,7 @@ const defaultContexts = {
isExact: false,
path: '',
url: '',
- },
+ }
},
toJSON: () => '/router/',
},