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,6 +12,8 @@ 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(
<table>
<tbody>
<TemplateListItem <TemplateListItem
isSelected={false} isSelected={false}
template={{ template={{
@@ -26,11 +28,15 @@ describe('<TemplateListItem />', () => {
}, },
}} }}
/> />
</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(
<table>
<tbody>
<TemplateListItem <TemplateListItem
isSelected={false} isSelected={false}
template={{ template={{
@@ -45,11 +51,15 @@ describe('<TemplateListItem />', () => {
}, },
}} }}
/> />
</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(
<table>
<tbody>
<TemplateListItem <TemplateListItem
isSelected={false} isSelected={false}
template={{ template={{
@@ -64,11 +74,15 @@ describe('<TemplateListItem />', () => {
}, },
}} }}
/> />
</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(
<table>
<tbody>
<TemplateListItem <TemplateListItem
isSelected={false} isSelected={false}
template={{ template={{
@@ -83,11 +97,15 @@ describe('<TemplateListItem />', () => {
}, },
}} }}
/> />
</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(
<table>
<tbody>
<TemplateListItem <TemplateListItem
isSelected={false} isSelected={false}
template={{ template={{
@@ -102,11 +120,15 @@ describe('<TemplateListItem />', () => {
}, },
}} }}
/> />
</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(
<table>
<tbody>
<TemplateListItem <TemplateListItem
isSelected={false} isSelected={false}
template={{ template={{
@@ -123,11 +145,15 @@ describe('<TemplateListItem />', () => {
}, },
}} }}
/> />
</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(
<table>
<tbody>
<TemplateListItem <TemplateListItem
isSelected={false} isSelected={false}
template={{ template={{
@@ -144,11 +170,15 @@ describe('<TemplateListItem />', () => {
}, },
}} }}
/> />
</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(
<table>
<tbody>
<TemplateListItem <TemplateListItem
isSelected={false} isSelected={false}
template={{ template={{
@@ -163,6 +193,8 @@ describe('<TemplateListItem />', () => {
}, },
}} }}
/> />
</tbody>
</table>
); );
expect(wrapper.find('ExclamationTriangleIcon').exists()).toBe(false); expect(wrapper.find('ExclamationTriangleIcon').exists()).toBe(false);
}); });
@@ -171,6 +203,8 @@ describe('<TemplateListItem />', () => {
initialEntries: ['/templates'], initialEntries: ['/templates'],
}); });
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<table>
<tbody>
<TemplateListItem <TemplateListItem
isSelected={false} isSelected={false}
detailUrl="/templates/job_template/1/details" detailUrl="/templates/job_template/1/details"
@@ -183,7 +217,9 @@ describe('<TemplateListItem />', () => {
}, },
}, },
}} }}
/>, />
</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(
<table>
<tbody>
<TemplateListItem <TemplateListItem
isSelected={false} isSelected={false}
detailUrl="/templates/job_template/1/details" detailUrl="/templates/job_template/1/details"
template={mockJobTemplateData} 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(
<table>
<tbody>
<TemplateListItem <TemplateListItem
isSelected={false} isSelected={false}
detailUrl="/templates/job_template/1/details" detailUrl="/templates/job_template/1/details"
template={mockJobTemplateData} 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,6 +272,8 @@ describe('<TemplateListItem />', () => {
test('should not render copy button', async () => { test('should not render copy button', async () => {
const wrapper = mountWithContexts( const wrapper = mountWithContexts(
<table>
<tbody>
<TemplateListItem <TemplateListItem
isSelected={false} isSelected={false}
detailUrl="/templates/job_template/1/details" detailUrl="/templates/job_template/1/details"
@@ -236,12 +282,16 @@ describe('<TemplateListItem />', () => {
summary_fields: { user_capabilities: { copy: false } }, 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(
<table>
<tbody>
<TemplateListItem <TemplateListItem
isSelected={false} isSelected={false}
detailUrl="/templates/job_template/1/details" detailUrl="/templates/job_template/1/details"
@@ -250,17 +300,23 @@ describe('<TemplateListItem />', () => {
type: 'workflow_job_template', 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(
<table>
<tbody>
<TemplateListItem <TemplateListItem
isSelected={false} isSelected={false}
detailUrl="/templates/job_template/1/details" detailUrl="/templates/job_template/1/details"
template={mockJobTemplateData} template={mockJobTemplateData}
/> />
</tbody>
</table>
); );
expect(wrapper.find('ProjectDiagramIcon').length).toBe(0); expect(wrapper.find('ProjectDiagramIcon').length).toBe(0);
}); });