Skip to content

Commit

Permalink
Adapt mocha tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Jan 20, 2020
1 parent c668ff6 commit 736a88c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import ngMock from 'ng_mock';
import { getSort } from '../../../np_ready/angular/doc_table/lib/get_sort';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

const defaultSort = [{ time: 'desc' }];
let indexPattern;

describe('docTable', function() {
Expand Down Expand Up @@ -51,21 +50,21 @@ describe('docTable', function() {
expect(getSort([{ bytes: 'desc' }], indexPattern)).to.eql([{ bytes: 'desc' }]);
});

it('should sort by the default when passed an unsortable field', function() {
expect(getSort(['non-sortable', 'asc'], indexPattern)).to.eql(defaultSort);
expect(getSort(['lol_nope', 'asc'], indexPattern)).to.eql(defaultSort);
it('should return an empty array when passed an unsortable field', function() {
expect(getSort(['non-sortable', 'asc'], indexPattern)).to.eql([]);
expect(getSort(['lol_nope', 'asc'], indexPattern)).to.eql([]);

delete indexPattern.timeFieldName;
expect(getSort(['non-sortable', 'asc'], indexPattern)).to.eql([]);
});

it('should sort in reverse chrono order otherwise on time based patterns', function() {
expect(getSort([], indexPattern)).to.eql(defaultSort);
expect(getSort(['foo'], indexPattern)).to.eql(defaultSort);
expect(getSort({ foo: 'bar' }, indexPattern)).to.eql(defaultSort);
it('should return an empty array ', function() {
expect(getSort([], indexPattern)).to.eql([]);
expect(getSort(['foo'], indexPattern)).to.eql([]);
expect(getSort({ foo: 'bar' }, indexPattern)).to.eql([]);
});

it('should sort by score on non-time patterns', function() {
it('should return an empty array on non-time patterns', function() {
delete indexPattern.timeFieldName;

expect(getSort([], indexPattern)).to.eql([]);
Expand All @@ -87,16 +86,16 @@ describe('docTable', function() {
expect(getSort.array([{ bytes: 'desc' }], indexPattern)).to.eql([['bytes', 'desc']]);
});

it('should sort by the default when passed an unsortable field', function() {
expect(getSort.array([{ 'non-sortable': 'asc' }], indexPattern)).to.eql([['time', 'desc']]);
expect(getSort.array([{ lol_nope: 'asc' }], indexPattern)).to.eql([['time', 'desc']]);
it('should sort by an empty array when an unsortable field is given', function() {
expect(getSort.array([{ 'non-sortable': 'asc' }], indexPattern)).to.eql([]);
expect(getSort.array([{ lol_nope: 'asc' }], indexPattern)).to.eql([]);

delete indexPattern.timeFieldName;
expect(getSort.array([{ 'non-sortable': 'asc' }], indexPattern)).to.eql([]);
});

it('should sort by the default when passed an empty sort', () => {
expect(getSort.array([], indexPattern)).to.eql([['time', 'desc']]);
it('should return an empty array when passed an empty sort array', () => {
expect(getSort.array([], indexPattern)).to.eql([]);

delete indexPattern.timeFieldName;
expect(getSort.array([], indexPattern)).to.eql([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export function getSort(sort, indexPattern) {
return [];
}

getSort.array = function(sort, indexPattern, defaultSortOrder, useDefault = true) {
return getSort(sort, indexPattern, defaultSortOrder, useDefault).map(sortPair =>
getSort.array = function(sort, indexPattern) {
return getSort(sort, indexPattern).map(sortPair =>
_(sortPair)
.pairs()
.pop()
Expand Down

0 comments on commit 736a88c

Please sign in to comment.