From 6b7d712f9f1b2f8cfad7606960cc93095bff2308 Mon Sep 17 00:00:00 2001 From: Marliana Lara Date: Fri, 15 Jan 2021 11:54:35 -0500 Subject: [PATCH 1/2] Give setting toggle form group a unique form field id --- awx/ui_next/src/screens/Setting/shared/SharedFields.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/ui_next/src/screens/Setting/shared/SharedFields.jsx b/awx/ui_next/src/screens/Setting/shared/SharedFields.jsx index 13ec5dc11c..877aa2be35 100644 --- a/awx/ui_next/src/screens/Setting/shared/SharedFields.jsx +++ b/awx/ui_next/src/screens/Setting/shared/SharedFields.jsx @@ -48,10 +48,10 @@ const SettingGroup = withI18n()( Date: Thu, 21 Jan 2021 12:48:42 -0500 Subject: [PATCH 2/2] Assert checkbox label click event updates checkbox value --- .../Setting/shared/SharedFields.test.jsx | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/awx/ui_next/src/screens/Setting/shared/SharedFields.test.jsx b/awx/ui_next/src/screens/Setting/shared/SharedFields.test.jsx index e603ae10fe..d0c8a1437a 100644 --- a/awx/ui_next/src/screens/Setting/shared/SharedFields.test.jsx +++ b/awx/ui_next/src/screens/Setting/shared/SharedFields.test.jsx @@ -1,5 +1,7 @@ import React from 'react'; +import { mount } from 'enzyme'; import { Formik } from 'formik'; +import { I18nProvider } from '@lingui/react'; import { act } from 'react-dom/test-utils'; import { mountWithContexts } from '../../../../testUtils/enzymeHelpers'; import { @@ -12,28 +14,38 @@ import { describe('Setting form fields', () => { test('BooleanField renders the expected content', async () => { - const wrapper = mountWithContexts( - - {() => ( - - )} - + const outerNode = document.createElement('div'); + document.body.appendChild(outerNode); + const wrapper = mount( + + + {() => ( + + )} + + , + { + attachTo: outerNode, + } ); expect(wrapper.find('Switch')).toHaveLength(1); expect(wrapper.find('Switch').prop('isChecked')).toBe(true); expect(wrapper.find('Switch').prop('isDisabled')).toBe(false); await act(async () => { - wrapper.find('Switch').invoke('onChange')(false); + wrapper + .find('Switch label') + .instance() + .dispatchEvent(new Event('click')); }); wrapper.update(); expect(wrapper.find('Switch').prop('isChecked')).toBe(false);