Convert tests in index_patterns/index_patterns/__tests__ to Jest (#44873)

This commit is contained in:
Alexey Antonov 2019-09-09 17:06:08 +03:00 committed by Artyom Gospodarsky
parent c06e1a6097
commit 76a62e2714
2 changed files with 33 additions and 63 deletions

View file

@ -1,63 +0,0 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
describe('IndexPatterns#getComputedFields', function () {
let indexPattern;
let fn;
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
fn = indexPattern.getComputedFields;
}));
it('should be a function', function () {
expect(fn).to.be.a(Function);
});
it('should request all stored fields', function () {
expect(fn().storedFields).to.contain('*');
});
it('should request date fields as docvalue_fields', function () {
const docvalueFields = fn().docvalueFields;
const docvalueFieldNames = docvalueFields.map(field => field.field);
expect(docvalueFields).to.have.length(3);
expect(docvalueFieldNames).to.contain('@timestamp');
expect(docvalueFieldNames).to.contain('time');
expect(docvalueFieldNames).to.contain('utc_time');
});
it('should request date field doc values in date_time format', function () {
const docvalueFields = fn().docvalueFields;
const timestampField = docvalueFields.find((field) => field.field === '@timestamp');
expect(timestampField).to.have.property('format', 'date_time');
});
it('should not request scripted date fields as docvalue_fields', function () {
expect(fn().docvalueFields).to.not.contain('script date');
});
});

View file

@ -183,6 +183,39 @@ describe('IndexPattern', () => {
});
});
describe('getComputedFields', () => {
test('should be a function', () => {
expect(indexPattern.getComputedFields).toBeInstanceOf(Function);
});
test('should request all stored fields', () => {
expect(indexPattern.getComputedFields().storedFields).toContain('*');
});
test('should request date fields as docvalue_fields', () => {
const { docvalueFields } = indexPattern.getComputedFields();
const docValueFieldNames = docvalueFields.map(field => field.field);
expect(Object.keys(docValueFieldNames).length).toBe(3);
expect(docValueFieldNames).toContain('@timestamp');
expect(docValueFieldNames).toContain('time');
expect(docValueFieldNames).toContain('utc_time');
});
test('should request date field doc values in date_time format', () => {
const { docvalueFields } = indexPattern.getComputedFields();
const timestampField = docvalueFields.find(field => field.field === '@timestamp');
expect(timestampField).toHaveProperty('format', 'date_time');
});
test('should not request scripted date fields as docvalue_fields', () => {
const { docvalueFields } = indexPattern.getComputedFields();
expect(docvalueFields).not.toContain('script date');
});
});
describe('getNonScriptedFields', () => {
test('should return all non-scripted fields', () => {
const notScriptedNames = mockLogStashFields()