Skip to content

Commit

Permalink
chore(NA): move canvas plugin tests out of __tests__ folder (#87519)
Browse files Browse the repository at this point in the history
* chore(NA): move canvas plugin tests out of __tests__ folder

* chore(NA): fix types import on fixtures

* chore(NA): rename helpers to test_helpers

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
mistic and kibanamachine committed Jan 6, 2021
1 parent 906984c commit 69fdcc8
Show file tree
Hide file tree
Showing 91 changed files with 308 additions and 316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { functions as browserFns } from '../../canvas_plugin_src/functions/browser';
import { ExpressionFunction } from '../../../../../src/plugins/expressions';
import { initFunctions } from '../../public/functions';
import { functions as browserFns } from '../canvas_plugin_src/functions/browser';
import { ExpressionFunction } from '../../../../src/plugins/expressions';
import { initFunctions } from '../public/functions';

export const functionSpecs = browserFns
.concat(...(initFunctions({} as any) as any))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { CanvasWorkpad, CanvasElement, CanvasPage, CanvasVariable } from '../../types';
import { CanvasWorkpad, CanvasElement, CanvasPage, CanvasVariable } from '../types';

const BaseWorkpad: CanvasWorkpad = {
'@created': '2019-02-08T18:35:23.029Z',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
import { testTable } from '../common/__tests__/fixtures/test_tables';
import { fontStyle } from '../common/__tests__/fixtures/test_styles';
import { functionWrapper } from '../../../test_helpers/function_wrapper';
import { testTable } from '../common/__fixtures__/test_tables';
import { fontStyle } from '../common/__fixtures__/test_styles';
import { markdown } from './markdown';

describe('markdown', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { elasticLogo } from '../../../../lib/elastic_logo';
import { elasticLogo } from '../../../lib/elastic_logo';

export const fontStyle = {
type: 'style',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Datatable } from '../../../../../types';
import { Datatable } from '../../../../types';

const emptyTable: Datatable = {
type: 'datatable',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
import { functionWrapper } from '../../../test_helpers/function_wrapper';
import { all } from './all';

describe('all', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
import { functionWrapper } from '../../../test_helpers/function_wrapper';
import { getFunctionErrors } from '../../../i18n';
import { emptyTable, testTable } from './__tests__/fixtures/test_tables';
import { emptyTable, testTable } from './__fixtures__/test_tables';
import { alterColumn } from './alterColumn';

const errors = getFunctionErrors().alterColumn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
import { functionWrapper } from '../../../test_helpers/function_wrapper';
import { any } from './any';

describe('any', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
import { functionWrapper } from '../../../test_helpers/function_wrapper';
import { asFn } from './as';

describe('as', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
import { functionWrapper } from '../../../test_helpers/function_wrapper';
import { getFunctionErrors } from '../../../i18n';
import { testTable } from './__tests__/fixtures/test_tables';
import { testTable } from './__fixtures__/test_tables';
import { axisConfig } from './axisConfig';

const errors = getFunctionErrors().axisConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
import { functionWrapper } from '../../../test_helpers/function_wrapper';
import { caseFn } from './case';

describe('case', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
import { testTable } from './__tests__/fixtures/test_tables';
import { functionWrapper } from '../../../test_helpers/function_wrapper';
import { testTable } from './__fixtures__/test_tables';
import { clear } from './clear';

describe('clear', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
import { emptyTable, testTable } from './__tests__/fixtures/test_tables';
import { functionWrapper } from '../../../test_helpers/function_wrapper';
import { emptyTable, testTable } from './__fixtures__/test_tables';
import { columns } from './columns';

describe('columns', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* 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.
*/

import { functionWrapper } from '../../../test_helpers/function_wrapper';
import { getFunctionErrors } from '../../../i18n';
import { compare } from './compare';

const errors = getFunctionErrors().compare;

describe('compare', () => {
const fn = functionWrapper(compare);

describe('args', () => {
describe('op', () => {
it('sets the operator', () => {
expect(fn(0, { op: 'lt', to: 1 })).toBe(true);
});

it("defaults to 'eq'", () => {
expect(fn(0, { to: 1 })).toBe(false);
expect(fn(0, { to: 0 })).toBe(true);
});

it('throws when invalid op is provided', () => {
expect(() => fn(1, { op: 'boo', to: 2 })).toThrowError(
new RegExp(errors.invalidCompareOperator('boo').message)
);
expect(() => fn(1, { op: 'boo' })).toThrowError(
new RegExp(errors.invalidCompareOperator('boo').message)
);
});
});

describe('to', () => {
it('sets the value that context is compared to', () => {
expect(fn(0, { to: 1 })).toBe(false);
});

it('if not provided, ne returns true while every other operator returns false', () => {
expect(fn(null, { op: 'ne' })).toBe(true);
expect(fn(0, { op: 'ne' })).toBe(true);
expect(fn(true, { op: 'lte' })).toBe(false);
expect(fn(1, { op: 'gte' })).toBe(false);
expect(fn('foo', { op: 'lt' })).toBe(false);
expect(fn(null, { op: 'gt' })).toBe(false);
expect(fn(null, { op: 'eq' })).toBe(false);
});
});
});

describe('same type comparisons', () => {
describe('null', () => {
it('returns true', () => {
expect(fn(null, { op: 'eq', to: null })).toBe(true);
expect(fn(null, { op: 'lte', to: null })).toBe(true);
expect(fn(null, { op: 'gte', to: null })).toBe(true);
});

it('returns false', () => {
expect(fn(null, { op: 'ne', to: null })).toBe(false);
expect(fn(null, { op: 'lt', to: null })).toBe(false);
expect(fn(null, { op: 'gt', to: null })).toBe(false);
});
});

describe('number', () => {
it('returns true', () => {
expect(fn(-2.34, { op: 'lt', to: 10 })).toBe(true);
expect(fn(2, { op: 'gte', to: 2 })).toBe(true);
});

it('returns false', () => {
expect(fn(2, { op: 'eq', to: 10 })).toBe(false);
expect(fn(10, { op: 'ne', to: 10 })).toBe(false);
expect(fn(1, { op: 'lte', to: -3 })).toBe(false);
expect(fn(2, { op: 'gt', to: 2 })).toBe(false);
});
});

describe('string', () => {
it('returns true', () => {
expect(fn('foo', { op: 'gte', to: 'foo' })).toBe(true);
expect(fn('foo', { op: 'lte', to: 'foo' })).toBe(true);
expect(fn('bar', { op: 'lt', to: 'foo' })).toBe(true);
});

it('returns false', () => {
expect(fn('foo', { op: 'eq', to: 'bar' })).toBe(false);
expect(fn('foo', { op: 'ne', to: 'foo' })).toBe(false);
expect(fn('foo', { op: 'gt', to: 'foo' })).toBe(false);
});
});

describe('boolean', () => {
it('returns true', () => {
expect(fn(true, { op: 'eq', to: true })).toBe(true);
expect(fn(false, { op: 'eq', to: false })).toBe(true);
expect(fn(true, { op: 'ne', to: false })).toBe(true);
expect(fn(false, { op: 'ne', to: true })).toBe(true);
});
it('returns false', () => {
expect(fn(true, { op: 'eq', to: false })).toBe(false);
expect(fn(false, { op: 'eq', to: true })).toBe(false);
expect(fn(true, { op: 'ne', to: true })).toBe(false);
expect(fn(false, { op: 'ne', to: false })).toBe(false);
});
});
});

describe('different type comparisons', () => {
it("returns true for 'ne' only", () => {
expect(fn(0, { op: 'ne', to: '0' })).toBe(true);
});

it('otherwise always returns false', () => {
expect(fn(0, { op: 'eq', to: '0' })).toBe(false);
expect(fn('foo', { op: 'lt', to: 10 })).toBe(false);
expect(fn('foo', { op: 'lte', to: true })).toBe(false);
expect(fn(0, { op: 'gte', to: null })).toBe(false);
expect(fn(0, { op: 'eq', to: false })).toBe(false);
expect(fn(true, { op: 'gte', to: null })).toBe(false);
});
});
});
Loading

0 comments on commit 69fdcc8

Please sign in to comment.