Skip to content

Commit

Permalink
[Index Templates] Add test for legacy templates (#83346)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Nov 16, 2020
1 parent 90729c6 commit fb6d136
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export const BRANCH = '8.x';
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ export { nextTick, getRandomString, findTestSubject, TestBed } from '@kbn/test/j
export { setupEnvironment, WithAppDependencies, services } from './setup_environment';

export { TestSubjects } from './test_subjects';

export { BRANCH } from './constants';
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from 'react';
import { act } from 'react-dom/test-utils';

import * as fixtures from '../../../test/fixtures';
import { setupEnvironment } from '../helpers';
import { setupEnvironment, BRANCH } from '../helpers';

import { TEMPLATE_NAME, SETTINGS, ALIASES, MAPPINGS as DEFAULT_MAPPING } from './constants';
import { setup } from './template_edit.helpers';
Expand Down Expand Up @@ -224,4 +224,69 @@ describe('<TemplateEdit />', () => {
});
});
});

// @ts-expect-error
if (BRANCH === '7.x') {
describe('legacy index templates', () => {
const legacyTemplateToEdit = fixtures.getTemplate({
name: 'legacy_index_template',
indexPatterns: ['indexPattern1'],
isLegacy: true,
template: {
mappings: {
my_mapping_type: {},
},
},
});

beforeAll(() => {
httpRequestsMockHelpers.setLoadTemplateResponse(legacyTemplateToEdit);
});

beforeEach(async () => {
await act(async () => {
testBed = await setup();
});

testBed.component.update();
});

it('persists mappings type', async () => {
const { actions } = testBed;
// Logistics
await actions.completeStepOne();
// Note: "step 2" (component templates) doesn't exist for legacy templates
// Index settings
await actions.completeStepThree();
// Mappings
await actions.completeStepFour();
// Aliases
await actions.completeStepFive();

// Submit the form
await act(async () => {
actions.clickNextButton();
});

const latestRequest = server.requests[server.requests.length - 1];

const { version, template, name, indexPatterns, _kbnMeta, order } = legacyTemplateToEdit;

const expected = {
name,
indexPatterns,
version,
order,
template: {
aliases: undefined,
mappings: template!.mappings,
settings: undefined,
},
_kbnMeta,
};

expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toEqual(expected);
});
});
}
});

0 comments on commit fb6d136

Please sign in to comment.