mirror of
https://github.com/nasa/openmct.git
synced 2025-05-29 05:34:18 +00:00
Adds unit tests for isOneOf and isNotOneOf
This commit is contained in:
parent
a681d67e05
commit
39d7dc8372
@ -1,3 +1,5 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
export const OPERATIONS = [
|
export const OPERATIONS = [
|
||||||
{
|
{
|
||||||
name: 'equalTo',
|
name: 'equalTo',
|
||||||
@ -207,7 +209,7 @@ export const OPERATIONS = [
|
|||||||
name: 'valueIs',
|
name: 'valueIs',
|
||||||
operation: function (input) {
|
operation: function (input) {
|
||||||
const values = input[1].split(',');
|
const values = input[1].split(',');
|
||||||
return values.find((value) => input[0].toString() === value.toString().replace(' ', ''));
|
return values.find((value) => input[0].toString() === _.trim(value.toString()));
|
||||||
},
|
},
|
||||||
text: 'is one of',
|
text: 'is one of',
|
||||||
appliesTo: ["string", "number"],
|
appliesTo: ["string", "number"],
|
||||||
@ -220,7 +222,8 @@ export const OPERATIONS = [
|
|||||||
name: 'valueIsNot',
|
name: 'valueIsNot',
|
||||||
operation: function (input) {
|
operation: function (input) {
|
||||||
const values = input[1].split(',');
|
const values = input[1].split(',');
|
||||||
return values.find((value) => input[0].toString() !== value.toString().replace(' ', ''));
|
const found = values.find((value) => input[0].toString() === _.trim(value.toString()));
|
||||||
|
return !found;
|
||||||
},
|
},
|
||||||
text: 'is not one of',
|
text: 'is not one of',
|
||||||
appliesTo: ["string", "number"],
|
appliesTo: ["string", "number"],
|
||||||
|
68
src/plugins/condition/utils/operationsSpec.js
Normal file
68
src/plugins/condition/utils/operationsSpec.js
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT, Copyright (c) 2014-2020, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT is licensed 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.
|
||||||
|
*
|
||||||
|
* Open MCT includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
import { OPERATIONS } from "./operations";
|
||||||
|
let isOneOfOperation = OPERATIONS.find((operation) => operation.name === 'valueIs');
|
||||||
|
let isNotOneOfOperation = OPERATIONS.find((operation) => operation.name === 'valueIsNot');
|
||||||
|
|
||||||
|
describe('Is one of and is not one of operations', function () {
|
||||||
|
|
||||||
|
it('should evaluate isOneOf to true for number inputs', () => {
|
||||||
|
const inputs = [45, "5,6,45,8"];
|
||||||
|
expect(!!isOneOfOperation.operation(inputs)).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should evaluate isOneOf to true for string inputs', () => {
|
||||||
|
const inputs = ["45", " 45, 645, 4,8 "];
|
||||||
|
expect(!!isOneOfOperation.operation(inputs)).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should evaluate isNotOneOf to true for number inputs', () => {
|
||||||
|
const inputs = [45, "5,6,4,8"];
|
||||||
|
expect(!!isNotOneOfOperation.operation(inputs)).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should evaluate isNotOneOf to true for string inputs', () => {
|
||||||
|
const inputs = ["45", " 5,645, 4,8 "];
|
||||||
|
expect(!!isNotOneOfOperation.operation(inputs)).toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should evaluate isOneOf to false for number inputs', () => {
|
||||||
|
const inputs = [4, "5, 6, 7, 8"];
|
||||||
|
expect(!!isOneOfOperation.operation(inputs)).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should evaluate isOneOf to false for string inputs', () => {
|
||||||
|
const inputs = ["4", "5,645 ,7,8"];
|
||||||
|
expect(!!isOneOfOperation.operation(inputs)).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should evaluate isNotOneOf to false for number inputs', () => {
|
||||||
|
const inputs = [4, "5,4, 7,8"];
|
||||||
|
expect(!!isNotOneOfOperation.operation(inputs)).toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should evaluate isNotOneOf to false for string inputs', () => {
|
||||||
|
const inputs = ["4", "5,46,4,8"];
|
||||||
|
expect(!!isNotOneOfOperation.operation(inputs)).toBeFalse();
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user