update Template list tests

This commit is contained in:
Keith Grant
2021-01-19 15:14:12 -08:00
parent ad71dc3e98
commit 78ef11d558
2 changed files with 220 additions and 166 deletions

View File

@@ -171,13 +171,11 @@ function TemplateListItem({
<PencilAltIcon /> <PencilAltIcon />
</Button> </Button>
</ActionItem> </ActionItem>
<ActionItem <ActionItem visible={template.summary_fields.user_capabilities.copy}>
visible={template.summary_fields.user_capabilities.copy}
tooltip={i18n._(t`Copy Template`)}
>
<CopyButton <CopyButton
helperText={{ helperText={{
errorMessage: i18n._(t`Failed to copy template.`), errorMessage: i18n._(t`Failed to copy template.`),
tooltip: i18n._(t`Copy Template`),
}} }}
isDisabled={isDisabled} isDisabled={isDisabled}
onCopyStart={handleCopyStart} onCopyStart={handleCopyStart}
@@ -188,8 +186,8 @@ function TemplateListItem({
</ActionsTd> </ActionsTd>
</Tr> </Tr>
<Tr isExpanded={isExpanded}> <Tr isExpanded={isExpanded}>
<Td colspan={2} /> <Td colSpan={2} />
<Td colspan={4}> <Td colSpan={4}>
<ExpandableRowContent> <ExpandableRowContent>
<DetailList> <DetailList>
<Detail <Detail

View File

@@ -12,157 +12,189 @@ jest.mock('../../../api');
describe('<TemplateListItem />', () => { describe('<TemplateListItem />', () => {
test('launch button shown to users with start capabilities', () => { test('launch button shown to users with start capabilities', () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<TemplateListItem <table>
isSelected={false} <tbody>
template={{ <TemplateListItem
id: 1, isSelected={false}
name: 'Template 1', template={{
url: '/templates/job_template/1', id: 1,
type: 'job_template', name: 'Template 1',
summary_fields: { url: '/templates/job_template/1',
user_capabilities: { type: 'job_template',
start: true, summary_fields: {
}, user_capabilities: {
}, start: true,
}} },
/> },
}}
/>
</tbody>
</table>
); );
expect(wrapper.find('LaunchButton').exists()).toBeTruthy(); expect(wrapper.find('LaunchButton').exists()).toBeTruthy();
}); });
test('launch button hidden from users without start capabilities', () => { test('launch button hidden from users without start capabilities', () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<TemplateListItem <table>
isSelected={false} <tbody>
template={{ <TemplateListItem
id: 1, isSelected={false}
name: 'Template 1', template={{
url: '/templates/job_template/1', id: 1,
type: 'job_template', name: 'Template 1',
summary_fields: { url: '/templates/job_template/1',
user_capabilities: { type: 'job_template',
start: false, summary_fields: {
}, user_capabilities: {
}, start: false,
}} },
/> },
}}
/>
</tbody>
</table>
); );
expect(wrapper.find('LaunchButton').exists()).toBeFalsy(); expect(wrapper.find('LaunchButton').exists()).toBeFalsy();
}); });
test('edit button shown to users with edit capabilities', () => { test('edit button shown to users with edit capabilities', () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<TemplateListItem <table>
isSelected={false} <tbody>
template={{ <TemplateListItem
id: 1, isSelected={false}
name: 'Template 1', template={{
url: '/templates/job_template/1', id: 1,
type: 'job_template', name: 'Template 1',
summary_fields: { url: '/templates/job_template/1',
user_capabilities: { type: 'job_template',
edit: true, summary_fields: {
}, user_capabilities: {
}, edit: true,
}} },
/> },
}}
/>
</tbody>
</table>
); );
expect(wrapper.find('PencilAltIcon').exists()).toBeTruthy(); expect(wrapper.find('PencilAltIcon').exists()).toBeTruthy();
}); });
test('edit button hidden from users without edit capabilities', () => { test('edit button hidden from users without edit capabilities', () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<TemplateListItem <table>
isSelected={false} <tbody>
template={{ <TemplateListItem
id: 1, isSelected={false}
name: 'Template 1', template={{
url: '/templates/job_template/1', id: 1,
type: 'job_template', name: 'Template 1',
summary_fields: { url: '/templates/job_template/1',
user_capabilities: { type: 'job_template',
edit: false, summary_fields: {
}, user_capabilities: {
}, edit: false,
}} },
/> },
}}
/>
</tbody>
</table>
); );
expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy(); expect(wrapper.find('PencilAltIcon').exists()).toBeFalsy();
}); });
test('missing resource icon is shown.', () => { test('missing resource icon is shown.', () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<TemplateListItem <table>
isSelected={false} <tbody>
template={{ <TemplateListItem
id: 1, isSelected={false}
name: 'Template 1', template={{
url: '/templates/job_template/1', id: 1,
type: 'job_template', name: 'Template 1',
summary_fields: { url: '/templates/job_template/1',
user_capabilities: { type: 'job_template',
edit: false, summary_fields: {
}, user_capabilities: {
}, edit: false,
}} },
/> },
}}
/>
</tbody>
</table>
); );
expect(wrapper.find('ExclamationTriangleIcon').exists()).toBe(true); expect(wrapper.find('ExclamationTriangleIcon').exists()).toBe(true);
}); });
test('missing resource icon is not shown when there is a project and an inventory.', () => { test('missing resource icon is not shown when there is a project and an inventory.', () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<TemplateListItem <table>
isSelected={false} <tbody>
template={{ <TemplateListItem
id: 1, isSelected={false}
name: 'Template 1', template={{
url: '/templates/job_template/1', id: 1,
type: 'job_template', name: 'Template 1',
summary_fields: { url: '/templates/job_template/1',
user_capabilities: { type: 'job_template',
edit: false, summary_fields: {
}, user_capabilities: {
project: { name: 'Foo', id: 2 }, edit: false,
inventory: { name: 'Bar', id: 2 }, },
}, project: { name: 'Foo', id: 2 },
}} inventory: { name: 'Bar', id: 2 },
/> },
}}
/>
</tbody>
</table>
); );
expect(wrapper.find('ExclamationTriangleIcon').exists()).toBe(false); expect(wrapper.find('ExclamationTriangleIcon').exists()).toBe(false);
}); });
test('missing resource icon is not shown when inventory is prompt_on_launch, and a project', () => { test('missing resource icon is not shown when inventory is prompt_on_launch, and a project', () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<TemplateListItem <table>
isSelected={false} <tbody>
template={{ <TemplateListItem
id: 1, isSelected={false}
name: 'Template 1', template={{
url: '/templates/job_template/1', id: 1,
type: 'job_template', name: 'Template 1',
ask_inventory_on_launch: true, url: '/templates/job_template/1',
summary_fields: { type: 'job_template',
user_capabilities: { ask_inventory_on_launch: true,
edit: false, summary_fields: {
}, user_capabilities: {
project: { name: 'Foo', id: 2 }, edit: false,
}, },
}} project: { name: 'Foo', id: 2 },
/> },
}}
/>
</tbody>
</table>
); );
expect(wrapper.find('ExclamationTriangleIcon').exists()).toBe(false); expect(wrapper.find('ExclamationTriangleIcon').exists()).toBe(false);
}); });
test('missing resource icon is not shown type is workflow_job_template', () => { test('missing resource icon is not shown type is workflow_job_template', () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<TemplateListItem <table>
isSelected={false} <tbody>
template={{ <TemplateListItem
id: 1, isSelected={false}
name: 'Template 1', template={{
url: '/templates/job_template/1', id: 1,
type: 'workflow_job_template', name: 'Template 1',
summary_fields: { url: '/templates/job_template/1',
user_capabilities: { type: 'workflow_job_template',
edit: false, summary_fields: {
}, user_capabilities: {
}, edit: false,
}} },
/> },
}}
/>
</tbody>
</table>
); );
expect(wrapper.find('ExclamationTriangleIcon').exists()).toBe(false); expect(wrapper.find('ExclamationTriangleIcon').exists()).toBe(false);
}); });
@@ -171,19 +203,23 @@ describe('<TemplateListItem />', () => {
initialEntries: ['/templates'], initialEntries: ['/templates'],
}); });
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<TemplateListItem <table>
isSelected={false} <tbody>
detailUrl="/templates/job_template/1/details" <TemplateListItem
template={{ isSelected={false}
id: 1, detailUrl="/templates/job_template/1/details"
name: 'Template 1', template={{
summary_fields: { id: 1,
user_capabilities: { name: 'Template 1',
edit: false, summary_fields: {
}, user_capabilities: {
}, edit: false,
}} },
/>, },
}}
/>
</tbody>
</table>,
{ context: { router: { history } } } { context: { router: { history } } }
); );
wrapper.find('Link').simulate('click', { button: 0 }); wrapper.find('Link').simulate('click', { button: 0 });
@@ -195,11 +231,15 @@ describe('<TemplateListItem />', () => {
JobTemplatesAPI.copy.mockResolvedValue(); JobTemplatesAPI.copy.mockResolvedValue();
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<TemplateListItem <table>
isSelected={false} <tbody>
detailUrl="/templates/job_template/1/details" <TemplateListItem
template={mockJobTemplateData} isSelected={false}
/> detailUrl="/templates/job_template/1/details"
template={mockJobTemplateData}
/>
</tbody>
</table>
); );
await act(async () => await act(async () =>
wrapper.find('Button[aria-label="Copy"]').prop('onClick')() wrapper.find('Button[aria-label="Copy"]').prop('onClick')()
@@ -212,11 +252,15 @@ describe('<TemplateListItem />', () => {
JobTemplatesAPI.copy.mockRejectedValue(new Error()); JobTemplatesAPI.copy.mockRejectedValue(new Error());
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<TemplateListItem <table>
isSelected={false} <tbody>
detailUrl="/templates/job_template/1/details" <TemplateListItem
template={mockJobTemplateData} isSelected={false}
/> detailUrl="/templates/job_template/1/details"
template={mockJobTemplateData}
/>
</tbody>
</table>
); );
await act(async () => await act(async () =>
wrapper.find('Button[aria-label="Copy"]').prop('onClick')() wrapper.find('Button[aria-label="Copy"]').prop('onClick')()
@@ -228,39 +272,51 @@ describe('<TemplateListItem />', () => {
test('should not render copy button', async () => { test('should not render copy button', async () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<TemplateListItem <table>
isSelected={false} <tbody>
detailUrl="/templates/job_template/1/details" <TemplateListItem
template={{ isSelected={false}
...mockJobTemplateData, detailUrl="/templates/job_template/1/details"
summary_fields: { user_capabilities: { copy: false } }, template={{
}} ...mockJobTemplateData,
/> summary_fields: { user_capabilities: { copy: false } },
}}
/>
</tbody>
</table>
); );
expect(wrapper.find('CopyButton').length).toBe(0); expect(wrapper.find('CopyButton').length).toBe(0);
}); });
test('should render visualizer button for workflow', async () => { test('should render visualizer button for workflow', async () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<TemplateListItem <table>
isSelected={false} <tbody>
detailUrl="/templates/job_template/1/details" <TemplateListItem
template={{ isSelected={false}
...mockJobTemplateData, detailUrl="/templates/job_template/1/details"
type: 'workflow_job_template', template={{
}} ...mockJobTemplateData,
/> type: 'workflow_job_template',
}}
/>
</tbody>
</table>
); );
expect(wrapper.find('ProjectDiagramIcon').length).toBe(1); expect(wrapper.find('ProjectDiagramIcon').length).toBe(1);
}); });
test('should not render visualizer button for job template', async () => { test('should not render visualizer button for job template', async () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<TemplateListItem <table>
isSelected={false} <tbody>
detailUrl="/templates/job_template/1/details" <TemplateListItem
template={mockJobTemplateData} isSelected={false}
/> detailUrl="/templates/job_template/1/details"
template={mockJobTemplateData}
/>
</tbody>
</table>
); );
expect(wrapper.find('ProjectDiagramIcon').length).toBe(0); expect(wrapper.find('ProjectDiagramIcon').length).toBe(0);
}); });