From 13eb174c9f1134208fc94ab974a723b56b376eae Mon Sep 17 00:00:00 2001 From: nixocio Date: Thu, 14 Apr 2022 14:42:53 -0400 Subject: [PATCH] Fix notification template details for system auditors Fix notification template details for system auditors See: https://github.com/ansible/awx/issues/11770 --- .../NotificationTemplate.js | 4 +-- .../NotificationTemplateDetail.js | 7 ++-- .../NotificationTemplateDetail.test.js | 32 +++++++++++++++---- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/awx/ui/src/screens/NotificationTemplate/NotificationTemplate.js b/awx/ui/src/screens/NotificationTemplate/NotificationTemplate.js index e88a298c5f..1e2eab210c 100644 --- a/awx/ui/src/screens/NotificationTemplate/NotificationTemplate.js +++ b/awx/ui/src/screens/NotificationTemplate/NotificationTemplate.js @@ -38,7 +38,7 @@ function NotificationTemplate({ setBreadcrumb }) { setBreadcrumb(detail.data); return { template: detail.data, - defaultMessages: options.data.actions.POST.messages, + defaultMessages: options.data.actions?.POST?.messages, }; }, [templateId, setBreadcrumb]), { template: null, defaultMessages: null } @@ -53,7 +53,7 @@ function NotificationTemplate({ setBreadcrumb }) { - {error.response.status === 404 && ( + {error.response?.status === 404 && ( {t`Notification Template not found.`}{' '} diff --git a/awx/ui/src/screens/NotificationTemplate/NotificationTemplateDetail/NotificationTemplateDetail.js b/awx/ui/src/screens/NotificationTemplate/NotificationTemplateDetail/NotificationTemplateDetail.js index 489fa129d5..fda40d0feb 100644 --- a/awx/ui/src/screens/NotificationTemplate/NotificationTemplateDetail/NotificationTemplateDetail.js +++ b/awx/ui/src/screens/NotificationTemplate/NotificationTemplateDetail/NotificationTemplateDetail.js @@ -99,7 +99,7 @@ function NotificationTemplateDetail({ template, defaultMessages }) { ); const { error, dismissError } = useDismissableError(deleteError || testError); - const typeMessageDefaults = defaultMessages[template.notification_type]; + const typeMessageDefaults = defaultMessages?.[template?.notification_type]; return ( @@ -384,13 +384,14 @@ function NotificationTemplateDetail({ template, defaultMessages }) { date={modified} user={summary_fields?.modified_by} /> - {hasCustomMessages(messages, typeMessageDefaults) && ( + {typeMessageDefaults && + hasCustomMessages(messages, typeMessageDefaults) ? ( - )} + ) : null} {summary_fields.user_capabilities?.edit && ( diff --git a/awx/ui/src/screens/NotificationTemplate/NotificationTemplateDetail/NotificationTemplateDetail.test.js b/awx/ui/src/screens/NotificationTemplate/NotificationTemplateDetail/NotificationTemplateDetail.test.js index 829f272d45..e0013b4bb9 100644 --- a/awx/ui/src/screens/NotificationTemplate/NotificationTemplateDetail/NotificationTemplateDetail.test.js +++ b/awx/ui/src/screens/NotificationTemplate/NotificationTemplateDetail/NotificationTemplateDetail.test.js @@ -70,7 +70,11 @@ const mockTemplate = { describe('', () => { let wrapper; - beforeEach(async () => { + afterEach(() => { + jest.clearAllMocks(); + }); + + test('should render Details', async () => { await act(async () => { wrapper = mountWithContexts( ', () => { ); }); await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0); + function assertDetail(label, value) { + expect(wrapper.find(`Detail[label="${label}"] dt`).text()).toBe(label); + expect(wrapper.find(`Detail[label="${label}"] dd`).text()).toBe(value); + } + assertDetail('Name', mockTemplate.name); + assertDetail('Description', mockTemplate.description); + expect( + wrapper + .find('Detail[label="Email Options"]') + .containsAllMatchingElements([
  • Use SSL
  • ,
  • Use TLS
  • ]) + ).toEqual(true); }); - afterEach(() => { - jest.clearAllMocks(); - }); - - test('should render Details', () => { + test('should render Details when defaultMessages is missing', async () => { + await act(async () => { + wrapper = mountWithContexts( + + ); + }); + await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0); function assertDetail(label, value) { expect(wrapper.find(`Detail[label="${label}"] dt`).text()).toBe(label); expect(wrapper.find(`Detail[label="${label}"] dd`).text()).toBe(value);