|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +import { getSortForSearchSource } from './get_sort_for_search_source'; |
| 20 | +// @ts-ignore |
| 21 | +import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; |
| 22 | +import { IndexPattern } from '../../../../kibana_services'; |
| 23 | +import { SortOrder } from '../components/table_header/helpers'; |
| 24 | + |
| 25 | +describe('getSortForSearchSource function', function () { |
| 26 | + let indexPattern: IndexPattern; |
| 27 | + beforeEach(() => { |
| 28 | + indexPattern = FixturesStubbedLogstashIndexPatternProvider() as IndexPattern; |
| 29 | + }); |
| 30 | + test('should be a function', function () { |
| 31 | + expect(typeof getSortForSearchSource === 'function').toBeTruthy(); |
| 32 | + }); |
| 33 | + |
| 34 | + test('should return an object to use for searchSource when columns are given', function () { |
| 35 | + const cols = [['bytes', 'desc']] as SortOrder[]; |
| 36 | + expect(getSortForSearchSource(cols, indexPattern)).toEqual([{ bytes: 'desc' }]); |
| 37 | + expect(getSortForSearchSource(cols, indexPattern, 'asc')).toEqual([{ bytes: 'desc' }]); |
| 38 | + delete indexPattern.timeFieldName; |
| 39 | + expect(getSortForSearchSource(cols, indexPattern)).toEqual([{ bytes: 'desc' }]); |
| 40 | + expect(getSortForSearchSource(cols, indexPattern, 'asc')).toEqual([{ bytes: 'desc' }]); |
| 41 | + }); |
| 42 | + |
| 43 | + test('should return an object to use for searchSource when no columns are given', function () { |
| 44 | + const cols = [] as SortOrder[]; |
| 45 | + expect(getSortForSearchSource(cols, indexPattern)).toEqual([{ _doc: 'desc' }]); |
| 46 | + expect(getSortForSearchSource(cols, indexPattern, 'asc')).toEqual([{ _doc: 'asc' }]); |
| 47 | + delete indexPattern.timeFieldName; |
| 48 | + expect(getSortForSearchSource(cols, indexPattern)).toEqual([{ _score: 'desc' }]); |
| 49 | + expect(getSortForSearchSource(cols, indexPattern, 'asc')).toEqual([{ _score: 'asc' }]); |
| 50 | + }); |
| 51 | +}); |
0 commit comments