@@ -8,7 +8,7 @@ import React from 'react';
88import { act } from 'react-dom/test-utils' ;
99
1010import * as fixtures from '../../../test/fixtures' ;
11- import { setupEnvironment } from '../helpers' ;
11+ import { setupEnvironment , BRANCH } from '../helpers' ;
1212
1313import { TEMPLATE_NAME , SETTINGS , ALIASES , MAPPINGS as DEFAULT_MAPPING } from './constants' ;
1414import { 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