mirror of
https://github.com/ansible/awx.git
synced 2026-05-10 19:07:36 -02:30
Merge pull request #12062 from nixocio/ui_issue_11770
Fix notification template details for system auditors
This commit is contained in:
@@ -38,7 +38,7 @@ function NotificationTemplate({ setBreadcrumb }) {
|
|||||||
setBreadcrumb(detail.data);
|
setBreadcrumb(detail.data);
|
||||||
return {
|
return {
|
||||||
template: detail.data,
|
template: detail.data,
|
||||||
defaultMessages: options.data.actions.POST.messages,
|
defaultMessages: options.data.actions?.POST?.messages,
|
||||||
};
|
};
|
||||||
}, [templateId, setBreadcrumb]),
|
}, [templateId, setBreadcrumb]),
|
||||||
{ template: null, defaultMessages: null }
|
{ template: null, defaultMessages: null }
|
||||||
@@ -53,7 +53,7 @@ function NotificationTemplate({ setBreadcrumb }) {
|
|||||||
<PageSection>
|
<PageSection>
|
||||||
<Card>
|
<Card>
|
||||||
<ContentError error={error}>
|
<ContentError error={error}>
|
||||||
{error.response.status === 404 && (
|
{error.response?.status === 404 && (
|
||||||
<span>
|
<span>
|
||||||
{t`Notification Template not found.`}{' '}
|
{t`Notification Template not found.`}{' '}
|
||||||
<Link to="/notification_templates">
|
<Link to="/notification_templates">
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ function NotificationTemplateDetail({ template, defaultMessages }) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const { error, dismissError } = useDismissableError(deleteError || testError);
|
const { error, dismissError } = useDismissableError(deleteError || testError);
|
||||||
const typeMessageDefaults = defaultMessages[template.notification_type];
|
const typeMessageDefaults = defaultMessages?.[template?.notification_type];
|
||||||
return (
|
return (
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<DetailList gutter="sm">
|
<DetailList gutter="sm">
|
||||||
@@ -384,13 +384,14 @@ function NotificationTemplateDetail({ template, defaultMessages }) {
|
|||||||
date={modified}
|
date={modified}
|
||||||
user={summary_fields?.modified_by}
|
user={summary_fields?.modified_by}
|
||||||
/>
|
/>
|
||||||
{hasCustomMessages(messages, typeMessageDefaults) && (
|
{typeMessageDefaults &&
|
||||||
|
hasCustomMessages(messages, typeMessageDefaults) ? (
|
||||||
<CustomMessageDetails
|
<CustomMessageDetails
|
||||||
messages={messages}
|
messages={messages}
|
||||||
defaults={typeMessageDefaults}
|
defaults={typeMessageDefaults}
|
||||||
type={template.notification_type}
|
type={template.notification_type}
|
||||||
/>
|
/>
|
||||||
)}
|
) : null}
|
||||||
</DetailList>
|
</DetailList>
|
||||||
<CardActionsRow>
|
<CardActionsRow>
|
||||||
{summary_fields.user_capabilities?.edit && (
|
{summary_fields.user_capabilities?.edit && (
|
||||||
|
|||||||
@@ -70,7 +70,11 @@ const mockTemplate = {
|
|||||||
describe('<NotificationTemplateDetail />', () => {
|
describe('<NotificationTemplateDetail />', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
beforeEach(async () => {
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should render Details', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<NotificationTemplateDetail
|
<NotificationTemplateDetail
|
||||||
@@ -80,13 +84,29 @@ describe('<NotificationTemplateDetail />', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
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(() => {
|
test('should render Details when defaultMessages is missing', async () => {
|
||||||
jest.clearAllMocks();
|
await act(async () => {
|
||||||
});
|
wrapper = mountWithContexts(
|
||||||
|
<NotificationTemplateDetail
|
||||||
test('should render Details', () => {
|
template={mockTemplate}
|
||||||
|
defaultMessages={null}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
await waitForElement(wrapper, 'ContentLoading', (el) => el.length === 0);
|
||||||
function assertDetail(label, value) {
|
function assertDetail(label, value) {
|
||||||
expect(wrapper.find(`Detail[label="${label}"] dt`).text()).toBe(label);
|
expect(wrapper.find(`Detail[label="${label}"] dt`).text()).toBe(label);
|
||||||
expect(wrapper.find(`Detail[label="${label}"] dd`).text()).toBe(value);
|
expect(wrapper.find(`Detail[label="${label}"] dd`).text()).toBe(value);
|
||||||
|
|||||||
Reference in New Issue
Block a user