[Index Management] Fix broken jest tests (#173029)

This commit is contained in:
Ignacio Rivas 2023-12-18 17:21:28 +01:00 committed by GitHub
parent 7faa488a13
commit 164427463e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 59 deletions

View file

@ -1,3 +1 @@
[
"x-pack/plugins/index_management/jest.config.js"
]
[]

View file

@ -100,14 +100,10 @@ describe('<TemplateCreate />', () => {
httpRequestsMockHelpers.setLoadComponentTemplatesResponse(componentTemplates);
httpRequestsMockHelpers.setLoadNodesPluginsResponse([]);
// disable all react-beautiful-dnd development warnings
(window as any)['__@hello-pangea/dnd-disable-dev-warnings'] = true;
});
afterAll(() => {
jest.useRealTimers();
(window as any)['__@hello-pangea/dnd-disable-dev-warnings'] = false;
});
describe('composable index template', () => {
@ -533,11 +529,6 @@ describe('<TemplateCreate />', () => {
name: TEMPLATE_NAME,
indexPatterns: DEFAULT_INDEX_PATTERNS,
dataStream: {},
lifecycle: {
enabled: true,
value: 1,
unit: 'd',
},
allowAutoCreate: true,
});
// Component templates
@ -551,13 +542,14 @@ describe('<TemplateCreate />', () => {
});
it('should send the correct payload', async () => {
const { actions, find } = testBed;
const { component, actions, find } = testBed;
expect(find('stepTitle').text()).toEqual(`Review details for '${TEMPLATE_NAME}'`);
await act(async () => {
actions.clickNextButton();
});
component.update();
expect(httpSetup.post).toHaveBeenLastCalledWith(
`${API_BASE_PATH}/index_templates`,
@ -589,10 +581,6 @@ describe('<TemplateCreate />', () => {
},
},
aliases: ALIASES,
lifecycle: {
enabled: true,
data_retention: '1d',
},
},
}),
})
@ -620,15 +608,14 @@ describe('<TemplateCreate />', () => {
});
});
test('preview data stream', async () => {
describe('DSL', () => {
beforeEach(async () => {
await act(async () => {
testBed = await setup(httpSetup);
});
testBed.component.update();
const { actions } = testBed;
// Logistics
await actions.completeStepOne({
await testBed.actions.completeStepOne({
name: TEMPLATE_NAME,
indexPatterns: DEFAULT_INDEX_PATTERNS,
dataStream: {},
@ -638,6 +625,21 @@ describe('<TemplateCreate />', () => {
unit: 'd',
},
});
});
test('should include DSL in summary when set in step 1', async () => {
const { find, component } = testBed;
await act(async () => {
testBed.find('formWizardStep-5').simulate('click');
});
component.update();
expect(find('lifecycleValue').text()).toContain('1 day');
});
test('preview data stream', async () => {
const { actions } = testBed;
await act(async () => {
await actions.previewTemplate();
@ -661,3 +663,4 @@ describe('<TemplateCreate />', () => {
);
});
});
});

View file

@ -185,27 +185,24 @@ export const formSetup = async (initTestBed: SetupFunc<TestSubjects>) => {
if (version) {
form.setInputValue('versionField.input', JSON.stringify(version));
}
if (allowAutoCreate) {
form.toggleEuiSwitch('allowAutoCreateField.input');
}
});
component.update();
if (lifecycle && lifecycle.enabled) {
act(() => {
await act(async () => {
form.toggleEuiSwitch('dataRetentionToggle.input');
});
component.update();
act(() => {
form.setInputValue('valueDataRetentionField', String(lifecycle.value));
});
}
await act(async () => {
if (allowAutoCreate) {
form.toggleEuiSwitch('allowAutoCreateField.input');
}
clickNextButton();
jest.advanceTimersByTime(0);
});
component.update();
@ -378,6 +375,8 @@ export type TestSubjects =
| 'settingsEditor'
| 'versionField.input'
| 'valueDataRetentionField'
| 'formWizardStep-5'
| 'lifecycleValue'
| 'mappingsEditor.formTab'
| 'mappingsEditor.advancedConfiguration.sizeEnabledToggle'
| 'previewIndexTemplate';