Move testbed utils to x-pack/test_utils (#32893)

This commit is contained in:
Sébastien Loix 2019-03-19 08:12:19 +01:00 committed by GitHub
parent 47272c464f
commit effebd8c05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 245 additions and 261 deletions

View file

@ -155,6 +155,7 @@ module.exports = {
'x-pack/{dev-tools,tasks,scripts,test,build_chromium}/**/*',
'x-pack/**/{__tests__,__test__,__jest__,__fixtures__,__mocks__}/**/*',
'x-pack/**/*.test.js',
'x-pack/test_utils/**/*',
'x-pack/gulpfile.js',
'x-pack/plugins/apm/public/utils/testHelpers.js',
],

View file

@ -6,7 +6,7 @@
import axios from 'axios';
import { registerTestBed } from '../utils';
import { registerTestBed } from '../../../../test_utils';
import { rollupJobsStore } from '../../public/crud_app/store';
import {
setHttp,
@ -25,21 +25,21 @@ const JOB_TO_CREATE = {
interval: '24h'
};
const initUserActions = (component, findTestSubject) => {
const initUserActions = (component, find) => {
const clickNextStep = () => {
const button = findTestSubject('rollupJobNextButton');
const button = find('rollupJobNextButton');
button.simulate('click');
component.update();
};
const clickPreviousStep = () => {
const button = findTestSubject('rollupJobBackButton');
const button = find('rollupJobBackButton');
button.simulate('click');
component.update();
};
const clickSave = () => {
const button = findTestSubject('rollupJobSaveButton');
const button = find('rollupJobSaveButton');
button.simulate('click');
component.update();
};
@ -84,7 +84,7 @@ const initGoToStep = (fillFormFields, clickNextStep) => async (targetStep) => {
export const initTestBed = () => {
const testBed = registerTestBed(JobCreate, {}, rollupJobsStore)();
const userActions = initUserActions(testBed.component, testBed.findTestSubject);
const userActions = initUserActions(testBed.component, testBed.find);
const fillFormFields = initFillFormFields(testBed.form);
const goToStep = initGoToStep(fillFormFields, userActions.clickNextStep);
const getEuiStepsHorizontalActive = () => testBed.component.find('.euiStepHorizontal-isSelected').text();

View file

@ -22,8 +22,8 @@ jest.mock('lodash/function/debounce', () => fn => fn);
describe('Create Rollup Job, step 2: Date histogram', () => {
let server;
let findTestSubject;
let testSubjectExists;
let find;
let exists;
let userActions;
let getFormErrorsMessages;
let form;
@ -36,8 +36,8 @@ describe('Create Rollup Job, step 2: Date histogram', () => {
server.respondImmediately = true;
({ mockIndexPatternValidityResponse } = mockServerResponses(server));
({
findTestSubject,
testSubjectExists,
find,
exists,
userActions,
getFormErrorsMessages,
form,
@ -60,17 +60,17 @@ describe('Create Rollup Job, step 2: Date histogram', () => {
});
it('should have the title set to "Date histogram"', () => {
expect(testSubjectExists('rollupJobCreateDateHistogramTitle')).toBe(true);
expect(exists('rollupJobCreateDateHistogramTitle')).toBe(true);
});
it('should have a link to the documentation', () => {
expect(testSubjectExists('rollupJobCreateDateHistogramDocsButton')).toBe(true);
expect(exists('rollupJobCreateDateHistogramDocsButton')).toBe(true);
});
it('should have the "next" and "back" button visible', () => {
expect(testSubjectExists('rollupJobBackButton')).toBe(true);
expect(testSubjectExists('rollupJobNextButton')).toBe(true);
expect(testSubjectExists('rollupJobSaveButton')).toBe(false);
expect(exists('rollupJobBackButton')).toBe(true);
expect(exists('rollupJobNextButton')).toBe(true);
expect(exists('rollupJobSaveButton')).toBe(false);
});
it('should go to the "Logistics" step when clicking the back button', async () => {
@ -86,7 +86,7 @@ describe('Create Rollup Job, step 2: Date histogram', () => {
await goToStep(2);
const dateFieldSelectOptionsValues = findTestSubject('rollupJobCreateDateFieldSelect').find('option').map(option => option.text());
const dateFieldSelectOptionsValues = find('rollupJobCreateDateFieldSelect').find('option').map(option => option.text());
expect(dateFieldSelectOptionsValues).toEqual(dateFields);
});
});
@ -95,7 +95,7 @@ describe('Create Rollup Job, step 2: Date histogram', () => {
it('should have a select with all the timezones', async () => {
await goToStep(2);
const timeZoneSelect = findTestSubject('rollupJobCreateTimeZoneSelect');
const timeZoneSelect = find('rollupJobCreateTimeZoneSelect');
const options = timeZoneSelect.find('option').map(option => option.text());
expect(options).toEqual(moment.tz.names());
});
@ -107,18 +107,18 @@ describe('Create Rollup Job, step 2: Date histogram', () => {
});
it('should display errors when clicking "next" without filling the form', () => {
expect(testSubjectExists('rollupJobCreateStepError')).toBeFalsy();
expect(exists('rollupJobCreateStepError')).toBeFalsy();
userActions.clickNextStep();
expect(testSubjectExists('rollupJobCreateStepError')).toBeTruthy();
expect(exists('rollupJobCreateStepError')).toBeTruthy();
expect(getFormErrorsMessages()).toEqual(['Interval is required.']);
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(true);
expect(find('rollupJobNextButton').props().disabled).toBe(true);
});
describe('interval', () => {
afterEach(() => {
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(true);
expect(find('rollupJobNextButton').props().disabled).toBe(true);
});
it('should validate the interval format', () => {

View file

@ -21,8 +21,8 @@ jest.mock('lodash/function/debounce', () => fn => fn);
describe('Create Rollup Job, step 4: Histogram', () => {
let server;
let findTestSubject;
let testSubjectExists;
let find;
let exists;
let userActions;
let mockIndexPatternValidityResponse;
let getEuiStepsHorizontalActive;
@ -36,8 +36,8 @@ describe('Create Rollup Job, step 4: Histogram', () => {
server.respondImmediately = true;
({ mockIndexPatternValidityResponse } = mockServerResponses(server));
({
findTestSubject,
testSubjectExists,
find,
exists,
userActions,
getEuiStepsHorizontalActive,
goToStep,
@ -55,7 +55,7 @@ describe('Create Rollup Job, step 4: Histogram', () => {
const goToStepAndOpenFieldChooser = async () => {
await goToStep(4);
findTestSubject('rollupJobShowFieldChooserButton').simulate('click');
find('rollupJobShowFieldChooserButton').simulate('click');
};
describe('layout', () => {
@ -68,17 +68,17 @@ describe('Create Rollup Job, step 4: Histogram', () => {
});
it('should have the title set to "Terms"', () => {
expect(testSubjectExists('rollupJobCreateHistogramTitle')).toBe(true);
expect(exists('rollupJobCreateHistogramTitle')).toBe(true);
});
it('should have a link to the documentation', () => {
expect(testSubjectExists('rollupJobCreateHistogramDocsButton')).toBe(true);
expect(exists('rollupJobCreateHistogramDocsButton')).toBe(true);
});
it('should have the "next" and "back" button visible', () => {
expect(testSubjectExists('rollupJobBackButton')).toBe(true);
expect(testSubjectExists('rollupJobNextButton')).toBe(true);
expect(testSubjectExists('rollupJobSaveButton')).toBe(false);
expect(exists('rollupJobBackButton')).toBe(true);
expect(exists('rollupJobNextButton')).toBe(true);
expect(exists('rollupJobSaveButton')).toBe(false);
});
it('should go to the "Terms" step when clicking the back button', async () => {
@ -92,11 +92,11 @@ describe('Create Rollup Job, step 4: Histogram', () => {
});
it('should have a button to display the list of histogram fields to chose from', () => {
expect(testSubjectExists('rollupJobHistogramFieldChooser')).toBe(false);
expect(exists('rollupJobHistogramFieldChooser')).toBe(false);
findTestSubject('rollupJobShowFieldChooserButton').simulate('click');
find('rollupJobShowFieldChooserButton').simulate('click');
expect(testSubjectExists('rollupJobHistogramFieldChooser')).toBe(true);
expect(exists('rollupJobHistogramFieldChooser')).toBe(true);
});
});
@ -107,15 +107,15 @@ describe('Create Rollup Job, step 4: Histogram', () => {
});
it('should have the title set to "Add histogram fields"', async () => {
expect(findTestSubject('rollupJobCreateFlyoutTitle').text()).toEqual('Add histogram fields');
expect(find('rollupJobCreateFlyoutTitle').text()).toEqual('Add histogram fields');
});
it('should have a button to close the flyout', () => {
expect(testSubjectExists('rollupJobHistogramFieldChooser')).toBe(true);
expect(exists('rollupJobHistogramFieldChooser')).toBe(true);
findTestSubject('euiFlyoutCloseButton').simulate('click');
find('euiFlyoutCloseButton').simulate('click');
expect(testSubjectExists('rollupJobHistogramFieldChooser')).toBe(false);
expect(exists('rollupJobHistogramFieldChooser')).toBe(false);
});
});
@ -190,7 +190,7 @@ describe('Create Rollup Job, step 4: Histogram', () => {
describe('interval', () => {
const addHistogramFieldToList = () => {
findTestSubject('rollupJobShowFieldChooserButton').simulate('click');
find('rollupJobShowFieldChooserButton').simulate('click');
const { rows } = getMetadataFromEuiTable('rollupJobHistogramFieldChooser-table');
rows[0].reactWrapper.simulate('click');
};
@ -203,15 +203,15 @@ describe('Create Rollup Job, step 4: Histogram', () => {
describe('input validation', () => {
afterEach(() => {
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(true);
expect(find('rollupJobNextButton').props().disabled).toBe(true);
});
it('should display errors when clicking "next" without filling the interval', () => {
expect(testSubjectExists('rollupJobCreateStepError')).toBeFalsy();
expect(exists('rollupJobCreateStepError')).toBeFalsy();
userActions.clickNextStep();
expect(testSubjectExists('rollupJobCreateStepError')).toBeTruthy();
expect(exists('rollupJobCreateStepError')).toBeTruthy();
expect(getFormErrorsMessages()).toEqual(['Interval must be a whole number.']);
});

View file

@ -23,8 +23,8 @@ jest.mock('lodash/function/debounce', () => fn => fn);
describe('Create Rollup Job, step 1: Logistics', () => {
let server;
let findTestSubject;
let testSubjectExists;
let find;
let exists;
let userActions;
let getFormErrorsMessages;
let form;
@ -36,8 +36,8 @@ describe('Create Rollup Job, step 1: Logistics', () => {
server.respondImmediately = true;
({ mockIndexPatternValidityResponse } = mockServerResponses(server));
({
findTestSubject,
testSubjectExists,
find,
exists,
userActions,
getFormErrorsMessages,
form,
@ -54,41 +54,41 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should have the title set to "Logistics"', () => {
expect(testSubjectExists('rollupJobCreateLogisticsTitle')).toBe(true);
expect(exists('rollupJobCreateLogisticsTitle')).toBe(true);
});
it('should have a link to the documentation', () => {
expect(testSubjectExists('rollupJobCreateLogisticsDocsButton')).toBe(true);
expect(exists('rollupJobCreateLogisticsDocsButton')).toBe(true);
});
it('should only have the "next" button visible', () => {
expect(testSubjectExists('rollupJobBackButton')).toBe(false);
expect(testSubjectExists('rollupJobNextButton')).toBe(true);
expect(testSubjectExists('rollupJobSaveButton')).toBe(false);
expect(exists('rollupJobBackButton')).toBe(false);
expect(exists('rollupJobNextButton')).toBe(true);
expect(exists('rollupJobSaveButton')).toBe(false);
});
it('should display errors when clicking "next" without filling the form', () => {
expect(testSubjectExists('rollupJobCreateStepError')).toBeFalsy();
expect(exists('rollupJobCreateStepError')).toBeFalsy();
userActions.clickNextStep();
expect(testSubjectExists('rollupJobCreateStepError')).toBeTruthy();
expect(exists('rollupJobCreateStepError')).toBeTruthy();
expect(getFormErrorsMessages()).toEqual([
'Name is required.',
'Index pattern is required.',
'Rollup index is required.',
]);
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(true);
expect(find('rollupJobNextButton').props().disabled).toBe(true);
});
describe('form validations', () => {
describe('index pattern', () => {
beforeEach(() => {
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(false);
expect(find('rollupJobNextButton').props().disabled).toBe(false);
});
afterEach(() => {
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(true);
expect(find('rollupJobNextButton').props().disabled).toBe(true);
});
it('should not allow spaces', async () => {
@ -132,11 +132,11 @@ describe('Create Rollup Job, step 1: Logistics', () => {
describe('rollup index name', () => {
beforeEach(() => {
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(false);
expect(find('rollupJobNextButton').props().disabled).toBe(false);
});
afterEach(() => {
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(true);
expect(find('rollupJobNextButton').props().disabled).toBe(true);
});
it('should not allow spaces', () => {
@ -166,7 +166,7 @@ describe('Create Rollup Job, step 1: Logistics', () => {
describe('rollup cron', () => {
const changeFrequency = (value) => {
findTestSubject('rollupJobCreateFrequencySelect').simulate('change', { target: { value } });
find('rollupJobCreateFrequencySelect').simulate('change', { target: { value } });
};
const generateStringSequenceOfNumbers = (total) => (
@ -175,7 +175,7 @@ describe('Create Rollup Job, step 1: Logistics', () => {
describe('frequency', () => {
it('should allow "minute", "hour", "day", "week", "month", "year"', () => {
const frequencySelect = findTestSubject('rollupJobCreateFrequencySelect');
const frequencySelect = find('rollupJobCreateFrequencySelect');
const options = frequencySelect.find('option').map(option => option.text());
expect(options).toEqual(['minute', 'hour', 'day', 'week', 'month', 'year']);
});
@ -183,7 +183,7 @@ describe('Create Rollup Job, step 1: Logistics', () => {
describe('every minute', () => {
it('should not have any additional configuration', () => {
changeFrequency(MINUTE);
expect(findTestSubject('rollupCronFrequencyConfiguration').length).toBe(0);
expect(find('rollupCronFrequencyConfiguration').length).toBe(0);
});
});
@ -193,12 +193,12 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should have 1 additional configuration', () => {
expect(findTestSubject('rollupCronFrequencyConfiguration').length).toBe(1);
expect(testSubjectExists('rollupJobCreateFrequencyHourlyMinuteSelect')).toBe(true);
expect(find('rollupCronFrequencyConfiguration').length).toBe(1);
expect(exists('rollupJobCreateFrequencyHourlyMinuteSelect')).toBe(true);
});
it('should allow to select any minute from 00 -> 59', () => {
const minutSelect = findTestSubject('rollupJobCreateFrequencyHourlyMinuteSelect');
const minutSelect = find('rollupJobCreateFrequencyHourlyMinuteSelect');
const options = minutSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(60));
});
@ -210,19 +210,19 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should have 1 additional configuration with hour and minute selects', () => {
expect(findTestSubject('rollupCronFrequencyConfiguration').length).toBe(1);
expect(testSubjectExists('rollupJobCreateFrequencyDailyHourSelect')).toBe(true);
expect(testSubjectExists('rollupJobCreateFrequencyDailyMinuteSelect')).toBe(true);
expect(find('rollupCronFrequencyConfiguration').length).toBe(1);
expect(exists('rollupJobCreateFrequencyDailyHourSelect')).toBe(true);
expect(exists('rollupJobCreateFrequencyDailyMinuteSelect')).toBe(true);
});
it('should allow to select any hour from 00 -> 23', () => {
const hourSelect = findTestSubject('rollupJobCreateFrequencyDailyHourSelect');
const hourSelect = find('rollupJobCreateFrequencyDailyHourSelect');
const options = hourSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(24));
});
it('should allow to select any miute from 00 -> 59', () => {
const minutSelect = findTestSubject('rollupJobCreateFrequencyDailyMinuteSelect');
const minutSelect = find('rollupJobCreateFrequencyDailyMinuteSelect');
const options = minutSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(60));
});
@ -234,14 +234,14 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should have 2 additional configurations with day, hour and minute selects', () => {
expect(findTestSubject('rollupCronFrequencyConfiguration').length).toBe(2);
expect(testSubjectExists('rollupJobCreateFrequencyWeeklyDaySelect')).toBe(true);
expect(testSubjectExists('rollupJobCreateFrequencyWeeklyHourSelect')).toBe(true);
expect(testSubjectExists('rollupJobCreateFrequencyWeeklyMinuteSelect')).toBe(true);
expect(find('rollupCronFrequencyConfiguration').length).toBe(2);
expect(exists('rollupJobCreateFrequencyWeeklyDaySelect')).toBe(true);
expect(exists('rollupJobCreateFrequencyWeeklyHourSelect')).toBe(true);
expect(exists('rollupJobCreateFrequencyWeeklyMinuteSelect')).toBe(true);
});
it('should allow to select any day of the week', () => {
const hourSelect = findTestSubject('rollupJobCreateFrequencyWeeklyDaySelect');
const hourSelect = find('rollupJobCreateFrequencyWeeklyDaySelect');
const options = hourSelect.find('option').map(option => option.text());
expect(options).toEqual([
'Sunday',
@ -255,13 +255,13 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should allow to select any hour from 00 -> 23', () => {
const hourSelect = findTestSubject('rollupJobCreateFrequencyWeeklyHourSelect');
const hourSelect = find('rollupJobCreateFrequencyWeeklyHourSelect');
const options = hourSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(24));
});
it('should allow to select any miute from 00 -> 59', () => {
const minutSelect = findTestSubject('rollupJobCreateFrequencyWeeklyMinuteSelect');
const minutSelect = find('rollupJobCreateFrequencyWeeklyMinuteSelect');
const options = minutSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(60));
});
@ -273,26 +273,26 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should have 2 additional configurations with date, hour and minute selects', () => {
expect(findTestSubject('rollupCronFrequencyConfiguration').length).toBe(2);
expect(testSubjectExists('rollupJobCreateFrequencyMonthlyDateSelect')).toBe(true);
expect(testSubjectExists('rollupJobCreateFrequencyMonthlyHourSelect')).toBe(true);
expect(testSubjectExists('rollupJobCreateFrequencyMonthlyMinuteSelect')).toBe(true);
expect(find('rollupCronFrequencyConfiguration').length).toBe(2);
expect(exists('rollupJobCreateFrequencyMonthlyDateSelect')).toBe(true);
expect(exists('rollupJobCreateFrequencyMonthlyHourSelect')).toBe(true);
expect(exists('rollupJobCreateFrequencyMonthlyMinuteSelect')).toBe(true);
});
it('should allow to select any date of the month from 1st to 31st', () => {
const dateSelect = findTestSubject('rollupJobCreateFrequencyMonthlyDateSelect');
const dateSelect = find('rollupJobCreateFrequencyMonthlyDateSelect');
const options = dateSelect.find('option').map(option => option.text());
expect(options.length).toEqual(31);
});
it('should allow to select any hour from 00 -> 23', () => {
const hourSelect = findTestSubject('rollupJobCreateFrequencyMonthlyHourSelect');
const hourSelect = find('rollupJobCreateFrequencyMonthlyHourSelect');
const options = hourSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(24));
});
it('should allow to select any miute from 00 -> 59', () => {
const minutSelect = findTestSubject('rollupJobCreateFrequencyMonthlyMinuteSelect');
const minutSelect = find('rollupJobCreateFrequencyMonthlyMinuteSelect');
const options = minutSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(60));
});
@ -304,15 +304,15 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should have 3 additional configurations with month, date, hour and minute selects', () => {
expect(findTestSubject('rollupCronFrequencyConfiguration').length).toBe(3);
expect(testSubjectExists('rollupJobCreateFrequencyYearlyMonthSelect')).toBe(true);
expect(testSubjectExists('rollupJobCreateFrequencyYearlyDateSelect')).toBe(true);
expect(testSubjectExists('rollupJobCreateFrequencyYearlyHourSelect')).toBe(true);
expect(testSubjectExists('rollupJobCreateFrequencyYearlyMinuteSelect')).toBe(true);
expect(find('rollupCronFrequencyConfiguration').length).toBe(3);
expect(exists('rollupJobCreateFrequencyYearlyMonthSelect')).toBe(true);
expect(exists('rollupJobCreateFrequencyYearlyDateSelect')).toBe(true);
expect(exists('rollupJobCreateFrequencyYearlyHourSelect')).toBe(true);
expect(exists('rollupJobCreateFrequencyYearlyMinuteSelect')).toBe(true);
});
it('should allow to select any month of the year', () => {
const monthSelect = findTestSubject('rollupJobCreateFrequencyYearlyMonthSelect');
const monthSelect = find('rollupJobCreateFrequencyYearlyMonthSelect');
const options = monthSelect.find('option').map(option => option.text());
expect(options).toEqual([
'January',
@ -331,19 +331,19 @@ describe('Create Rollup Job, step 1: Logistics', () => {
});
it('should allow to select any date of the month from 1st to 31st', () => {
const dateSelect = findTestSubject('rollupJobCreateFrequencyYearlyDateSelect');
const dateSelect = find('rollupJobCreateFrequencyYearlyDateSelect');
const options = dateSelect.find('option').map(option => option.text());
expect(options.length).toEqual(31);
});
it('should allow to select any hour from 00 -> 23', () => {
const hourSelect = findTestSubject('rollupJobCreateFrequencyYearlyHourSelect');
const hourSelect = find('rollupJobCreateFrequencyYearlyHourSelect');
const options = hourSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(24));
});
it('should allow to select any miute from 00 -> 59', () => {
const minutSelect = findTestSubject('rollupJobCreateFrequencyYearlyMinuteSelect');
const minutSelect = find('rollupJobCreateFrequencyYearlyMinuteSelect');
const options = minutSelect.find('option').map(option => option.text());
expect(options).toEqual(generateStringSequenceOfNumbers(60));
});
@ -352,15 +352,15 @@ describe('Create Rollup Job, step 1: Logistics', () => {
describe('advanced cron expression', () => {
const activateAdvancedCronExpression = () => {
findTestSubject('rollupShowAdvancedCronLink').simulate('click');
find('rollupShowAdvancedCronLink').simulate('click');
};
it('should allow to create a cron expression', () => {
expect(testSubjectExists('rollupAdvancedCron')).toBe(false);
expect(exists('rollupAdvancedCron')).toBe(false);
activateAdvancedCronExpression();
expect(testSubjectExists('rollupAdvancedCron')).toBe(true);
expect(exists('rollupAdvancedCron')).toBe(true);
});
it('should not be empty', () => {
@ -385,11 +385,11 @@ describe('Create Rollup Job, step 1: Logistics', () => {
describe('page size', () => {
beforeEach(() => {
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(false);
expect(find('rollupJobNextButton').props().disabled).toBe(false);
});
afterEach(() => {
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(true);
expect(find('rollupJobNextButton').props().disabled).toBe(true);
});
it('should not be empty', () => {
@ -407,11 +407,11 @@ describe('Create Rollup Job, step 1: Logistics', () => {
describe('delay', () => {
beforeEach(() => {
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(false);
expect(find('rollupJobNextButton').props().disabled).toBe(false);
});
afterEach(() => {
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(true);
expect(find('rollupJobNextButton').props().disabled).toBe(true);
});
it('should validate the interval format', () => {

View file

@ -21,8 +21,8 @@ jest.mock('lodash/function/debounce', () => fn => fn);
describe('Create Rollup Job, step 5: Metrics', () => {
let server;
let findTestSubject;
let testSubjectExists;
let find;
let exists;
let userActions;
let mockIndexPatternValidityResponse;
let getEuiStepsHorizontalActive;
@ -34,8 +34,8 @@ describe('Create Rollup Job, step 5: Metrics', () => {
server.respondImmediately = true;
({ mockIndexPatternValidityResponse } = mockServerResponses(server));
({
findTestSubject,
testSubjectExists,
find,
exists,
userActions,
getEuiStepsHorizontalActive,
goToStep,
@ -52,7 +52,7 @@ describe('Create Rollup Job, step 5: Metrics', () => {
const goToStepAndOpenFieldChooser = async () => {
await goToStep(5);
findTestSubject('rollupJobShowFieldChooserButton').simulate('click');
find('rollupJobShowFieldChooserButton').simulate('click');
};
describe('layout', () => {
@ -65,17 +65,17 @@ describe('Create Rollup Job, step 5: Metrics', () => {
});
it('should have the title set to "Metrics"', () => {
expect(testSubjectExists('rollupJobCreateMetricsTitle')).toBe(true);
expect(exists('rollupJobCreateMetricsTitle')).toBe(true);
});
it('should have a link to the documentation', () => {
expect(testSubjectExists('rollupJobCreateMetricsDocsButton')).toBe(true);
expect(exists('rollupJobCreateMetricsDocsButton')).toBe(true);
});
it('should have the "next" and "back" button visible', () => {
expect(testSubjectExists('rollupJobBackButton')).toBe(true);
expect(testSubjectExists('rollupJobNextButton')).toBe(true);
expect(testSubjectExists('rollupJobSaveButton')).toBe(false);
expect(exists('rollupJobBackButton')).toBe(true);
expect(exists('rollupJobNextButton')).toBe(true);
expect(exists('rollupJobSaveButton')).toBe(false);
});
it('should go to the "Histogram" step when clicking the back button', async () => {
@ -89,11 +89,11 @@ describe('Create Rollup Job, step 5: Metrics', () => {
});
it('should have a button to display the list of metrics fields to chose from', () => {
expect(testSubjectExists('rollupJobMetricsFieldChooser')).toBe(false);
expect(exists('rollupJobMetricsFieldChooser')).toBe(false);
findTestSubject('rollupJobShowFieldChooserButton').simulate('click');
find('rollupJobShowFieldChooserButton').simulate('click');
expect(testSubjectExists('rollupJobMetricsFieldChooser')).toBe(true);
expect(exists('rollupJobMetricsFieldChooser')).toBe(true);
});
});
@ -104,15 +104,15 @@ describe('Create Rollup Job, step 5: Metrics', () => {
});
it('should have the title set to "Add metrics fields"', async () => {
expect(findTestSubject('rollupJobCreateFlyoutTitle').text()).toEqual('Add metrics fields');
expect(find('rollupJobCreateFlyoutTitle').text()).toEqual('Add metrics fields');
});
it('should have a button to close the flyout', () => {
expect(testSubjectExists('rollupJobMetricsFieldChooser')).toBe(true);
expect(exists('rollupJobMetricsFieldChooser')).toBe(true);
findTestSubject('euiFlyoutCloseButton').simulate('click');
find('euiFlyoutCloseButton').simulate('click');
expect(testSubjectExists('rollupJobMetricsFieldChooser')).toBe(false);
expect(exists('rollupJobMetricsFieldChooser')).toBe(false);
});
});
@ -151,8 +151,8 @@ describe('Create Rollup Job, step 5: Metrics', () => {
describe('fields list', () => {
const addFieldToList = (type = 'numeric') => {
if(!testSubjectExists('rollupJobMetricsFieldChooser-table')) {
findTestSubject('rollupJobShowFieldChooserButton').simulate('click');
if(!exists('rollupJobMetricsFieldChooser-table')) {
find('rollupJobShowFieldChooserButton').simulate('click');
}
const { rows } = getMetadataFromEuiTable('rollupJobMetricsFieldChooser-table');
for (let i = 0; i < rows.length; i++) {
@ -181,7 +181,7 @@ describe('Create Rollup Job, step 5: Metrics', () => {
addFieldToList('numeric');
numericTypeMetrics.forEach(type => {
try {
expect(testSubjectExists(`rollupJobMetricsCheckbox-${type}`)).toBe(true);
expect(exists(`rollupJobMetricsCheckbox-${type}`)).toBe(true);
} catch(e) {
throw(new Error(`Test subject "rollupJobMetricsCheckbox-${type}" was not found.`));
}
@ -200,7 +200,7 @@ describe('Create Rollup Job, step 5: Metrics', () => {
dateTypeMetrics.forEach(type => {
try {
expect(testSubjectExists(`rollupJobMetricsCheckbox-${type}`)).toBe(true);
expect(exists(`rollupJobMetricsCheckbox-${type}`)).toBe(true);
} catch(e) {
throw(new Error(`Test subject "rollupJobMetricsCheckbox-${type}" was not found.`));
}
@ -214,15 +214,15 @@ describe('Create Rollup Job, step 5: Metrics', () => {
});
it('should not allow to go to the next step if at least one metric type is not selected', () => {
expect(testSubjectExists('rollupJobCreateStepError')).toBeFalsy();
expect(exists('rollupJobCreateStepError')).toBeFalsy();
addFieldToList('numeric');
userActions.clickNextStep();
const stepError = findTestSubject('rollupJobCreateStepError');
const stepError = find('rollupJobCreateStepError');
expect(stepError.length).toBeTruthy();
expect(stepError.text()).toEqual('Select metrics types for these fields or remove them: a-numericField.');
expect(findTestSubject('rollupJobNextButton').props().disabled).toBe(true);
expect(find('rollupJobNextButton').props().disabled).toBe(true);
});
it('should have a delete button on each row to remove the metric field', async () => {

View file

@ -22,8 +22,8 @@ jest.mock('lodash/function/debounce', () => fn => fn);
describe('Create Rollup Job, step 5: Metrics', () => {
let server;
let findTestSubject;
let testSubjectExists;
let find;
let exists;
let userActions;
let mockIndexPatternValidityResponse;
let getEuiStepsHorizontalActive;
@ -36,8 +36,8 @@ describe('Create Rollup Job, step 5: Metrics', () => {
server.respondImmediately = true;
({ mockIndexPatternValidityResponse } = mockServerResponses(server));
({
findTestSubject,
testSubjectExists,
find,
exists,
userActions,
getEuiStepsHorizontalActive,
goToStep,
@ -60,13 +60,13 @@ describe('Create Rollup Job, step 5: Metrics', () => {
});
it('should have the title set to "Review"', () => {
expect(testSubjectExists('rollupJobCreateReviewTitle')).toBe(true);
expect(exists('rollupJobCreateReviewTitle')).toBe(true);
});
it('should have the "next" and "save" button visible', () => {
expect(testSubjectExists('rollupJobBackButton')).toBe(true);
expect(testSubjectExists('rollupJobNextButton')).toBe(false);
expect(testSubjectExists('rollupJobSaveButton')).toBe(true);
expect(exists('rollupJobBackButton')).toBe(true);
expect(exists('rollupJobNextButton')).toBe(false);
expect(exists('rollupJobSaveButton')).toBe(true);
});
it('should go to the "Metrics" step when clicking the back button', async () => {
@ -76,9 +76,9 @@ describe('Create Rollup Job, step 5: Metrics', () => {
});
describe('tabs', () => {
const getTabsText = () => findTestSubject('stepReviewTab').map(tab => tab.text());
const getTabsText = () => find('stepReviewTab').map(tab => tab.text());
const selectFirstField = (step) => {
findTestSubject('rollupJobShowFieldChooserButton').simulate('click');
find('rollupJobShowFieldChooserButton').simulate('click');
// Select the first term field
getMetadataFromEuiTable(`rollupJob${step}FieldChooser-table`)

View file

@ -21,8 +21,8 @@ jest.mock('lodash/function/debounce', () => fn => fn);
describe('Create Rollup Job, step 3: Terms', () => {
let server;
let findTestSubject;
let testSubjectExists;
let find;
let exists;
let userActions;
let mockIndexPatternValidityResponse;
let getEuiStepsHorizontalActive;
@ -34,8 +34,8 @@ describe('Create Rollup Job, step 3: Terms', () => {
server.respondImmediately = true;
({ mockIndexPatternValidityResponse } = mockServerResponses(server));
({
findTestSubject,
testSubjectExists,
find,
exists,
userActions,
getEuiStepsHorizontalActive,
goToStep,
@ -52,7 +52,7 @@ describe('Create Rollup Job, step 3: Terms', () => {
const goToStepAndOpenFieldChooser = async () => {
await goToStep(3);
findTestSubject('rollupJobShowFieldChooserButton').simulate('click');
find('rollupJobShowFieldChooserButton').simulate('click');
};
describe('layout', () => {
@ -65,17 +65,17 @@ describe('Create Rollup Job, step 3: Terms', () => {
});
it('should have the title set to "Terms"', () => {
expect(testSubjectExists('rollupJobCreateTermsTitle')).toBe(true);
expect(exists('rollupJobCreateTermsTitle')).toBe(true);
});
it('should have a link to the documentation', () => {
expect(testSubjectExists('rollupJobCreateTermsDocsButton')).toBe(true);
expect(exists('rollupJobCreateTermsDocsButton')).toBe(true);
});
it('should have the "next" and "back" button visible', () => {
expect(testSubjectExists('rollupJobBackButton')).toBe(true);
expect(testSubjectExists('rollupJobNextButton')).toBe(true);
expect(testSubjectExists('rollupJobSaveButton')).toBe(false);
expect(exists('rollupJobBackButton')).toBe(true);
expect(exists('rollupJobNextButton')).toBe(true);
expect(exists('rollupJobSaveButton')).toBe(false);
});
it('should go to the "Date histogram" step when clicking the back button', async () => {
@ -89,11 +89,11 @@ describe('Create Rollup Job, step 3: Terms', () => {
});
it('should have a button to display the list of terms to chose from', () => {
expect(testSubjectExists('rollupJobTermsFieldChooser')).toBe(false);
expect(exists('rollupJobTermsFieldChooser')).toBe(false);
findTestSubject('rollupJobShowFieldChooserButton').simulate('click');
find('rollupJobShowFieldChooserButton').simulate('click');
expect(testSubjectExists('rollupJobTermsFieldChooser')).toBe(true);
expect(exists('rollupJobTermsFieldChooser')).toBe(true);
});
});
@ -104,15 +104,15 @@ describe('Create Rollup Job, step 3: Terms', () => {
});
it('should have the title set to "Add terms fields"', async () => {
expect(findTestSubject('rollupJobCreateFlyoutTitle').text()).toEqual('Add terms fields');
expect(find('rollupJobCreateFlyoutTitle').text()).toEqual('Add terms fields');
});
it('should have a button to close the flyout', () => {
expect(testSubjectExists('rollupJobTermsFieldChooser')).toBe(true);
expect(exists('rollupJobTermsFieldChooser')).toBe(true);
findTestSubject('euiFlyoutCloseButton').simulate('click');
find('euiFlyoutCloseButton').simulate('click');
expect(testSubjectExists('rollupJobTermsFieldChooser')).toBe(false);
expect(exists('rollupJobTermsFieldChooser')).toBe(false);
});
});

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { getRandomString } from '../__jest__/utils';
import { getRandomString } from '../../../test_utils';
const initialValues = {
dateHistogramField: 'timestamp',

View file

@ -44,6 +44,7 @@ export const TabHistogram = ({ histogram, histogramInterval }) => (
<FieldList
columns={columns}
fields={histogram}
dataTestSubj="detailPanelHistogramTabTable"
/>
</Fragment>
);

View file

@ -25,5 +25,6 @@ export const TabMetrics = ({ metrics }) => (
<FieldList
columns={columns}
fields={metrics}
dataTestSubj="detailPanelMetricsTabTable"
/>
);

View file

@ -18,5 +18,6 @@ export const TabTerms = ({ terms }) => (
<FieldList
columns={columns}
fields={terms}
dataTestSubj="detailPanelTermsTabTable"
/>
);

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { registerTestBed } from '../../../../../__jest__/utils';
import { registerTestBed } from '../../../../../../../test_utils';
import { getJob } from '../../../../../fixtures';
import { rollupJobsStore } from '../../../store';
import { DetailPanel } from './detail_panel';
@ -42,16 +42,16 @@ const initTestBed = registerTestBed(DetailPanel, defaultProps, rollupJobsStore);
describe('<DetailPanel />', () => {
describe('layout', () => {
let component;
let findTestSubject;
let testSubjectExists;
let find;
let exists;
beforeEach(() => {
({ component, findTestSubject } = initTestBed());
({ component, find } = initTestBed());
});
it('should have the title set to the current Job "id"', () => {
const { job } = defaultProps;
const title = findTestSubject('rollupJobDetailsFlyoutTitle');
const title = find('rollupJobDetailsFlyoutTitle');
expect(title.length).toBe(1);
expect(title.text()).toEqual(job.id);
});
@ -66,19 +66,19 @@ describe('<DetailPanel />', () => {
});
it('should show a loading when the job is loading', () => {
({ component, findTestSubject, testSubjectExists } = initTestBed({ isLoading: true }));
const loading = findTestSubject('rollupJobDetailLoading');
({ component, find, exists } = initTestBed({ isLoading: true }));
const loading = find('rollupJobDetailLoading');
expect(loading.length).toBeTruthy();
expect(loading.text()).toEqual('Loading rollup job...');
// Make sure the title and the tabs are visible
expect(testSubjectExists('detailPanelTabSelected')).toBeTruthy();
expect(testSubjectExists('rollupJobDetailsFlyoutTitle')).toBeTruthy();
expect(exists('detailPanelTabSelected')).toBeTruthy();
expect(exists('rollupJobDetailsFlyoutTitle')).toBeTruthy();
});
it('should display a message when no job is provided', () => {
({ component, findTestSubject } = initTestBed({ job: undefined }));
expect(findTestSubject('rollupJobDetailJobNotFound').text()).toEqual('Rollup job not found');
({ component, find } = initTestBed({ job: undefined }));
expect(find('rollupJobDetailJobNotFound').text()).toEqual('Rollup job not found');
});
});
@ -122,12 +122,12 @@ describe('<DetailPanel />', () => {
describe('summary tab content', () => {
// Init testBed on the SUMMARY tab
const panelType = JOB_DETAILS_TAB_SUMMARY;
const { findTestSubject } = initTestBed({ panelType });
const { find } = initTestBed({ panelType });
it('should have a "Logistics", "Date histogram" and "Stats" section', () => {
const expectedSections = ['Logistics', 'DateHistogram', 'Stats'];
const sectionsFound = expectedSections.reduce((sectionsFound, section) => {
if (findTestSubject(`rollupJobDetailSummary${section}Section`).length) {
if (find(`rollupJobDetailSummary${section}Section`).length) {
sectionsFound.push(section);
}
return sectionsFound;
@ -141,7 +141,7 @@ describe('<DetailPanel />', () => {
it('should have "Index pattern", "Rollup index", "Cron" and "Delay" subsections', () => {
const logisticsSubsectionsTitles = LOGISTICS_SUBSECTIONS.reduce((subSections, subSection) => {
if (findTestSubject(`rollupJobDetailLogistics${subSection}Title`)) {
if (find(`rollupJobDetailLogistics${subSection}Title`)) {
subSections.push(subSection);
}
return subSections;
@ -151,7 +151,7 @@ describe('<DetailPanel />', () => {
it('should set the correct job value for each of the subsection', () => {
LOGISTICS_SUBSECTIONS.forEach((subSection) => {
const wrapper = findTestSubject(`rollupJobDetailLogistics${subSection}Description`);
const wrapper = find(`rollupJobDetailLogistics${subSection}Description`);
expect(wrapper.length).toBe(1);
const description = wrapper.text();
@ -181,7 +181,7 @@ describe('<DetailPanel />', () => {
it('should have "Time field", "Timezone", "Interval" subsections', () => {
const dateHistogramSubsections = DATE_HISTOGRAMS_SUBSECTIONS.reduce((subSections, subSection) => {
if (findTestSubject(`rollupJobDetailDateHistogram${subSection}Title`)) {
if (find(`rollupJobDetailDateHistogram${subSection}Title`)) {
subSections.push(subSection);
}
return subSections;
@ -191,7 +191,7 @@ describe('<DetailPanel />', () => {
it('should set the correct job value for each of the subsection', () => {
DATE_HISTOGRAMS_SUBSECTIONS.forEach((subSection) => {
const wrapper = findTestSubject(`rollupJobDetailDateHistogram${subSection}Description`);
const wrapper = find(`rollupJobDetailDateHistogram${subSection}Description`);
expect(wrapper.length).toBe(1);
const description = wrapper.text();
@ -218,7 +218,7 @@ describe('<DetailPanel />', () => {
it('should have "Documents processed", "Pages processed", "Rollups indexed" and "Trigger count" subsections', () => {
const statsSubSections = STATS_SUBSECTIONS.reduce((subSections, subSection) => {
if (findTestSubject(`rollupJobDetailStats${subSection}Title`)) {
if (find(`rollupJobDetailStats${subSection}Title`)) {
subSections.push(subSection);
}
return subSections;
@ -228,7 +228,7 @@ describe('<DetailPanel />', () => {
it('should set the correct job value for each of the subsection', () => {
STATS_SUBSECTIONS.forEach((subSection) => {
const wrapper = findTestSubject(`rollupJobDetailStats${subSection}Description`);
const wrapper = find(`rollupJobDetailStats${subSection}Description`);
expect(wrapper.length).toBe(1);
const description = wrapper.text();
@ -253,7 +253,7 @@ describe('<DetailPanel />', () => {
});
it('should display the job status', () => {
const statsSection = findTestSubject('rollupJobDetailSummaryStatsSection');
const statsSection = find('rollupJobDetailSummaryStatsSection');
expect(statsSection.length).toBe(1);
expect(defaultJob.status).toEqual('stopped'); // make sure status is Stopped
expect(statsSection.find('EuiHealth').text()).toEqual('Stopped');
@ -264,74 +264,44 @@ describe('<DetailPanel />', () => {
describe('terms tab content', () => {
// Init testBed on the TERMS tab
const panelType = JOB_DETAILS_TAB_TERMS;
const { findTestSubject } = initTestBed({ panelType });
const tabContent = findTestSubject('rollupJobDetailTabContent');
const getRowsText = () => (
tabContent
.find('tr')
.map(row => row.find('.euiTableCellContent').text())
.slice(1) // we remove the first row as it is the table header
);
const { getMetadataFromEuiTable } = initTestBed({ panelType });
const { tableCellsValues } = getMetadataFromEuiTable('detailPanelTermsTabTable');
it('should list the Job terms fields', () => {
const rowsText = getRowsText();
const expected = defaultJob.terms.map(term => term.name);
expect(rowsText).toEqual(expected);
const expected = defaultJob.terms.map(term => [term.name]);
expect(tableCellsValues).toEqual(expected);
});
});
describe('histogram tab content', () => {
// Init testBed on the HISTOGRAM tab
const panelType = JOB_DETAILS_TAB_HISTOGRAM;
const { findTestSubject } = initTestBed({ panelType });
const tabContent = findTestSubject('rollupJobDetailTabContent');
const getRowsText = () => (
tabContent
.find('tr')
.map(row => row.find('.euiTableCellContent').text())
.slice(1) // we remove the first row as it is the table header
);
const { getMetadataFromEuiTable } = initTestBed({ panelType });
const { tableCellsValues } = getMetadataFromEuiTable('detailPanelHistogramTabTable');
it('should list the Job histogram fields', () => {
const rowsText = getRowsText();
const expected = defaultJob.histogram.map(h => h.name);
expect(rowsText).toEqual(expected);
const expected = defaultJob.histogram.map(h => [h.name]);
expect(tableCellsValues).toEqual(expected);
});
});
describe('metrics tab content', () => {
// Init testBed on the METRICS tab
const panelType = JOB_DETAILS_TAB_METRICS;
const { findTestSubject } = initTestBed({ panelType });
const tabContent = findTestSubject('rollupJobDetailTabContent');
const getRows = () => (
tabContent
.find('tr')
.slice(1)
);
const { getMetadataFromEuiTable } = initTestBed({ panelType });
const { tableCellsValues } = getMetadataFromEuiTable('detailPanelMetricsTabTable');
it('should list the Job metrics fields and their types', () => {
const rows = getRows();
rows.forEach((row, i) => {
const metric = defaultJob.metrics[i];
row.find('td').forEach((cell, j) => {
if (j === 0) {
// field
expect(cell.find('.euiTableCellContent').text()).toEqual(metric.name);
} else if (j === 1) {
// types
expect(cell.find('.euiTableCellContent').text()).toEqual(metric.types.join(', '));
}
});
});
const expected = defaultJob.metrics.map(metric => [metric.name, metric.types.join(', ')]);
expect(tableCellsValues).toEqual(expected);
});
});
describe('JSON tab content', () => {
// Init testBed on the JSON tab
const panelType = JOB_DETAILS_TAB_JSON;
const { findTestSubject } = initTestBed({ panelType });
const tabContent = findTestSubject('rollupJobDetailTabContent');
const { find } = initTestBed({ panelType });
const tabContent = find('rollupJobDetailTabContent');
it('should render the "EuiCodeEditor" with the job "json" data', () => {
const euiCodeEditor = tabContent.find('EuiCodeEditor');

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { registerTestBed } from '../../../../__jest__/utils';
import { registerTestBed } from '../../../../../../test_utils';
import { rollupJobsStore } from '../../store';
import { JobList } from './job_list';
@ -34,22 +34,22 @@ const initTestBed = registerTestBed(JobList, defaultProps, rollupJobsStore);
describe('<JobList />', () => {
it('should render empty prompt when loading is complete and there are no jobs', () => {
const { testSubjectExists } = initTestBed();
const { exists } = initTestBed();
expect(testSubjectExists('jobListEmptyPrompt')).toBeTruthy();
expect(exists('jobListEmptyPrompt')).toBeTruthy();
});
it('should display a loading message when loading the jobs', () => {
const { component, testSubjectExists } = initTestBed({ isLoading: true });
const { component, exists } = initTestBed({ isLoading: true });
expect(testSubjectExists('jobListLoading')).toBeTruthy();
expect(exists('jobListLoading')).toBeTruthy();
expect(component.find('JobTableUi').length).toBeFalsy();
});
it('should display the <JobTable /> when there are jobs', () => {
const { component, testSubjectExists } = initTestBed({ hasJobs: true });
const { component, exists } = initTestBed({ hasJobs: true });
expect(testSubjectExists('jobListLoading')).toBeFalsy();
expect(exists('jobListLoading')).toBeFalsy();
expect(component.find('JobTableUi').length).toBeTruthy();
});
@ -72,7 +72,7 @@ describe('<JobList />', () => {
});
describe('when there is an API error', () => {
const { testSubjectExists, findTestSubject } = initTestBed({
const { exists, find } = initTestBed({
jobLoadError: {
status: 400,
data: { statusCode: 400, error: 'Houston we got a problem.' }
@ -80,20 +80,20 @@ describe('<JobList />', () => {
});
it('should display a callout with the status and the message', () => {
expect(testSubjectExists('jobListError')).toBeTruthy();
expect(findTestSubject('jobListError').find('EuiText').text()).toEqual('400 Houston we got a problem.');
expect(exists('jobListError')).toBeTruthy();
expect(find('jobListError').find('EuiText').text()).toEqual('400 Houston we got a problem.');
});
});
describe('when the user does not have the permission to access it', () => {
const { testSubjectExists } = initTestBed({ jobLoadError: { status: 403 } });
const { exists } = initTestBed({ jobLoadError: { status: 403 } });
it('should render a callout message', () => {
expect(testSubjectExists('jobListNoPermission')).toBeTruthy();
expect(exists('jobListNoPermission')).toBeTruthy();
});
it('should display the page header', () => {
expect(testSubjectExists('jobListPageHeader')).toBeTruthy();
expect(exists('jobListPageHeader')).toBeTruthy();
});
});
});

View file

@ -6,7 +6,7 @@
import { Pager } from '@elastic/eui';
import { registerTestBed } from '../../../../../__jest__/utils';
import { registerTestBed } from '../../../../../../../test_utils';
import { getJobs } from '../../../../../fixtures';
import { rollupJobsStore } from '../../../store';
import { JobTable } from './job_table';
@ -40,8 +40,8 @@ describe('<JobTable />', () => {
const totalJobs = 5;
const jobs = getJobs(totalJobs);
const openDetailPanel = jest.fn();
const { findTestSubject } = initTestBed({ jobs, openDetailPanel });
const tableRows = findTestSubject('jobTableRow');
const { find } = initTestBed({ jobs, openDetailPanel });
const tableRows = find('jobTableRow');
it('should create 1 table row per job', () => {
expect(tableRows.length).toEqual(totalJobs);
@ -60,7 +60,7 @@ describe('<JobTable />', () => {
];
const tableColumns = expectedColumns.reduce((tableColumns, columnId) => (
findTestSubject(`jobTableHeaderCell-${columnId}`).length
find(`jobTableHeaderCell-${columnId}`).length
? tableColumns.concat(columnId)
: tableColumns
), []);
@ -115,16 +115,16 @@ describe('<JobTable />', () => {
});
describe('action menu', () => {
let findTestSubject;
let testSubjectExists;
let find;
let exists;
let selectJob;
let jobs;
let tableRows;
beforeEach(() => {
jobs = getJobs();
({ findTestSubject, testSubjectExists } = initTestBed({ jobs }));
tableRows = findTestSubject('jobTableRow');
({ find, exists } = initTestBed({ jobs }));
tableRows = find('jobTableRow');
selectJob = (index = 0) => {
const job = jobs[index];
@ -135,11 +135,11 @@ describe('<JobTable />', () => {
});
it('should be visible when a job is selected', () => {
expect(testSubjectExists('jobActionMenuButton')).toBeFalsy();
expect(exists('jobActionMenuButton')).toBeFalsy();
selectJob();
expect(testSubjectExists('jobActionMenuButton')).toBeTruthy();
expect(exists('jobActionMenuButton')).toBeTruthy();
});
it('should have a "start" and "delete" action for a job that is stopped', () => {
@ -148,10 +148,10 @@ describe('<JobTable />', () => {
job.status = 'stopped';
selectJob(index);
const menuButton = findTestSubject('jobActionMenuButton');
const menuButton = find('jobActionMenuButton');
menuButton.simulate('click'); // open the context menu
const contextMenu = findTestSubject('jobActionContextMenu');
const contextMenu = find('jobActionContextMenu');
expect(contextMenu.length).toBeTruthy();
const contextMenuButtons = contextMenu.find('button');
@ -165,9 +165,9 @@ describe('<JobTable />', () => {
job.status = 'started';
selectJob(index);
findTestSubject('jobActionMenuButton').simulate('click');
find('jobActionMenuButton').simulate('click');
const contextMenuButtons = findTestSubject('jobActionContextMenu').find('button');
const contextMenuButtons = find('jobActionContextMenu').find('button');
const buttonsLabel = contextMenuButtons.map(btn => btn.text());
expect(buttonsLabel).toEqual(['Stop job']);
});
@ -180,9 +180,9 @@ describe('<JobTable />', () => {
selectJob(0);
selectJob(1);
findTestSubject('jobActionMenuButton').simulate('click');
find('jobActionMenuButton').simulate('click');
const contextMenuButtons = findTestSubject('jobActionContextMenu').find('button');
const contextMenuButtons = find('jobActionContextMenu').find('button');
const buttonsLabel = contextMenuButtons.map(btn => btn.text());
expect(buttonsLabel).toEqual(['Start jobs', 'Stop jobs']);
});

View file

@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
export { registerTestBed } from './testbed';
export { getRandomString } from './lib';

View file

@ -4,10 +4,5 @@
* you may not use this file except in compliance with the Elastic License.
*/
export {
getRandomString,
} from './strings';
export {
registerTestBed,
} from './testbed';
export { getRandomString } from './strings';

View file

@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
export { registerTestBed } from './testbed';

View file

@ -6,7 +6,7 @@
import React from 'react';
import { Provider } from 'react-redux';
import { mountWithIntl } from '../../../../test_utils/enzyme_helpers';
import { mountWithIntl } from '../enzyme_helpers';
import { findTestSubject as findTestSubjectHelper } from '@elastic/eui/lib/test';
const registerTestSubjExists = component => (testSubject, count = 1) => findTestSubjectHelper(component, testSubject).length === count;
@ -30,8 +30,8 @@ export const registerTestBed = (Component, defaultProps, store = {}) => (props)
)
});
const testSubjectExists = registerTestSubjExists(component);
const findTestSubject = testSubject => findTestSubjectHelper(component, testSubject);
const exists = registerTestSubjExists(component);
const find = testSubject => findTestSubjectHelper(component, testSubject);
const getFormErrorsMessages = () => {
const errorMessagesWrappers = component.find('.euiFormErrorText');
@ -39,7 +39,7 @@ export const registerTestBed = (Component, defaultProps, store = {}) => (props)
};
const setInputValue = (inputTestSubject, value, isAsync = false) => {
const formInput = findTestSubject(inputTestSubject);
const formInput = find(inputTestSubject);
formInput.simulate('change', { target: { value } });
component.update();
@ -54,7 +54,7 @@ export const registerTestBed = (Component, defaultProps, store = {}) => (props)
};
const selectCheckBox = (checkboxTestSubject) => {
findTestSubject(checkboxTestSubject).simulate('change', { target: { checked: true } });
find(checkboxTestSubject).simulate('change', { target: { checked: true } });
};
/**
@ -63,7 +63,7 @@ export const registerTestBed = (Component, defaultProps, store = {}) => (props)
* @param {ReactWrapper} table enzyme react wrapper of the EuiBasicTable
*/
const getMetadataFromEuiTable = (tableTestSubject) => {
const rows = findTestSubject(tableTestSubject)
const rows = find(tableTestSubject)
.find('tr')
.slice(1) // we remove the first row as it is the table header
.map(row => ({
@ -71,7 +71,7 @@ export const registerTestBed = (Component, defaultProps, store = {}) => (props)
columns: row.find('td').map(col => ({
reactWrapper: col,
// We can't access the td value with col.text() because
// eui adds an extra div inside the table > tr > td on mobile => (".euiTableRowCell__mobileHeader")
// eui adds an extra div in td on mobile => (.euiTableRowCell__mobileHeader)
value: col.find('.euiTableCellContent').text()
}))
}));
@ -83,8 +83,8 @@ export const registerTestBed = (Component, defaultProps, store = {}) => (props)
return {
component,
testSubjectExists,
findTestSubject,
exists,
find,
setProps,
getFormErrorsMessages,
getMetadataFromEuiTable,