diff --git a/awx/ui/src/screens/NotificationTemplate/NotificationTemplateList/NotificationTemplateListItem.test.js b/awx/ui/src/screens/NotificationTemplate/NotificationTemplateList/NotificationTemplateListItem.test.js
index eb50a1f684..59d417763f 100644
--- a/awx/ui/src/screens/NotificationTemplate/NotificationTemplateList/NotificationTemplateListItem.test.js
+++ b/awx/ui/src/screens/NotificationTemplate/NotificationTemplateList/NotificationTemplateListItem.test.js
@@ -30,6 +30,7 @@ describe('', () => {
@@ -53,6 +54,7 @@ describe('', () => {
@@ -73,6 +75,7 @@ describe('', () => {
@@ -94,6 +97,7 @@ describe('', () => {
@@ -121,6 +125,7 @@ describe('', () => {
},
},
}}
+ onAddToast={jest.fn()}
detailUrl="/notification_templates/3/detail"
/>
diff --git a/awx/ui/src/screens/Setting/shared/SharedFields.js b/awx/ui/src/screens/Setting/shared/SharedFields.js
index bb39074b88..5d1f37a03c 100644
--- a/awx/ui/src/screens/Setting/shared/SharedFields.js
+++ b/awx/ui/src/screens/Setting/shared/SharedFields.js
@@ -94,48 +94,6 @@ const BooleanField = ({
const [field, meta, helpers] = useField(name);
const [isModalOpen, setIsModalOpen] = useState(false);
- if (isModalOpen) {
- return (
- {
- setIsModalOpen(false);
- }}
- actions={[
- ,
- ,
- ]}
- >
- {t`Are you sure you want to disable local authentication? Doing so could impact users' ability to log in and the system administrator's ability to reverse this change.`}
-
- );
- }
-
return config ? (
+ {isModalOpen && (
+ {
+ setIsModalOpen(false);
+ }}
+ actions={[
+ ,
+ ,
+ ]}
+ >{t`Are you sure you want to disable local authentication? Doing so could impact users' ability to log in and the system administrator's ability to reverse this change.`}
+ )}
- needsConfirmationModal
- ? setIsModalOpen(true)
- : helpers.setValue(!field.value)
- }
+ onChange={(isOn) => {
+ if (needsConfirmationModal && isOn) {
+ setIsModalOpen(true);
+ }
+ helpers.setValue(!field.value);
+ }}
aria-label={ariaLabel || config.label}
/>
diff --git a/awx/ui/src/screens/Setting/shared/SharedFields.test.js b/awx/ui/src/screens/Setting/shared/SharedFields.test.js
index a081945e5b..b87a782009 100644
--- a/awx/ui/src/screens/Setting/shared/SharedFields.test.js
+++ b/awx/ui/src/screens/Setting/shared/SharedFields.test.js
@@ -321,11 +321,14 @@ describe('Setting form fields', () => {
expect(wrapper.find('Switch').prop('isChecked')).toBe(false);
expect(wrapper.find('Switch').prop('isDisabled')).toBe(false);
await act(async () => {
- wrapper.find('Switch').invoke('onChange')();
+ wrapper.find('Switch').invoke('onChange')(true);
});
wrapper.update();
expect(wrapper.find('AlertModal')).toHaveLength(1);
+ expect(
+ wrapper.find('BooleanField[name="DISABLE_LOCAL_AUTH"]')
+ ).toHaveLength(1);
await act(async () =>
wrapper
.find('Button[ouiaId="confirm-misc-settings-modal"]')
@@ -336,7 +339,45 @@ describe('Setting form fields', () => {
expect(wrapper.find('Switch').prop('isChecked')).toBe(true);
});
- test('shold not toggle disable local auth', async () => {
+ test('should not render confirmation modal when toggling off', async () => {
+ const wrapper = mountWithContexts(
+
+ {() => (
+
+ )}
+
+ );
+ 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.update();
+ expect(wrapper.find('AlertModal')).toHaveLength(0);
+ expect(wrapper.find('Switch').prop('isChecked')).toBe(false);
+ });
+
+ test('should not toggle disable local auth', async () => {
const wrapper = mountWithContexts(
{
expect(wrapper.find('Switch').prop('isChecked')).toBe(false);
expect(wrapper.find('Switch').prop('isDisabled')).toBe(false);
await act(async () => {
- wrapper.find('Switch').invoke('onChange')();
+ wrapper.find('Switch').invoke('onChange')(true);
});
wrapper.update();