From a6f79c646dd4066986a3e4e193d06593dfecd314 Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Thu, 18 Apr 2019 13:54:41 -0400 Subject: [PATCH] update organization add test to use mountWithContexts --- .../screens/OrganizationAdd.test.jsx | 116 ++++-------------- 1 file changed, 23 insertions(+), 93 deletions(-) diff --git a/__tests__/pages/Organizations/screens/OrganizationAdd.test.jsx b/__tests__/pages/Organizations/screens/OrganizationAdd.test.jsx index 5f7765966e..6a27b7ff1e 100644 --- a/__tests__/pages/Organizations/screens/OrganizationAdd.test.jsx +++ b/__tests__/pages/Organizations/screens/OrganizationAdd.test.jsx @@ -1,12 +1,8 @@ import React from 'react'; -import { mount } from 'enzyme'; -import { MemoryRouter } from 'react-router-dom'; -import { I18nProvider } from '@lingui/react'; -import { ConfigProvider } from '../../../../src/contexts/Config'; -import { NetworkProvider } from '../../../../src/contexts/Network'; +import { mountWithContexts } from '../../../enzymeHelpers'; -import { _OrganizationAdd } from '../../../../src/pages/Organizations/screens/OrganizationAdd'; +import OrganizationAdd from '../../../../src/pages/Organizations/screens/OrganizationAdd'; const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); @@ -29,25 +25,15 @@ describe('', () => { }); test('handleSubmit should post to api', () => { - const wrapper = mount( - - - - - <_OrganizationAdd api={api} /> - - - - - ); - + const wrapper = mountWithContexts(, { + context: { network: networkProviderValue } + }); const updatedOrgData = { name: 'new name', description: 'new description', custom_virtualenv: 'Buzz', }; wrapper.find('OrganizationForm').prop('handleSubmit')(updatedOrgData, [], []); - expect(api.createOrganization).toHaveBeenCalledWith(updatedOrgData); }); @@ -55,21 +41,11 @@ describe('', () => { const history = { push: jest.fn(), }; - const wrapper = mount( - - - - - <_OrganizationAdd api={api} history={history} /> - - - - - ); - + const wrapper = mountWithContexts(, { + context: { router: { history } } + }); expect(history.push).not.toHaveBeenCalled(); wrapper.find('button[aria-label="Cancel"]').prop('onClick')(); - expect(history.push).toHaveBeenCalledWith('/organizations'); }); @@ -77,21 +53,11 @@ describe('', () => { const history = { push: jest.fn(), }; - const wrapper = mount( - - - - - <_OrganizationAdd api={api} history={history} /> - - - - - ); - + const wrapper = mountWithContexts(, { + context: { router: { history } } + }); expect(history.push).not.toHaveBeenCalled(); wrapper.find('button[aria-label="Close"]').prop('onClick')(); - expect(history.push).toHaveBeenCalledWith('/organizations'); }); @@ -113,37 +79,18 @@ describe('', () => { ...orgData, } }); - const wrapper = mount( - - - - - <_OrganizationAdd api={api} history={history} /> - - - - - ); - + const wrapper = mountWithContexts(, { + context: { router: { history }, network: networkProviderValue } + }); wrapper.find('OrganizationForm').prop('handleSubmit')(orgData, [], []); await sleep(0); - expect(history.push).toHaveBeenCalledWith('/organizations/5'); }); test('handleSubmit should post instance groups', async () => { - const wrapper = mount( - - - - - <_OrganizationAdd api={api} /> - - - - - ); - + const wrapper = mountWithContexts(, { + context: { network: networkProviderValue } + }); const orgData = { name: 'new name', description: 'new description', @@ -160,7 +107,6 @@ describe('', () => { }); wrapper.find('OrganizationForm').prop('handleSubmit')(orgData, [3], []); await sleep(0); - expect(api.associateInstanceGroup) .toHaveBeenCalledWith('/api/v2/organizations/5/instance_groups', 3); }); @@ -169,17 +115,9 @@ describe('', () => { const config = { custom_virtualenvs: ['foo', 'bar'], }; - const wrapper = mount( - - - - - <_OrganizationAdd api={api} /> - - - - - ).find('OrganizationAdd').find('AnsibleSelect'); + const wrapper = mountWithContexts(, { + context: { network: networkProviderValue, config } + }).find('AnsibleSelect'); expect(wrapper.find('FormSelect')).toHaveLength(1); expect(wrapper.find('FormSelectOption')).toHaveLength(2); }); @@ -188,17 +126,9 @@ describe('', () => { const config = { custom_virtualenvs: [], }; - const wrapper = mount( - - - - - <_OrganizationAdd api={api} /> - - - - - ).find('OrganizationAdd').find('AnsibleSelect'); + const wrapper = mountWithContexts(, { + context: { network: networkProviderValue, config } + }).find('AnsibleSelect'); expect(wrapper.find('FormSelect')).toHaveLength(0); }); });