Skip to content

Commit

Permalink
[Rollup] Fix rendering undefined from job status map (#41438) (#41893)
Browse files Browse the repository at this point in the history
* Updated JobStatus' status mapper to handle unknown strings
Added data to test case to ensure that the components using JobStatus can still render with unknown states

* Fixed unnecessary formatting changes and added translation for unknown label JP

* Added Chinese translation for unknown

* Added unknown status spec

* Remove manual addition of translation
  • Loading branch information
jloleysens authored Jul 24, 2019
1 parent 40c8f1b commit bfeaf0a
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
*/

// This is the Rollup job we will be creating in our tests
// Components using the JobStatus component should still be able to render
// despite having a rollup job with an unknown status
export const JOB_TO_CREATE = {
id: 'test-job',
indexPattern: 'test-pattern-*',
rollupIndex: 'rollup-index',
interval: '24h'
interval: '24h',
};

export const JOBS = {
Expand All @@ -24,16 +26,16 @@ export const JOBS = {
interval: '24h',
field: 'timestamp',
delay: '1d',
time_zone: 'UTC'
}
time_zone: 'UTC',
},
},
metrics: [],
timeout: '20s',
page_size: 1000
page_size: 1000,
},
status: {
job_state: 'stopped',
upgraded_doc_id: true
upgraded_doc_id: true,
},
stats: {
pages_processed: 0,
Expand All @@ -45,7 +47,42 @@ export const JOBS = {
index_failures: 0,
search_time_in_ms: 0,
search_total: 0,
search_failures: 0
}
}]
search_failures: 0,
},
},
{
config: {
id: 'my-rollup-job',
index_pattern: 'kibana_sample*',
rollup_index: 'rollup-index',
cron: '0 0 0 ? * 7',
groups: {
date_histogram: {
interval: '24h',
field: 'timestamp',
delay: '1d',
time_zone: 'UTC',
},
},
metrics: [],
timeout: '20s',
page_size: 1000,
},
status: {
job_state: 'not_a_known_state',
upgraded_doc_id: true,
},
stats: {
pages_processed: 0,
documents_processed: 0,
rollups_indexed: 0,
trigger_count: 0,
index_time_in_ms: 0,
index_total: 0,
index_failures: 0,
search_time_in_ms: 0,
search_total: 0,
search_failures: 0,
},
}],
};
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/rollup/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
export {
getJob,
getJobs,
jobCount
} from './job';
9 changes: 7 additions & 2 deletions x-pack/legacy/plugins/rollup/fixtures/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ const initialValues = {
triggerCount: 7,
};

export const getJob = (values = { id: getRandomString() }) => ({ ...initialValues, ...values });
const statuses = ['stopped', 'stopping', 'started', 'indexing', 'abort', 'abc' /* unknown status */];

export const getJobs = (total = 5) => new Array(total).fill().map(() => getJob());
export const getJob = (values = { id: getRandomString() }) => ({ ...initialValues, ...values });
export const jobCount = statuses.length;
export const getJobs = () =>
statuses.map(status =>
getJob({ status, id: getRandomString() })
);
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';

import {
EuiHealth,
} from '@elastic/eui';
import { EuiHealth } from '@elastic/eui';

const statusToHealthMap = {
stopped: (
Expand All @@ -20,6 +18,14 @@ const statusToHealthMap = {
/>
</EuiHealth>
),
stopping: (
<EuiHealth color="warning">
<FormattedMessage
id="xpack.rollupJobs.jobStatus.stoppingLabel"
defaultMessage="Stopping"
/>
</EuiHealth>
),
started: (
<EuiHealth color="success">
<FormattedMessage
Expand All @@ -46,4 +52,13 @@ const statusToHealthMap = {
),
};

export const JobStatus = ({ status }) => statusToHealthMap[status];
const statusUnknown = (
<EuiHealth color="subdued">
<FormattedMessage
id="xpack.rollupJobs.jobStatus.unknownLabel"
defaultMessage="Unknown"
/>
</EuiHealth>
);

export const JobStatus = ({ status }) => statusToHealthMap[status] || statusUnknown;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { Pager } from '@elastic/eui';

import { registerTestBed } from '../../../../../../../../test_utils';
import { getJobs } from '../../../../../fixtures';
import { getJobs, jobCount } from '../../../../../fixtures';
import { rollupJobsStore } from '../../../store';
import { JobTable } from './job_table';

Expand Down Expand Up @@ -37,7 +37,7 @@ const initTestBed = registerTestBed(JobTable, { defaultProps, store: rollupJobsS

describe('<JobTable />', () => {
describe('table rows', () => {
const totalJobs = 5;
const totalJobs = jobCount;
const jobs = getJobs(totalJobs);
const openDetailPanel = jest.fn();
const { find } = initTestBed({ jobs, openDetailPanel });
Expand Down Expand Up @@ -68,6 +68,8 @@ describe('<JobTable />', () => {
expect(tableColumns).toEqual(expectedColumns);
});

const getRowTextGetter = (row) => (field) => row.find(`[data-test-subj="jobTableCell-${field}"]`).hostNodes().text();

it('should set the correct job value in each row cell', () => {
const unformattedFields = [
'id',
Expand All @@ -78,7 +80,7 @@ describe('<JobTable />', () => {
];
const row = tableRows.first();
const job = jobs[0];
const getCellText = (field) => row.find(`[data-test-subj="jobTableCell-${field}"]`).hostNodes().text();
const getCellText = getRowTextGetter(row);

unformattedFields.forEach((field) => {
const cellText = getCellText(field);
Expand Down Expand Up @@ -112,6 +114,13 @@ describe('<JobTable />', () => {
expect(openDetailPanel.mock.calls.length).toBe(1);
expect(openDetailPanel.mock.calls[0][0]).toBe(job.id);
});

it('should still render despite unknown job statuses', () => {
const row = tableRows.last();
const getCellText = getRowTextGetter(row);
// In job fixtures, the last job has unknown status
expect('Unknown').toEqual(getCellText('status'));
});
});

describe('action menu', () => {
Expand Down

0 comments on commit bfeaf0a

Please sign in to comment.