1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-30 22:21:13 +03:00

Expand job detail tests to verify more fields

* Update job detail tests to use large mock job data source
* Move mock job data source into a shared file
* Update OrgAccess snapshot due to DetailList style change
This commit is contained in:
Marliana Lara 2019-09-24 15:16:59 -04:00
parent 4b8a06801c
commit 76325eefd3
No known key found for this signature in database
GPG Key ID: 38C73B40DFA809EE
4 changed files with 54 additions and 44 deletions

View File

@ -4,64 +4,74 @@ import { mountWithContexts } from '@testUtils/enzymeHelpers';
import { sleep } from '@testUtils/testUtils';
import JobDetail from './JobDetail';
import { JobsAPI, ProjectUpdatesAPI } from '@api';
import mockJobData from '../shared/data.job.json';
jest.mock('@api');
describe('<JobDetail />', () => {
let job;
beforeEach(() => {
job = {
name: 'Foo',
summary_fields: {},
};
});
test('initially renders succesfully', () => {
mountWithContexts(<JobDetail job={job} />);
mountWithContexts(<JobDetail job={mockJobData} />);
});
test('should display a Close button', () => {
const wrapper = mountWithContexts(<JobDetail job={job} />);
const wrapper = mountWithContexts(<JobDetail job={mockJobData} />);
expect(wrapper.find('Button[aria-label="close"]').length).toBe(1);
wrapper.unmount();
});
test('should display details', () => {
job.status = 'Successful';
job.started = '2019-07-02T17:35:22.753817Z';
job.finished = '2019-07-02T17:35:34.910800Z';
const wrapper = mountWithContexts(<JobDetail job={mockJobData} />);
const wrapper = mountWithContexts(<JobDetail job={job} />);
const details = wrapper.find('Detail');
function assertDetail(detail, label, value) {
expect(detail.prop('label')).toEqual(label);
expect(detail.prop('value')).toEqual(value);
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(details.at(0), 'Status', 'Successful');
assertDetail(details.at(1), 'Started', job.started);
assertDetail(details.at(2), 'Finished', job.finished);
assertDetail('Status', 'Successful');
assertDetail('Started', mockJobData.started);
assertDetail('Finished', mockJobData.finished);
assertDetail('Template', mockJobData.summary_fields.job_template.name);
assertDetail('Job Type', 'Run');
assertDetail('Launched By', mockJobData.summary_fields.created_by.username);
assertDetail('Inventory', mockJobData.summary_fields.inventory.name);
assertDetail('Project', mockJobData.summary_fields.project.name);
assertDetail('Revision', mockJobData.scm_revision);
assertDetail('Playbook', mockJobData.playbook);
assertDetail('Verbosity', '0 (Normal)');
assertDetail('Environment', mockJobData.custom_virtualenv);
assertDetail('Execution Node', mockJobData.execution_node);
assertDetail(
'Instance Group',
mockJobData.summary_fields.instance_group.name
);
assertDetail('Job Slice', '0/1');
assertDetail('Credentials', 'SSH: Demo Credential');
});
test('should display credentials', () => {
job.summary_fields.credentials = [
{
id: 1,
name: 'Foo',
cloud: false,
kind: 'ssh',
},
];
const wrapper = mountWithContexts(<JobDetail job={job} />);
const wrapper = mountWithContexts(<JobDetail job={mockJobData} />);
const credentialChip = wrapper.find('CredentialChip');
expect(credentialChip.prop('credential')).toEqual(
job.summary_fields.credentials[0]
mockJobData.summary_fields.credentials[0]
);
});
test('should display successful job status icon', () => {
const wrapper = mountWithContexts(<JobDetail job={mockJobData} />);
const statusDetail = wrapper.find('Detail[label="Status"]');
expect(statusDetail.find('StatusIcon__SuccessfulTop')).toHaveLength(1);
expect(statusDetail.find('StatusIcon__SuccessfulBottom')).toHaveLength(1);
});
test('should display successful project status icon', () => {
const wrapper = mountWithContexts(<JobDetail job={mockJobData} />);
const statusDetail = wrapper.find('Detail[label="Project"]');
expect(statusDetail.find('StatusIcon__SuccessfulTop')).toHaveLength(1);
expect(statusDetail.find('StatusIcon__SuccessfulBottom')).toHaveLength(1);
});
test('should properly delete job', async () => {
job = {
name: 'Rage',

View File

@ -2,7 +2,7 @@ import React from 'react';
import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers';
import JobOutput from './JobOutput';
import { JobsAPI } from '@api';
import mockJobData from './data.job.json';
import mockJobData from '../shared/data.job.json';
import mockJobEventsData from './data.job_events.json';
jest.mock('@api');

View File

@ -321,9 +321,9 @@ exports[`<OrganizationAccessItem /> initially renders succesfully 1`] = `
"componentStyle": ComponentStyle {
"componentId": "DetailList-sc-12g7m4-0",
"isStatic": false,
"lastClassName": "gmERnX",
"lastClassName": "eYaZBv",
"rules": Array [
"display:grid;grid-gap:20px;align-items:baseline;",
"display:grid;grid-gap:20px;align-items:flex-start;",
[Function],
],
},
@ -341,15 +341,15 @@ exports[`<OrganizationAccessItem /> initially renders succesfully 1`] = `
stacked={true}
>
<DetailList
className="DetailList-sc-12g7m4-0 gmERnX"
className="DetailList-sc-12g7m4-0 eYaZBv"
stacked={true}
>
<TextList
className="DetailList-sc-12g7m4-0 gmERnX"
className="DetailList-sc-12g7m4-0 eYaZBv"
component="dl"
>
<dl
className="DetailList-sc-12g7m4-0 gmERnX"
className="DetailList-sc-12g7m4-0 eYaZBv"
data-pf-content={true}
>
<Detail
@ -484,9 +484,9 @@ exports[`<OrganizationAccessItem /> initially renders succesfully 1`] = `
"componentStyle": ComponentStyle {
"componentId": "DetailList-sc-12g7m4-0",
"isStatic": false,
"lastClassName": "gmERnX",
"lastClassName": "eYaZBv",
"rules": Array [
"display:grid;grid-gap:20px;align-items:baseline;",
"display:grid;grid-gap:20px;align-items:flex-start;",
[Function],
],
},
@ -504,15 +504,15 @@ exports[`<OrganizationAccessItem /> initially renders succesfully 1`] = `
stacked={true}
>
<DetailList
className="DetailList-sc-12g7m4-0 gmERnX"
className="DetailList-sc-12g7m4-0 eYaZBv"
stacked={true}
>
<TextList
className="DetailList-sc-12g7m4-0 gmERnX"
className="DetailList-sc-12g7m4-0 eYaZBv"
component="dl"
>
<dl
className="DetailList-sc-12g7m4-0 gmERnX"
className="DetailList-sc-12g7m4-0 eYaZBv"
data-pf-content={true}
>
<Detail