mirror of
https://github.com/ansible/awx.git
synced 2026-01-19 21:51:26 -03:30
Merge pull request #12062 from nixocio/ui_issue_11770
Fix notification template details for system auditors
This commit is contained in:
commit
8a5fd11506
@ -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 }) {
|
||||
<PageSection>
|
||||
<Card>
|
||||
<ContentError error={error}>
|
||||
{error.response.status === 404 && (
|
||||
{error.response?.status === 404 && (
|
||||
<span>
|
||||
{t`Notification Template not found.`}{' '}
|
||||
<Link to="/notification_templates">
|
||||
|
||||
@ -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 (
|
||||
<CardBody>
|
||||
<DetailList gutter="sm">
|
||||
@ -384,13 +384,14 @@ function NotificationTemplateDetail({ template, defaultMessages }) {
|
||||
date={modified}
|
||||
user={summary_fields?.modified_by}
|
||||
/>
|
||||
{hasCustomMessages(messages, typeMessageDefaults) && (
|
||||
{typeMessageDefaults &&
|
||||
hasCustomMessages(messages, typeMessageDefaults) ? (
|
||||
<CustomMessageDetails
|
||||
messages={messages}
|
||||
defaults={typeMessageDefaults}
|
||||
type={template.notification_type}
|
||||
/>
|
||||
)}
|
||||
) : null}
|
||||
</DetailList>
|
||||
<CardActionsRow>
|
||||
{summary_fields.user_capabilities?.edit && (
|
||||
|
||||
@ -70,7 +70,11 @@ const mockTemplate = {
|
||||
describe('<NotificationTemplateDetail />', () => {
|
||||
let wrapper;
|
||||
|
||||
beforeEach(async () => {
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
test('should render Details', async () => {
|
||||
await act(async () => {
|
||||
wrapper = mountWithContexts(
|
||||
<NotificationTemplateDetail
|
||||
@ -80,13 +84,29 @@ describe('<NotificationTemplateDetail />', () => {
|
||||
);
|
||||
});
|
||||
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([<li>Use SSL</li>, <li>Use TLS</li>])
|
||||
).toEqual(true);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
test('should render Details', () => {
|
||||
test('should render Details when defaultMessages is missing', async () => {
|
||||
await act(async () => {
|
||||
wrapper = mountWithContexts(
|
||||
<NotificationTemplateDetail
|
||||
template={mockTemplate}
|
||||
defaultMessages={null}
|
||||
/>
|
||||
);
|
||||
});
|
||||
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user