From 9dda5404a0cb797c989a28f35f310a01c3411877 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Fri, 21 Jun 2019 12:01:29 -0400 Subject: [PATCH 1/3] add 'has' prefix to error booleans --- src/App.jsx | 10 +++++----- src/screens/Job/JobList/JobList.jsx | 12 ++++++------ src/screens/Login/Login.jsx | 28 ++++++++++++++-------------- src/screens/Login/Login.test.jsx | 12 ++++++------ 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index afc27ff70a..1e1053d982 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -48,7 +48,7 @@ class App extends Component { version: null, isAboutModalOpen: false, isNavOpen, - configError: false, + hasConfigError: false, }; this.handleLogout = this.handleLogout.bind(this); @@ -81,7 +81,7 @@ class App extends Component { } handleConfigErrorClose () { - this.setState({ configError: false }); + this.setState({ hasConfigError: false }); } async loadConfig () { @@ -92,7 +92,7 @@ class App extends Component { this.setState({ ansible_version, custom_virtualenvs, version, me }); } catch (err) { - this.setState({ configError: true }); + this.setState({ hasConfigError: true }); } } @@ -104,7 +104,7 @@ class App extends Component { isNavOpen, me, version, - configError, + hasConfigError, } = this.state; const { i18n, @@ -170,7 +170,7 @@ class App extends Component { onClose={this.handleAboutClose} /> UnifiedJobsAPI.destroy(id))); } catch (err) { - this.setState({ deletionError: true }); + this.setState({ hasDeletionError: true }); } finally { await this.loadJobs(); } @@ -109,7 +109,7 @@ class JobList extends Component { const { hasContentError, hasContentLoading, - deletionError, + hasDeletionError, jobs, itemCount, selected, @@ -166,7 +166,7 @@ class JobList extends Component { /> ', () => { } = await findChildren(loginWrapper); expect(usernameInput.props().value).toBe(''); expect(passwordInput.props().value).toBe(''); - expect(awxLogin.state('validationError')).toBe(false); + expect(awxLogin.state('hasValidationError')).toBe(false); expect(submitButton.props().isDisabled).toBe(false); done(); }); @@ -126,14 +126,14 @@ describe('', () => { submitButton.simulate('click'); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'invalid'); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'invalid'); - await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('validationError') === true); + await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasValidationError') === true); await waitForElement(loginWrapper, formError, (el) => el.length === 1); usernameInput.props().onChange({ currentTarget: { value: 'dsarif' } }); passwordInput.props().onChange({ currentTarget: { value: 'freneticpny' } }); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'dsarif'); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'freneticpny'); - await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('validationError') === false); + await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasValidationError') === false); await waitForElement(loginWrapper, formError, (el) => el.length === 0); done(); @@ -151,16 +151,16 @@ describe('', () => { RootAPI.login.mockRejectedValueOnce({ response: { status: 500 } }); submitButton.simulate('click'); - await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('authenticationError') === true); + await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasAuthError') === true); usernameInput.props().onChange({ currentTarget: { value: 'sgrimes' } }); passwordInput.props().onChange({ currentTarget: { value: 'ovid' } }); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'sgrimes'); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'ovid'); - await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('authenticationError') === true); + await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasAuthError') === true); submitButton.simulate('click'); - await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('authenticationError') === false); + await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasAuthError') === false); done(); }); From 657a6f3a9317030722172c5b1057c8724f782ad7 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Fri, 21 Jun 2019 12:10:01 -0400 Subject: [PATCH 2/3] use top-level import aliases --- src/App.test.jsx | 4 ++-- src/screens/Application/Applications.test.jsx | 4 +++- src/screens/AuthSetting/AuthSettings.test.jsx | 4 +++- src/screens/Credential/Credentials.test.jsx | 4 +++- src/screens/CredentialType/CredentialTypes.test.jsx | 4 +++- src/screens/Dashboard/Dashboard.test.jsx | 4 +++- src/screens/InstanceGroup/InstanceGroups.test.jsx | 4 +++- src/screens/Inventory/Inventories.test.jsx | 4 +++- src/screens/InventoryScript/InventoryScripts.test.jsx | 4 +++- src/screens/JobsSetting/JobsSettings.test.jsx | 4 +++- src/screens/License/License.test.jsx | 4 +++- src/screens/Login/Login.test.jsx | 10 ++++++---- src/screens/ManagementJob/ManagementJobs.test.jsx | 4 +++- .../NotificationTemplate/NotifcationTemplates.test.jsx | 4 +++- src/screens/Portal/Portal.test.jsx | 4 +++- src/screens/Project/Projects.test.jsx | 4 +++- src/screens/Schedule/Schedules.test.jsx | 4 +++- src/screens/SystemSetting/SystemSettings.test.jsx | 4 +++- src/screens/Team/Teams.test.jsx | 4 +++- src/screens/UISetting/UISettings.test.jsx | 4 +++- src/screens/User/Users.test.jsx | 4 +++- 21 files changed, 65 insertions(+), 25 deletions(-) diff --git a/src/App.test.jsx b/src/App.test.jsx index 439650c9e2..5a69647dfa 100644 --- a/src/App.test.jsx +++ b/src/App.test.jsx @@ -1,10 +1,10 @@ import React from 'react'; -import { mountWithContexts, waitForElement } from '../testUtils/enzymeHelpers'; +import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers'; +import { ConfigAPI, MeAPI, RootAPI } from '@api'; import { asyncFlush } from '../jest.setup'; import App from './App'; -import { ConfigAPI, MeAPI, RootAPI } from './api'; jest.mock('./api'); diff --git a/src/screens/Application/Applications.test.jsx b/src/screens/Application/Applications.test.jsx index aae3890717..95a64706e3 100644 --- a/src/screens/Application/Applications.test.jsx +++ b/src/screens/Application/Applications.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import Applications from './Applications'; describe('', () => { diff --git a/src/screens/AuthSetting/AuthSettings.test.jsx b/src/screens/AuthSetting/AuthSettings.test.jsx index f19ac23575..93aa0a8aa6 100644 --- a/src/screens/AuthSetting/AuthSettings.test.jsx +++ b/src/screens/AuthSetting/AuthSettings.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import AuthSettings from './AuthSettings'; describe('', () => { diff --git a/src/screens/Credential/Credentials.test.jsx b/src/screens/Credential/Credentials.test.jsx index 73c4dfc588..5e65514281 100644 --- a/src/screens/Credential/Credentials.test.jsx +++ b/src/screens/Credential/Credentials.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import Credentials from './Credentials'; describe('', () => { diff --git a/src/screens/CredentialType/CredentialTypes.test.jsx b/src/screens/CredentialType/CredentialTypes.test.jsx index 9fc3eaeb19..9ef45e3709 100644 --- a/src/screens/CredentialType/CredentialTypes.test.jsx +++ b/src/screens/CredentialType/CredentialTypes.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import CredentialTypes from './CredentialTypes'; describe('', () => { diff --git a/src/screens/Dashboard/Dashboard.test.jsx b/src/screens/Dashboard/Dashboard.test.jsx index b11c727cf5..6a8562dabe 100644 --- a/src/screens/Dashboard/Dashboard.test.jsx +++ b/src/screens/Dashboard/Dashboard.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import Dashboard from './Dashboard'; describe('', () => { diff --git a/src/screens/InstanceGroup/InstanceGroups.test.jsx b/src/screens/InstanceGroup/InstanceGroups.test.jsx index a66a63aaa9..8e924033cb 100644 --- a/src/screens/InstanceGroup/InstanceGroups.test.jsx +++ b/src/screens/InstanceGroup/InstanceGroups.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import InstanceGroups from './InstanceGroups'; describe('', () => { diff --git a/src/screens/Inventory/Inventories.test.jsx b/src/screens/Inventory/Inventories.test.jsx index 1e41d3b70f..24ca2c1db8 100644 --- a/src/screens/Inventory/Inventories.test.jsx +++ b/src/screens/Inventory/Inventories.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import Inventories from './Inventories'; describe('', () => { diff --git a/src/screens/InventoryScript/InventoryScripts.test.jsx b/src/screens/InventoryScript/InventoryScripts.test.jsx index 33c05957e0..cfce2e3d45 100644 --- a/src/screens/InventoryScript/InventoryScripts.test.jsx +++ b/src/screens/InventoryScript/InventoryScripts.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import InventoryScripts from './InventoryScripts'; describe('', () => { diff --git a/src/screens/JobsSetting/JobsSettings.test.jsx b/src/screens/JobsSetting/JobsSettings.test.jsx index a7c86188fc..4960cb766e 100644 --- a/src/screens/JobsSetting/JobsSettings.test.jsx +++ b/src/screens/JobsSetting/JobsSettings.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import JobsSettings from './JobsSettings'; describe('', () => { diff --git a/src/screens/License/License.test.jsx b/src/screens/License/License.test.jsx index 176571d073..393d8dda6d 100644 --- a/src/screens/License/License.test.jsx +++ b/src/screens/License/License.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import License from './License'; describe('', () => { diff --git a/src/screens/Login/Login.test.jsx b/src/screens/Login/Login.test.jsx index c85f90f8e1..d7ecda90d7 100644 --- a/src/screens/Login/Login.test.jsx +++ b/src/screens/Login/Login.test.jsx @@ -1,9 +1,11 @@ import React from 'react'; -import { mountWithContexts, waitForElement } from '../../../testUtils/enzymeHelpers'; -import AWXLogin from './Login'; -import { RootAPI } from '../../api'; -jest.mock('../../api'); +import { RootAPI } from '@api'; +import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers'; + +import AWXLogin from './Login'; + +jest.mock('@api'); describe('', () => { async function findChildren (wrapper) { diff --git a/src/screens/ManagementJob/ManagementJobs.test.jsx b/src/screens/ManagementJob/ManagementJobs.test.jsx index 5e1962dda4..125fc10fac 100644 --- a/src/screens/ManagementJob/ManagementJobs.test.jsx +++ b/src/screens/ManagementJob/ManagementJobs.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import ManagementJobs from './ManagementJobs'; describe('', () => { diff --git a/src/screens/NotificationTemplate/NotifcationTemplates.test.jsx b/src/screens/NotificationTemplate/NotifcationTemplates.test.jsx index de4a4d494f..88ff84bc3f 100644 --- a/src/screens/NotificationTemplate/NotifcationTemplates.test.jsx +++ b/src/screens/NotificationTemplate/NotifcationTemplates.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import NotificationTemplates from './NotificationTemplates'; describe('', () => { diff --git a/src/screens/Portal/Portal.test.jsx b/src/screens/Portal/Portal.test.jsx index 0ad075812b..b0f16f2642 100644 --- a/src/screens/Portal/Portal.test.jsx +++ b/src/screens/Portal/Portal.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import Portal from './Portal'; describe('', () => { diff --git a/src/screens/Project/Projects.test.jsx b/src/screens/Project/Projects.test.jsx index 7f19cb4016..bfc3ed03ed 100644 --- a/src/screens/Project/Projects.test.jsx +++ b/src/screens/Project/Projects.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import Projects from './Projects'; describe('', () => { diff --git a/src/screens/Schedule/Schedules.test.jsx b/src/screens/Schedule/Schedules.test.jsx index aebcc8a192..11e11d8c40 100644 --- a/src/screens/Schedule/Schedules.test.jsx +++ b/src/screens/Schedule/Schedules.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import Schedules from './Schedules'; describe('', () => { diff --git a/src/screens/SystemSetting/SystemSettings.test.jsx b/src/screens/SystemSetting/SystemSettings.test.jsx index 52e559d0e5..acdff2e0f6 100644 --- a/src/screens/SystemSetting/SystemSettings.test.jsx +++ b/src/screens/SystemSetting/SystemSettings.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import SystemSettings from './SystemSettings'; describe('', () => { diff --git a/src/screens/Team/Teams.test.jsx b/src/screens/Team/Teams.test.jsx index c845ad599a..5edb1fece6 100644 --- a/src/screens/Team/Teams.test.jsx +++ b/src/screens/Team/Teams.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import Teams from './Teams'; describe('', () => { diff --git a/src/screens/UISetting/UISettings.test.jsx b/src/screens/UISetting/UISettings.test.jsx index 1d209bb1d4..b9459c50f0 100644 --- a/src/screens/UISetting/UISettings.test.jsx +++ b/src/screens/UISetting/UISettings.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import UISettings from './UISettings'; describe('', () => { diff --git a/src/screens/User/Users.test.jsx b/src/screens/User/Users.test.jsx index cf714b7774..aed28f73dd 100644 --- a/src/screens/User/Users.test.jsx +++ b/src/screens/User/Users.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; -import { mountWithContexts } from '../../../testUtils/enzymeHelpers'; + +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + import Users from './Users'; describe('', () => { From cc36b46925bcea779b32f80b07f922237a89c1dd Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Fri, 21 Jun 2019 12:15:59 -0400 Subject: [PATCH 3/3] remove network context mock --- .../OrganizationEdit.test.jsx | 37 ++----------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/src/screens/Organization/OrganizationEdit/OrganizationEdit.test.jsx b/src/screens/Organization/OrganizationEdit/OrganizationEdit.test.jsx index 2277cd601b..c635652c99 100644 --- a/src/screens/Organization/OrganizationEdit/OrganizationEdit.test.jsx +++ b/src/screens/Organization/OrganizationEdit/OrganizationEdit.test.jsx @@ -10,8 +10,6 @@ jest.mock('@api'); const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); describe('', () => { - let api; - const mockData = { name: 'Foo', description: 'Bar', @@ -22,23 +20,8 @@ describe('', () => { } }; - beforeEach(() => { - api = { - getInstanceGroups: jest.fn(), - updateOrganizationDetails: jest.fn(), - associateInstanceGroup: jest.fn(), - disassociate: jest.fn(), - }; - }); - test('handleSubmit should call api update', () => { - const wrapper = mountWithContexts( - , { context: { network: { - api, - } } } - ); + const wrapper = mountWithContexts(); const updatedOrgData = { name: 'new name', @@ -51,13 +34,7 @@ describe('', () => { }); test('handleSubmit associates and disassociates instance groups', async () => { - const wrapper = mountWithContexts( - , { context: { network: { - api, - } } } - ); + const wrapper = mountWithContexts(); const updatedOrgData = { name: 'new name', @@ -77,14 +54,8 @@ describe('', () => { push: jest.fn(), }; const wrapper = mountWithContexts( - , { context: { - network: { - api: { api }, - }, - router: { history } - } } + , + { context: { router: { history } } } ); expect(history.push).not.toHaveBeenCalled();