Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setting toggle on click behavior #9093

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion awx/ui_next/src/screens/Setting/shared/SharedFields.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ const SettingGroup = withI18n()(
<FormGroup
fieldId={fieldId}
helperTextInvalid={helperTextInvalid}
id={`${fieldId}-field`}
isRequired={isRequired}
label={label}
validated={validated}
id={fieldId}
labelIcon={
<>
<Popover
Expand Down
46 changes: 29 additions & 17 deletions awx/ui_next/src/screens/Setting/shared/SharedFields.test.jsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -12,28 +14,38 @@ import {

describe('Setting form fields', () => {
test('BooleanField renders the expected content', async () => {
const wrapper = mountWithContexts(
<Formik
initialValues={{
boolean: true,
}}
>
{() => (
<BooleanField
name="boolean"
config={{
label: 'test',
help_text: 'test',
}}
/>
)}
</Formik>
const outerNode = document.createElement('div');
document.body.appendChild(outerNode);
const wrapper = mount(
<I18nProvider>
<Formik
initialValues={{
boolean: true,
}}
>
{() => (
<BooleanField
name="boolean"
config={{
label: 'test',
help_text: 'test',
}}
/>
)}
</Formik>
</I18nProvider>,
{
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);
Expand Down