[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.setLoadComponentTemplatesResponse(componentTemplates);
httpRequestsMockHelpers.setLoadNodesPluginsResponse([]); httpRequestsMockHelpers.setLoadNodesPluginsResponse([]);
// disable all react-beautiful-dnd development warnings
(window as any)['__@hello-pangea/dnd-disable-dev-warnings'] = true;
}); });
afterAll(() => { afterAll(() => {
jest.useRealTimers(); jest.useRealTimers();
(window as any)['__@hello-pangea/dnd-disable-dev-warnings'] = false;
}); });
describe('composable index template', () => { describe('composable index template', () => {
@ -533,11 +529,6 @@ describe('<TemplateCreate />', () => {
name: TEMPLATE_NAME, name: TEMPLATE_NAME,
indexPatterns: DEFAULT_INDEX_PATTERNS, indexPatterns: DEFAULT_INDEX_PATTERNS,
dataStream: {}, dataStream: {},
lifecycle: {
enabled: true,
value: 1,
unit: 'd',
},
allowAutoCreate: true, allowAutoCreate: true,
}); });
// Component templates // Component templates
@ -551,13 +542,14 @@ describe('<TemplateCreate />', () => {
}); });
it('should send the correct payload', async () => { 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}'`); expect(find('stepTitle').text()).toEqual(`Review details for '${TEMPLATE_NAME}'`);
await act(async () => { await act(async () => {
actions.clickNextButton(); actions.clickNextButton();
}); });
component.update();
expect(httpSetup.post).toHaveBeenLastCalledWith( expect(httpSetup.post).toHaveBeenLastCalledWith(
`${API_BASE_PATH}/index_templates`, `${API_BASE_PATH}/index_templates`,
@ -589,10 +581,6 @@ describe('<TemplateCreate />', () => {
}, },
}, },
aliases: ALIASES, 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 () => { await act(async () => {
testBed = await setup(httpSetup); testBed = await setup(httpSetup);
}); });
testBed.component.update(); testBed.component.update();
const { actions } = testBed; await testBed.actions.completeStepOne({
// Logistics
await actions.completeStepOne({
name: TEMPLATE_NAME, name: TEMPLATE_NAME,
indexPatterns: DEFAULT_INDEX_PATTERNS, indexPatterns: DEFAULT_INDEX_PATTERNS,
dataStream: {}, dataStream: {},
@ -638,6 +625,21 @@ describe('<TemplateCreate />', () => {
unit: 'd', 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 act(async () => {
await actions.previewTemplate(); await actions.previewTemplate();
@ -661,3 +663,4 @@ describe('<TemplateCreate />', () => {
); );
}); });
}); });
});

View file

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