Fixes search drop down items for job output search

This commit is contained in:
Alex Corey
2022-02-21 15:57:41 -05:00
parent 3d6a49ce7c
commit 79afdfd1a6
2 changed files with 62 additions and 6 deletions

View File

@@ -93,9 +93,12 @@ function JobOutputSearch({
key: 'stdout__icontains', key: 'stdout__icontains',
isDefault: true, isDefault: true,
}, },
{ ];
if (job.type !== 'system_job' && job.type !== 'inventory_update') {
columns.push({
name: t`Event`, name: t`Event`,
key: 'event', key: 'or__event',
options: [ options: [
['runner_on_failed', t`Host Failed`], ['runner_on_failed', t`Host Failed`],
['runner_on_start', t`Host Started`], ['runner_on_start', t`Host Started`],
@@ -129,9 +132,9 @@ function JobOutputSearch({
['system_warning', t`System Warning`], ['system_warning', t`System Warning`],
['error', t`Error`], ['error', t`Error`],
], ],
}, });
{ name: t`Advanced`, key: 'advanced' }, }
]; columns.push({ name: t`Advanced`, key: 'advanced' });
const isDisabled = isJobRunning(job.status); const isDisabled = isJobRunning(job.status);
return ( return (

View File

@@ -23,6 +23,7 @@ describe('JobOutputSearch', () => {
<JobOutputSearch <JobOutputSearch
job={{ job={{
status: 'successful', status: 'successful',
type: 'project',
}} }}
qsConfig={{ qsConfig={{
defaultParams: { page: 1 }, defaultParams: { page: 1 },
@@ -42,7 +43,59 @@ describe('JobOutputSearch', () => {
await act(async () => { await act(async () => {
wrapper.find(searchBtn).simulate('click'); wrapper.find(searchBtn).simulate('click');
}); });
expect(wrapper.find('Search').prop('columns')).toHaveLength(3);
expect(wrapper.find('Search').prop('columns').at(0).name).toBe('Stdout');
expect(wrapper.find('Search').prop('columns').at(1).name).toBe('Event');
expect(wrapper.find('Search').prop('columns').at(2).name).toBe('Advanced');
expect(history.location.search).toEqual('?stdout__icontains=99'); expect(history.location.search).toEqual('?stdout__icontains=99');
}); });
test('Should not have Event key in search drop down for system job', () => {
const history = createMemoryHistory({
initialEntries: ['/jobs/playbook/1/output'],
});
const wrapper = mountWithContexts(
<JobOutputSearch
job={{
status: 'successful',
type: 'system_job',
}}
qsConfig={{
defaultParams: { page: 1 },
integerFields: ['page', 'page_size'],
}}
/>,
{
context: { router: { history } },
}
);
expect(wrapper.find('Search').prop('columns')).toHaveLength(2);
expect(wrapper.find('Search').prop('columns').at(0).name).toBe('Stdout');
expect(wrapper.find('Search').prop('columns').at(1).name).toBe('Advanced');
});
test('Should not have Event key in search drop down for inventory update job', () => {
const history = createMemoryHistory({
initialEntries: ['/jobs/playbook/1/output'],
});
const wrapper = mountWithContexts(
<JobOutputSearch
job={{
status: 'successful',
type: 'inventory_update',
}}
qsConfig={{
defaultParams: { page: 1 },
integerFields: ['page', 'page_size'],
}}
/>,
{
context: { router: { history } },
}
);
expect(wrapper.find('Search').prop('columns')).toHaveLength(2);
expect(wrapper.find('Search').prop('columns').at(0).name).toBe('Stdout');
expect(wrapper.find('Search').prop('columns').at(1).name).toBe('Advanced');
});
}); });