mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02:30
Cleans up console error thrown from this test. Also fixed the last test as it wasn't actually testing the desired behavior.
This commit is contained in:
@@ -74,91 +74,119 @@ describe('<WorkflowJobTemplate/>', () => {
|
|||||||
data: { results: [{ id: 1, name: 'Org Foo' }] },
|
data: { results: [{ id: 1, name: 'Org Foo' }] },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
beforeEach(() => {
|
|
||||||
WorkflowJobTemplatesAPI.readWorkflowJobTemplateOptions.mockResolvedValue({
|
|
||||||
data: { actions: { PUT: {} } },
|
|
||||||
});
|
|
||||||
history = createMemoryHistory({
|
|
||||||
initialEntries: ['/templates/workflow_job_template/1/details'],
|
|
||||||
});
|
|
||||||
act(() => {
|
|
||||||
wrapper = mountWithContexts(
|
|
||||||
<Route
|
|
||||||
path="/templates/workflow_job_template/:id/details"
|
|
||||||
component={() => (
|
|
||||||
<WorkflowJobTemplate setBreadcrumb={() => {}} me={mockMe} />
|
|
||||||
)}
|
|
||||||
/>,
|
|
||||||
{
|
|
||||||
context: {
|
|
||||||
router: {
|
|
||||||
history,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
wrapper.unmount();
|
wrapper.unmount();
|
||||||
});
|
});
|
||||||
test('calls api to get workflow job template data', async () => {
|
describe('User can PUT', () => {
|
||||||
expect(wrapper.find('WorkflowJobTemplate').length).toBe(1);
|
beforeEach(async () => {
|
||||||
expect(WorkflowJobTemplatesAPI.readDetail).toBeCalledWith('1');
|
WorkflowJobTemplatesAPI.readWorkflowJobTemplateOptions.mockResolvedValue({
|
||||||
wrapper.update();
|
data: { actions: { PUT: {} } },
|
||||||
await sleep(0);
|
});
|
||||||
expect(WorkflowJobTemplatesAPI.readWebhookKey).toBeCalledWith('1');
|
history = createMemoryHistory({
|
||||||
expect(WorkflowJobTemplatesAPI.readWorkflowJobTemplateOptions).toBeCalled();
|
initialEntries: ['/templates/workflow_job_template/1/details'],
|
||||||
|
});
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<Route
|
||||||
|
path="/templates/workflow_job_template/:id/details"
|
||||||
|
component={() => (
|
||||||
|
<WorkflowJobTemplate setBreadcrumb={() => {}} me={mockMe} />
|
||||||
|
)}
|
||||||
|
/>,
|
||||||
|
{
|
||||||
|
context: {
|
||||||
|
router: {
|
||||||
|
history,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
test('calls api to get workflow job template data', async () => {
|
||||||
|
expect(wrapper.find('WorkflowJobTemplate').length).toBe(1);
|
||||||
|
expect(WorkflowJobTemplatesAPI.readDetail).toBeCalledWith('1');
|
||||||
|
wrapper.update();
|
||||||
|
await sleep(0);
|
||||||
|
expect(WorkflowJobTemplatesAPI.readWebhookKey).toBeCalledWith('1');
|
||||||
|
expect(
|
||||||
|
WorkflowJobTemplatesAPI.readWorkflowJobTemplateOptions
|
||||||
|
).toBeCalled();
|
||||||
|
|
||||||
expect(CredentialsAPI.readDetail).toBeCalledWith(1234567);
|
expect(CredentialsAPI.readDetail).toBeCalledWith(1234567);
|
||||||
expect(OrganizationsAPI.read).toBeCalledWith({
|
expect(OrganizationsAPI.read).toBeCalledWith({
|
||||||
page_size: 1,
|
page_size: 1,
|
||||||
role_level: 'notification_admin_role',
|
role_level: 'notification_admin_role',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('renders proper tabs', async () => {
|
||||||
|
const tabs = [
|
||||||
|
'Details',
|
||||||
|
'Access',
|
||||||
|
'Notifications',
|
||||||
|
'Schedules',
|
||||||
|
'Visualizer',
|
||||||
|
'Completed Jobs',
|
||||||
|
'Survey',
|
||||||
|
];
|
||||||
|
waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0);
|
||||||
|
wrapper.update();
|
||||||
|
wrapper.find('TabContainer').forEach(tc => {
|
||||||
|
tabs.forEach(t => expect(tc.prop(`aria-label=[${t}]`)));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Does not render Notifications tab', async () => {
|
||||||
|
OrganizationsAPI.read.mockResolvedValue({
|
||||||
|
data: { results: [] },
|
||||||
|
});
|
||||||
|
const tabs = [
|
||||||
|
'Details',
|
||||||
|
'Access',
|
||||||
|
'Schedules',
|
||||||
|
'Visualizer',
|
||||||
|
'Completed Jobs',
|
||||||
|
'Survey',
|
||||||
|
];
|
||||||
|
waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0);
|
||||||
|
wrapper.update();
|
||||||
|
wrapper.find('TabContainer').forEach(tc => {
|
||||||
|
tabs.forEach(t => expect(tc.prop(`aria-label=[${t}]`)));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('User cannot PUT', () => {
|
||||||
test('renders proper tabs', async () => {
|
beforeEach(async () => {
|
||||||
const tabs = [
|
WorkflowJobTemplatesAPI.readWorkflowJobTemplateOptions.mockResolvedValueOnce(
|
||||||
'Details',
|
{
|
||||||
'Access',
|
data: { actions: {} },
|
||||||
'Notifications',
|
}
|
||||||
'Schedules',
|
);
|
||||||
'Visualizer',
|
history = createMemoryHistory({
|
||||||
'Completed Jobs',
|
initialEntries: ['/templates/workflow_job_template/1/details'],
|
||||||
'Survey',
|
});
|
||||||
];
|
await act(async () => {
|
||||||
waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0);
|
wrapper = mountWithContexts(
|
||||||
wrapper.update();
|
<Route
|
||||||
wrapper.find('TabContainer').forEach(tc => {
|
path="/templates/workflow_job_template/:id/details"
|
||||||
tabs.forEach(t => expect(tc.prop(`aria-label=[${t}]`)));
|
component={() => (
|
||||||
|
<WorkflowJobTemplate setBreadcrumb={() => {}} me={mockMe} />
|
||||||
|
)}
|
||||||
|
/>,
|
||||||
|
{
|
||||||
|
context: {
|
||||||
|
router: {
|
||||||
|
history,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
test('should not call for webhook key', async () => {
|
||||||
|
expect(WorkflowJobTemplatesAPI.readWebhookKey).not.toBeCalled();
|
||||||
test('Does not render Notifications tab', async () => {
|
|
||||||
OrganizationsAPI.read.mockResolvedValue({
|
|
||||||
data: { results: [] },
|
|
||||||
});
|
});
|
||||||
const tabs = [
|
|
||||||
'Details',
|
|
||||||
'Access',
|
|
||||||
'Schedules',
|
|
||||||
'Visualizer',
|
|
||||||
'Completed Jobs',
|
|
||||||
'Survey',
|
|
||||||
];
|
|
||||||
waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0);
|
|
||||||
wrapper.update();
|
|
||||||
wrapper.find('TabContainer').forEach(tc => {
|
|
||||||
tabs.forEach(t => expect(tc.prop(`aria-label=[${t}]`)));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
test('should not call for webhook key', async () => {
|
|
||||||
WorkflowJobTemplatesAPI.readWorkflowJobTemplateOptions.mockResolvedValueOnce(
|
|
||||||
{
|
|
||||||
data: { actions: {} },
|
|
||||||
}
|
|
||||||
);
|
|
||||||
expect(WorkflowJobTemplatesAPI.readWebhookKey).not.toBeCalled();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user