Skip to content

Commit fb6d136

Browse files
[Index Templates] Add test for legacy templates (#83346)
1 parent 90729c6 commit fb6d136

3 files changed

Lines changed: 75 additions & 1 deletion

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export const BRANCH = '8.x';

x-pack/plugins/index_management/__jest__/client_integration/helpers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ export { nextTick, getRandomString, findTestSubject, TestBed } from '@kbn/test/j
1111
export { setupEnvironment, WithAppDependencies, services } from './setup_environment';
1212

1313
export { TestSubjects } from './test_subjects';
14+
15+
export { BRANCH } from './constants';

x-pack/plugins/index_management/__jest__/client_integration/index_template_wizard/template_edit.test.tsx

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import React from 'react';
88
import { act } from 'react-dom/test-utils';
99

1010
import * as fixtures from '../../../test/fixtures';
11-
import { setupEnvironment } from '../helpers';
11+
import { setupEnvironment, BRANCH } from '../helpers';
1212

1313
import { TEMPLATE_NAME, SETTINGS, ALIASES, MAPPINGS as DEFAULT_MAPPING } from './constants';
1414
import { setup } from './template_edit.helpers';
@@ -224,4 +224,69 @@ describe('<TemplateEdit />', () => {
224224
});
225225
});
226226
});
227+
228+
// @ts-expect-error
229+
if (BRANCH === '7.x') {
230+
describe('legacy index templates', () => {
231+
const legacyTemplateToEdit = fixtures.getTemplate({
232+
name: 'legacy_index_template',
233+
indexPatterns: ['indexPattern1'],
234+
isLegacy: true,
235+
template: {
236+
mappings: {
237+
my_mapping_type: {},
238+
},
239+
},
240+
});
241+
242+
beforeAll(() => {
243+
httpRequestsMockHelpers.setLoadTemplateResponse(legacyTemplateToEdit);
244+
});
245+
246+
beforeEach(async () => {
247+
await act(async () => {
248+
testBed = await setup();
249+
});
250+
251+
testBed.component.update();
252+
});
253+
254+
it('persists mappings type', async () => {
255+
const { actions } = testBed;
256+
// Logistics
257+
await actions.completeStepOne();
258+
// Note: "step 2" (component templates) doesn't exist for legacy templates
259+
// Index settings
260+
await actions.completeStepThree();
261+
// Mappings
262+
await actions.completeStepFour();
263+
// Aliases
264+
await actions.completeStepFive();
265+
266+
// Submit the form
267+
await act(async () => {
268+
actions.clickNextButton();
269+
});
270+
271+
const latestRequest = server.requests[server.requests.length - 1];
272+
273+
const { version, template, name, indexPatterns, _kbnMeta, order } = legacyTemplateToEdit;
274+
275+
const expected = {
276+
name,
277+
indexPatterns,
278+
version,
279+
order,
280+
template: {
281+
aliases: undefined,
282+
mappings: template!.mappings,
283+
settings: undefined,
284+
},
285+
_kbnMeta,
286+
};
287+
288+
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toEqual(expected);
289+
});
290+
});
291+
}
227292
});

0 commit comments

Comments
 (0)