Skip to content

Commit

Permalink
chore(NA): move canvas plugin tests out of __tests__ folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic committed Jan 6, 2021
1 parent 31c667a commit 8ced490
Show file tree
Hide file tree
Showing 91 changed files with 307 additions and 315 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 @@ -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 '../../../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 '../../../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 '../../../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 '../../../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 '../../../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 '../../../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 '../../../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 '../../../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 '../../../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 '../../../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);
});
});
});
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 '../../../helpers/function_wrapper';
import { elasticLogo } from '../../lib/elastic_logo';
import { getFunctionErrors } from '../../../i18n';
import { containerStyle } from './containerStyle';
Expand Down
Loading

0 comments on commit 8ced490

Please sign in to comment.