diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/constants.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/constants.js index 965f383b2f09e..2a29b066004f0 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/constants.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/constants.js @@ -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 = { @@ -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, @@ -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, + }, + }], }; diff --git a/x-pack/legacy/plugins/rollup/fixtures/index.js b/x-pack/legacy/plugins/rollup/fixtures/index.js index 6d0d802b41306..fb574685f7117 100644 --- a/x-pack/legacy/plugins/rollup/fixtures/index.js +++ b/x-pack/legacy/plugins/rollup/fixtures/index.js @@ -7,4 +7,5 @@ export { getJob, getJobs, + jobCount } from './job'; diff --git a/x-pack/legacy/plugins/rollup/fixtures/job.js b/x-pack/legacy/plugins/rollup/fixtures/job.js index b155b05be12e0..0f3838c39db06 100644 --- a/x-pack/legacy/plugins/rollup/fixtures/job.js +++ b/x-pack/legacy/plugins/rollup/fixtures/job.js @@ -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() }) + ); diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_status/job_status.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_status/job_status.js index 2e830bd02e05c..6b63fc8418002 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_status/job_status.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_status/job_status.js @@ -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: ( @@ -20,6 +18,14 @@ const statusToHealthMap = { /> ), + stopping: ( + + + + ), started: ( statusToHealthMap[status]; +const statusUnknown = ( + + + +); + +export const JobStatus = ({ status }) => statusToHealthMap[status] || statusUnknown; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_table/job_table.test.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_table/job_table.test.js index ec0c258f91ffb..e5e332a196b84 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_table/job_table.test.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_table/job_table.test.js @@ -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'; @@ -37,7 +37,7 @@ const initTestBed = registerTestBed(JobTable, { defaultProps, store: rollupJobsS describe('', () => { describe('table rows', () => { - const totalJobs = 5; + const totalJobs = jobCount; const jobs = getJobs(totalJobs); const openDetailPanel = jest.fn(); const { find } = initTestBed({ jobs, openDetailPanel }); @@ -68,6 +68,8 @@ describe('', () => { 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', @@ -78,7 +80,7 @@ describe('', () => { ]; 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); @@ -112,6 +114,13 @@ describe('', () => { 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', () => {