Skip to content

Commit

Permalink
[Index Management] Fix broken jest tests (elastic#173029)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabarasaba authored Dec 18, 2023
1 parent 7faa488 commit 1644274
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 60 deletions.
4 changes: 1 addition & 3 deletions .buildkite/disabled_jest_configs.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
[
"x-pack/plugins/index_management/jest.config.js"
]
[]
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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
Expand All @@ -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`,
Expand Down Expand Up @@ -589,10 +581,6 @@ describe('<TemplateCreate />', () => {
},
},
aliases: ALIASES,
lifecycle: {
enabled: true,
data_retention: '1d',
},
},
}),
})
Expand Down Expand Up @@ -620,44 +608,59 @@ describe('<TemplateCreate />', () => {
});
});

test('preview data stream', async () => {
await act(async () => {
testBed = await setup(httpSetup);
});
testBed.component.update();

const { actions } = testBed;
// Logistics
await actions.completeStepOne({
name: TEMPLATE_NAME,
indexPatterns: DEFAULT_INDEX_PATTERNS,
dataStream: {},
lifecycle: {
enabled: true,
value: 1,
unit: 'd',
},
describe('DSL', () => {
beforeEach(async () => {
await act(async () => {
testBed = await setup(httpSetup);
});
testBed.component.update();

await testBed.actions.completeStepOne({
name: TEMPLATE_NAME,
indexPatterns: DEFAULT_INDEX_PATTERNS,
dataStream: {},
lifecycle: {
enabled: true,
value: 1,
unit: 'd',
},
});
});

await act(async () => {
await actions.previewTemplate();
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');
});

expect(httpSetup.post).toHaveBeenLastCalledWith(
`${API_BASE_PATH}/index_templates/simulate`,
expect.objectContaining({
body: JSON.stringify({
template: {
lifecycle: {
enabled: true,
data_retention: '1d',
test('preview data stream', async () => {
const { actions } = testBed;

await act(async () => {
await actions.previewTemplate();
});

expect(httpSetup.post).toHaveBeenLastCalledWith(
`${API_BASE_PATH}/index_templates/simulate`,
expect.objectContaining({
body: JSON.stringify({
template: {
lifecycle: {
enabled: true,
data_retention: '1d',
},
},
},
index_patterns: DEFAULT_INDEX_PATTERNS,
data_stream: {},
allow_auto_create: false,
}),
})
);
index_patterns: DEFAULT_INDEX_PATTERNS,
data_stream: {},
allow_auto_create: false,
}),
})
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
form.setInputValue('valueDataRetentionField', String(lifecycle.value));
}

await act(async () => {
if (allowAutoCreate) {
form.toggleEuiSwitch('allowAutoCreateField.input');
}

clickNextButton();
jest.advanceTimersByTime(0);
});

component.update();
Expand Down Expand Up @@ -378,6 +375,8 @@ export type TestSubjects =
| 'settingsEditor'
| 'versionField.input'
| 'valueDataRetentionField'
| 'formWizardStep-5'
| 'lifecycleValue'
| 'mappingsEditor.formTab'
| 'mappingsEditor.advancedConfiguration.sizeEnabledToggle'
| 'previewIndexTemplate';

0 comments on commit 1644274

Please sign in to comment.