import { CLIENT_SETTINGS_SERVICE_MOCK } from '@core/mocks/client-settings.service.mock'; import { CURRENCY_SERVICE_MOCK } from '@core/mocks/currency.service.mock'; import { GCMockModule } from '@core/mocks/gc-module.mock'; import { BaseApplication } from '@core/typings/application.typing'; import { BaseApplicationForLogic, FormioAnswerValues, FormTypes } from '@features/configure-forms/form.typing'; import { FilterModalTypes } from '@yourcause/common'; import { Spec, TestCase } from '@yourcause/test-decorators'; import { DescribeAngularService } from '@yourcause/test-decorators/angular'; import { expect } from 'chai'; import moment from 'moment'; import { GlobalLogicGroupType, LogicBuilderService } from './logic-builder.service'; import { ConditionalLogicResultType, EvaluationType, GlobalLogicGroup, LogicColumn, LogicColumnDisplay, LogicCondition, NestedPropColumn, RelatedLogicValueCondition, ValueLogicCondition } from './logic-builder.typing'; @DescribeAngularService(LogicBuilderService, { imports: [ GCMockModule ], providers: [ CURRENCY_SERVICE_MOCK, CLIENT_SETTINGS_SERVICE_MOCK ] }) export class LogicBuilderServiceSpec implements Spec { numberKey = 'numberKey'; textKey = 'textKey'; picklistKey = 'picklistKey'; picklistMultiKey = 'picklistMultiKey'; currencyKey = 'currencyKey'; /** * numberKey equals 2 */ numberCondition: ValueLogicCondition> = { sourceColumn: ['referenceFields', this.numberKey] as NestedPropColumn, comparison: FilterModalTypes.equals, identifier: '', useAnd: true, value: '2' }; /** * designation is blank */ isBlankCondition: LogicCondition> = { sourceColumn: ['application', 'designation'] as NestedPropColumn, comparison: FilterModalTypes.isBlank, identifier: '', useAnd: true }; /** * textKey is not blank */ notBlankCondition: LogicCondition> = { sourceColumn: ['referenceFields', this.textKey] as NestedPropColumn, comparison: FilterModalTypes.notBlank, identifier: '', useAnd: true }; /** * Amount requested greater than 500 */ amountRequestedCondition: ValueLogicCondition> = { sourceColumn: ['application', 'amountRequested'] as NestedPropColumn, comparison: FilterModalTypes.greaterThan, identifier: '', useAnd: false, value: 500 }; /** * picklistKey equals 'Picklist val' */ picklistCondition: ValueLogicCondition> = { sourceColumn: ['referenceFields', this.picklistKey] as NestedPropColumn, comparison: FilterModalTypes.equals, identifier: '', useAnd: false, value: 'Picklist val' }; /** * picklistMultiKey is SC or MD */ picklistMultiCondition: LogicCondition> = { sourceColumn: ['referenceFields', this.picklistMultiKey] as NestedPropColumn, comparison: FilterModalTypes.multiValueIncludes, identifier: '', useAnd: true, value: ['SC', 'MD'] }; /** * Related Column condition */ relatedColumnCondition: RelatedLogicValueCondition, LogicColumn> = { sourceColumn: ['application', 'designation'] as NestedPropColumn, comparison: FilterModalTypes.greaterThan, identifier: '', useAnd: false, value: null, relatedColumn: ['referenceFields', this.textKey] as NestedPropColumn }; /** * A group that should fail by default (because of a blank picklistMultiKey) */ group1: GlobalLogicGroup = { conditions: [ this.numberCondition, this.isBlankCondition, this.picklistMultiCondition ], useAnd: true, identifier: '', evaluationType: EvaluationType.ConditionallyTrue }; /** * A group that should pass by default */ group2: GlobalLogicGroup = { conditions: [ this.amountRequestedCondition, this.picklistCondition, this.notBlankCondition ], useAnd: true, identifier: '', evaluationType: EvaluationType.ConditionallyTrue }; /** * numberKey: 2 * textkey: 'Some text' * picklistKey: 'Picklist val' * multiPicklistKey: undefined * amountRequested: 400 * designation: '' */ record: BaseApplicationForLogic = { tabs: [], referenceFields: { [this.numberKey]: 2, [this.textKey]: 'Some text', [this.picklistKey]: 'Picklist val', [this.currencyKey]: { currency: 'USD', amountForControl: 400, amountInDefaultCurrency: 499, amountEquivalent: 400 } }, application: { formType: FormTypes.REQUEST, applicationId: 1, applicationFormId: 2, formId: 3, revisionId: 4, amountRequested: 400, designation: '', careOf: '', programId: 5, reportFieldResponse: null, specialHandling: null, defaultSpecialHandling: null, referenceFields: {}, reviewerRecommendedFundingAmount: null } as BaseApplication, layoutComponents: null, reportFieldResponse: null }; picklistEqualsCondition = { sourceColumn: ['referenceFields', 'alienType'], comparison: 'eq', useAnd: false, identifier: '251c161db9e346948445443236a2180b8e3435d93f1241edad47ca24e81144e7', value: ['bleep'] }; picklistContainsCondition = { sourceColumn: ['referenceFields', 'alienType'], comparison: 'cn', useAnd: false, identifier: '251c161db9e346948445443236a2180b8e3435d93f1241edad47ca24e81144e7', value: 'a' }; picklistContainsOptionCondition = { sourceColumn: ['referenceFields', 'alienType'], comparison: 'cn', useAnd: false, identifier: '251c161db9e346948445443236a2180b8e3435d93f1241edad47ca24e81144e7', value: 'bleep' }; picklistIsBlankCondition = { sourceColumn: ['referenceFields', 'alienType'], comparison: 'ib', useAnd: false, identifier: '251c161db9e346948445443236a2180b8e3435d93f1241edad47ca24e81144e7' }; picklistEqualsObjectCondition = { sourceColumn: ['referenceFields', 'alienType'], comparison: 'eq', useAnd: false, identifier: '251c161db9e346948445443236a2180b8e3435d93f1241edad47ca24e81144e7', value: { bleep: true } }; constructedSentenceForPicklistOneOf = `Alien Type one of Bleep`; constructedSentenceForPicklistContains = `Alien Type contains a`; constructedSentenceForPicklistContainsOption = `Alien Type contains Bleep`; constructedSentenceForEvaluatingIsBlank = `Alien Type is blank`; @TestCase('should be able to get default conditional logic') getDefaultConditionalLogic (service: LogicBuilderService) { const defaultLogic = service.getDefaultConditionalLogic(); const expectedEvaluationType = EvaluationType.AlwaysTrue; expect(defaultLogic.evaluationType).to.be.equal(expectedEvaluationType); } @TestCase('should be able to get default conditional value logic') getDefaultConditionalValueLogic (service: LogicBuilderService) { const defaultLogic = service.getDefaultConditionalValueLogic(); const expectedEvaluationType = EvaluationType.ConditionallyTrue; expect(defaultLogic.evaluationType).to.be.equal(expectedEvaluationType); expect(defaultLogic).to.have.property('result'); } @TestCase('should be able to get default conditional value logic - checkbox') getDefaultConditionalValueLogicCheckbox (service: LogicBuilderService) { const defaultLogic = service.getDefaultConditionalValueLogic('checkbox'); const expectedEvaluationType = EvaluationType.ConditionallyTrue; expect(defaultLogic.evaluationType).to.be.equal(expectedEvaluationType); expect(defaultLogic.result).to.be.false; } @TestCase('should be able to evaluate conditional condition for amount requested greater than') evaluateConditionalConditionAmtRequestedGreaterThan (service: LogicBuilderService) { const result = service.evaluateConditionalCondition( { comparison: FilterModalTypes.greaterThan, sourceColumn: ['application', 'amountRequested'] as NestedPropColumn, useAnd: false, value: '1000', identifier: '' }, { tabs: null, referenceFields: null, application: { amountRequested: 500 } as BaseApplication, layoutComponents: null, reportFieldResponse: null } ); // Should not pass expect(result).to.be.false; } @TestCase('should be able to evaluate conditional condition for checkbox equals') evaluateConditionalConditionCheckbox (service: LogicBuilderService) { const result = service.evaluateConditionalCondition( { comparison: FilterModalTypes.equals, sourceColumn: ['referenceFields', 'checkYes'] as NestedPropColumn, useAnd: false, value: true, identifier: '' }, { tabs: null, referenceFields: { checkYes: true }, application: null, layoutComponents: null, reportFieldResponse: null } ); // Should pass expect(result).to.be.true; } @TestCase('should be able to evaluate conditional condition for one of') evaluateConditionalConditionOneOf (service: LogicBuilderService) { const result = service.evaluateConditionalCondition( { comparison: FilterModalTypes.equals, sourceColumn: ['referenceFields', 'someField'] as NestedPropColumn, useAnd: false, value: ['a', 'b'], identifier: '' }, { tabs: null, referenceFields: { someField: 'a' }, application: null, layoutComponents: null, reportFieldResponse: null } ); // Should pass expect(result).to.be.true; } @TestCase('should be able to evaluate conditional condition for one of (fail)') evaluateConditionalConditionNotOneOf (service: LogicBuilderService) { const result = service.evaluateConditionalCondition( { comparison: FilterModalTypes.equals, sourceColumn: ['referenceFields', 'someField'] as NestedPropColumn, useAnd: false, value: ['b', 'c'], identifier: '' }, { tabs: null, referenceFields: { someField: 'a' }, application: null, layoutComponents: null, reportFieldResponse: null } ); // Should pass expect(result).to.be.false; } @TestCase('should be able to evaluate conditional condition for picklist equals') evaluateConditionalConditionPicklistEquals (service: LogicBuilderService) { const result = service.evaluateConditionalCondition( { comparison: FilterModalTypes.equals, sourceColumn: ['referenceFields', 'dJCaseyStatesParent2'] as NestedPropColumn, useAnd: false, value: 'KY', identifier: '' }, { tabs: null, referenceFields: { dJCaseyStatesParent2: 'AL' }, application: null, layoutComponents: null, reportFieldResponse: null } ); // Should not pass expect(result).to.be.false; } @TestCase('should be able to evaluate conditional condition for multiValueIncludes') evaluateConditionalConditionMultiValueIncludes (service: LogicBuilderService) { const result = service.evaluateConditionalCondition( { comparison: FilterModalTypes.multiValueIncludes, sourceColumn: ['referenceFields', 'picklistMultipleRef'] as NestedPropColumn, useAnd: false, value: ['AL', 'AR'], identifier: '' }, { tabs: null, referenceFields: { picklistMultipleRef: ['MD', 'AR'] }, application: null, layoutComponents: null, reportFieldResponse: null } ); // Should pass expect(result).to.be.true; } @TestCase('should be able to evaluate conditional condition for contains') evaluateConditionalConditionForContains (service: LogicBuilderService) { const valueToCompare = 'some string'; const result = service.evaluateConditionalCondition( { comparison: FilterModalTypes.contains, sourceColumn: ['referenceFields', 'textKey'] as NestedPropColumn, useAnd: false, value: valueToCompare, identifier: '' }, { tabs: null, referenceFields: { textKey: `some text ${valueToCompare} more text` }, application: null, layoutComponents: null, reportFieldResponse: null } ); // Should pass expect(result).to.be.true; } @TestCase('should be able to evaluate conditional condition for starts with/ends with') evaluateConditionalConditionForStartsWithEndsWith (service: LogicBuilderService) { const valueToCompare = 'some string'; let condition: LogicCondition> = { comparison: FilterModalTypes.startsWith, sourceColumn: ['referenceFields', 'textKey'] as NestedPropColumn, useAnd: false, value: valueToCompare, identifier: '' }; const record: BaseApplicationForLogic = { tabs: null, referenceFields: { textKey: `some text ${valueToCompare}` }, application: null, layoutComponents: null, reportFieldResponse: null }; let result = service.evaluateConditionalCondition( condition, record ); // Should not pass expect(result).to.be.false; condition = { ...condition, comparison: FilterModalTypes.endsWith }; result = service.evaluateConditionalCondition( condition, record ); // Should pass expect(result).to.be.true; } @TestCase('should be able to evaluate conditional condition for is blank') evaluateConditionalConditionForIsBlankNotBlank (service: LogicBuilderService) { let condition: LogicCondition> = { comparison: FilterModalTypes.isBlank, sourceColumn: ['referenceFields', 'textKey'] as NestedPropColumn, useAnd: false, value: null } as any; const record: BaseApplicationForLogic = { tabs: null, referenceFields: { textKey: '' }, application: null, layoutComponents: null, reportFieldResponse: null }; let result = service.evaluateConditionalCondition( condition, record ); // Should pass expect(result).to.be.true; condition = { ...condition, comparison: FilterModalTypes.notBlank }; result = service.evaluateConditionalCondition( condition, record ); // Should fail expect(result).to.be.false; } @TestCase('should be able to extract conditions from group') extractConditionsFromGroup (service: LogicBuilderService) { const extracted = service.extractConditionsFromGroup(this.group1); expect(extracted.length).to.be.equal(this.group1.conditions.length); const hasNumberColumn = extracted.some((condition) => { return condition.sourceColumn[1] === this.numberKey; }); expect(hasNumberColumn).to.be.true; const hasIsBlankCondition = extracted.some((condition) => { return condition.comparison === 'ib'; }); expect(hasIsBlankCondition).to.be.true; const hasPicklistMultiCondition = extracted.some((condition) => { return condition.comparison === 'in'; }); expect(hasPicklistMultiCondition).to.be.true; } @TestCase('should be able to run conditional logic') runConditionalLogic (service: LogicBuilderService) { let result = service.runConditionalLogic( [ [['tabs', 0] as NestedPropColumn, this.group1] ], this.record ); let response = service.getCurrentLogicValueOfColumn( ['tabs', 0] as NestedPropColumn, result ); // Should not show because picklistMulti condition not met expect(response).to.be.false; result = service.runConditionalLogic( [ [['tabs', 0] as NestedPropColumn, this.group1] ], { ...this.record, referenceFields: { ...this.record.referenceFields, [this.picklistMultiKey]: ['SC'] } } ); response = service.getCurrentLogicValueOfColumn( ['tabs', 0] as NestedPropColumn, result ); // All conditions pass expect(response).to.be.true; } @TestCase('should be able to run value logic') runValueLogic (service: LogicBuilderService) { const column = ['tabs', 0] as NestedPropColumn; const expectedResult = 'should be this'; // make sure it fails through group 1 and returns the middle value (without going to the third group) const result = service.runValueLogic( [[ column, [ { ...this.group1, result: 'should not be this', resultType: ConditionalLogicResultType.STATIC_VALUE }, { ...this.group2, result: expectedResult, resultType: ConditionalLogicResultType.STATIC_VALUE }, { ...this.group2, result: 'should not be this', resultType: ConditionalLogicResultType.STATIC_VALUE } ] ]], this.record ); const response = service.getCurrentLogicValueOfColumn( column, result ); // All conditions pass expect(response).to.equal(expectedResult); } @TestCase('should be able to evaluate conditional group') evaluateConditionalGroup (service: LogicBuilderService) { let passes = service.evaluateConditionalGroup( this.group2, this.record ); // Should pass because group uses ORs and it meets 2 of 3 conditions expect(passes).to.be.true; passes = service.evaluateConditionalGroup( this.group2, { ...this.record, referenceFields: { [this.textKey]: '', [this.picklistKey]: 'other value' } } ); // Should fail because all conditions fail expect(passes).to.be.false; } @TestCase('should be able to get has valid result') hasValidResult (service: LogicBuilderService) { let isValid = service.hasValidResult(''); expect(isValid).to.be.false; isValid = service.hasValidResult(null); expect(isValid).to.be.false; isValid = service.hasValidResult(undefined); expect(isValid).to.be.false; isValid = service.hasValidResult(1); expect(isValid).to.be.true; } @TestCase('should be able to format text') formatText (service: LogicBuilderService) { let value: string|string[] = ['text1', 'text2']; let result = service.formatText(value); let expected = 'text1, text2'; expect(result).to.be.equal(expected); value = 'text1'; result = service.formatText(value); expected = 'text1'; expect(result).to.be.equal(expected); } @TestCase('should be able to format number') formatNumber (service: LogicBuilderService) { let value: number|number[] = [1, 2]; let result = service.formatNumber(value); let expected = '1, 2'; expect(result).to.be.equal(expected); value = 1; result = service.formatNumber(value); expected = '1'; expect(result).to.be.equal(expected); } @TestCase('should be able to format currency') formatCurrency (service: LogicBuilderService) { const result = service.formatCurrency({ currency: 'USD', amountInDefaultCurrency: 500.27, amountEquivalent: 500.27, amountForControl: 500.27 }); const expected = '$500.27'; expect(result).to.be.equal(expected); } @TestCase('should be able to format date') formatDate (service: LogicBuilderService) { let result = service.formatDate('01/01/2021'); let expected = 'Jan 1, 2021'; expect(result).to.be.equal(expected); result = service.formatDate(['01/01/2021', '01/01/2022']); expected = 'Jan 1, 2021 - Jan 1, 2022'; expect(result).to.be.equal(expected); } @TestCase('should be able to format checkbox') formatCheckbox (service: LogicBuilderService) { let value: string|boolean = 'true'; let result = service.formatCheckbox(value); let expected = 'true'; expect(result).to.be.equal(expected); value = false; result = service.formatCheckbox(value); expected = 'false'; expect(result).to.be.equal(expected); } @TestCase('should be able to format value for object') formatValueForObject (service: LogicBuilderService) { const formatted = service.formatValueForObject( { blue: true, red: true }, 'select', [{ label: 'Blue', value: 'blue' }, { label: 'Red', value: 'red' }] ); const expected = 'Blue, Red'; expect(formatted).to.be.equal(expected); } @TestCase('should be able to format value for array') formatValueForArray (service: LogicBuilderService) { const formatted = service.formatValueForArray( ['blue', 'red'], 'select', [{ label: 'Blue', value: 'blue' }, { label: 'Red', value: 'red' }] ); const expected = 'Blue, Red'; expect(formatted).to.be.equal(expected); } @TestCase('should be able to get display value from options') getDisplayValueFromOptions (service: LogicBuilderService) { const value = service.getDisplayValueFromOptions( 'blue', [{ label: 'Blue', value: 'blue' }, { label: 'Red', value: 'red' }] ); expect(value).to.be.equal('Blue'); } @TestCase('should be able to check isEmpty for array') isEmptyArray (service: LogicBuilderService) { let val: number[] = []; let isEmpty = service.isEmpty(val); expect(isEmpty).to.be.true; val = [1]; isEmpty = service.isEmpty(val); expect(isEmpty).to.be.false; } @TestCase('should be able to check isEmpty for object') isEmptyObj (service: LogicBuilderService) { let val = {}; let isEmpty = service.isEmpty(val); expect(isEmpty).to.be.true; val = { 1: true }; isEmpty = service.isEmpty(val); expect(isEmpty).to.be.false; } @TestCase('should be able to check isEmpty for non object/array') isEmptyOther (service: LogicBuilderService) { let val = null; let isEmpty = service.isEmpty(val); expect(isEmpty).to.be.true; val = 0; isEmpty = service.isEmpty(val); expect(isEmpty).to.be.false; } @TestCase('should be able to get result type options') getResultTypeOptions (service: LogicBuilderService) { const options = service.getResultTypeOptions(); const hasOtherColumn = options.some((opt) => { return opt.value === ConditionalLogicResultType.OTHER_COLUMN; }); const hasStatic = options.some((opt) => { return opt.value === ConditionalLogicResultType.STATIC_VALUE; }); expect(options.length).to.be.equal(2); expect(hasOtherColumn).to.be.true; expect(hasStatic).to.be.true; } @TestCase('should be able to get comparison value - static value') getComparisonValue (service: LogicBuilderService) { const val = service.getComparisonValue(this.numberCondition, this.record); expect(val).to.be.equal(this.numberCondition.value); } @TestCase('should be able to get comparison value - related column') getComparisonValueRelatedColumn (service: LogicBuilderService) { const val = service.getComparisonValue(this.relatedColumnCondition, this.record); expect(val).to.be.equal(this.record.referenceFields[this.textKey]); } @TestCase('should be able to get should show other column selector - false') shouldShowOtherColumnSelectorFalse (service: LogicBuilderService) { const options = [{ label: 'option', value: 'key' }]; let shouldShow = service.shouldShowOtherColumnSelector( options, FilterModalTypes.isBlank ); // should not show because is blank is not valid for other columns expect(shouldShow).to.be.false; shouldShow = service.shouldShowOtherColumnSelector( options, FilterModalTypes.Yesterday ); // should not show because yesterday is not valid for other columns expect(shouldShow).to.be.false; shouldShow = service.shouldShowOtherColumnSelector( [], FilterModalTypes.equals ); // should not show bc there are no options expect(shouldShow).to.be.false; } @TestCase('should be able to get should show other column selector - true') shouldShowOtherColumnSelectorTrue (service: LogicBuilderService) { const options = [{ label: 'option', value: 'key' }]; let shouldShow = service.shouldShowOtherColumnSelector( options, FilterModalTypes.greaterThan ); // should show because there are options and valid filter type expect(shouldShow).to.be.true; shouldShow = service.shouldShowOtherColumnSelector( options, FilterModalTypes.multiValueIncludes ); // should show because there are options and valid filter type expect(shouldShow).to.be.true; } @TestCase('should be able to display sentence with picklist - one of') testDisplaySentenceWithPicklistOneOf (service: LogicBuilderService) { const constructSummarySentenceForPicklistPayload = { availableColumns: [{ column: [ 'referenceFields', 'alienType' ], filterOptions: [ {label: 'Blorp', value: 'blorp'}, {label: 'Bleep', value: 'bleep'} ], label: 'Alien Type', otherColumnOptions: [], type: 'multiListFuzzyText' }] as LogicColumnDisplay[], depth: 0, logic: { conditions: [ this.picklistEqualsCondition ], evaluationType: 0, identifier: '9b72950a55094a1e8fced6d8aa3f0a8c6400b833946640eda248d1cb1ed7bd93', result: 'nahh', resultType: 0, useAnd: false } as GlobalLogicGroupType }; const sentence = service.constructSummarySentence( constructSummarySentenceForPicklistPayload.logic, constructSummarySentenceForPicklistPayload.availableColumns, constructSummarySentenceForPicklistPayload.depth ); expect(sentence).to.equal(this.constructedSentenceForPicklistOneOf); } @TestCase('should be able to display sentence with picklist - contains') testDisplaySentenceWithPicklistContains (service: LogicBuilderService) { const constructSummarySentenceForPicklistPayload = { availableColumns: [{ column: [ 'referenceFields', 'alienType' ], filterOptions: [ {label: 'Blorp', value: 'blorp'}, {label: 'Bleep', value: 'bleep'} ], label: 'Alien Type', otherColumnOptions: [], type: 'multiListFuzzyText' }] as LogicColumnDisplay[], depth: 0, logic: { conditions: [ this.picklistContainsCondition ], evaluationType: 0, identifier: '9b72950a55094a1e8fced6d8aa3f0a8c6400b833946640eda248d1cb1ed7bd93', result: 'nahh', resultType: 0, useAnd: false } as GlobalLogicGroupType }; const sentence = service.constructSummarySentence( constructSummarySentenceForPicklistPayload.logic, constructSummarySentenceForPicklistPayload.availableColumns, constructSummarySentenceForPicklistPayload.depth ); expect(sentence).to.equal(this.constructedSentenceForPicklistContains); } @TestCase('should be able to display sentence with evaluation of isBlank') testDisplaySentenceWithEvaluationOfOtherComp (service: LogicBuilderService) { const constructSummarySentenceForPicklistPayload = { availableColumns: [{ column: [ 'referenceFields', 'alienType' ], filterOptions: [ {label: 'Blorp', value: 'blorp'}, {label: 'Bleep', value: 'bleep'} ], label: 'Alien Type', otherColumnOptions: [], type: 'multiListFuzzyText' }] as LogicColumnDisplay[], depth: 0, logic: { conditions: [ this.picklistIsBlankCondition ], evaluationType: 0, identifier: '9b72950a55094a1e8fced6d8aa3f0a8c6400b833946640eda248d1cb1ed7bd93', result: 'nahh', resultType: 0, useAnd: false } as GlobalLogicGroupType }; const sentence = service.constructSummarySentence( constructSummarySentenceForPicklistPayload.logic, constructSummarySentenceForPicklistPayload.availableColumns, constructSummarySentenceForPicklistPayload.depth ); expect(sentence).to.equal(this.constructedSentenceForEvaluatingIsBlank); } @TestCase('should be able to display sentence with single contains option') testDisplaySentenceWithSinceContainsOption (service: LogicBuilderService) { const constructSummarySentenceForPicklistPayload = { availableColumns: [{ column: [ 'referenceFields', 'alienType' ], filterOptions: [ {label: 'Blorp', value: 'blorp'}, {label: 'Bleep', value: 'bleep'} ], label: 'Alien Type', otherColumnOptions: [], type: 'multiListFuzzyText' }] as LogicColumnDisplay[], depth: 0, logic: { conditions: [ this.picklistContainsOptionCondition ], evaluationType: 0, identifier: '9b72950a55094a1e8fced6d8aa3f0a8c6400b833946640eda248d1cb1ed7bd93', result: 'nahh', resultType: 0, useAnd: false } as GlobalLogicGroupType }; const sentence = service.constructSummarySentence( constructSummarySentenceForPicklistPayload.logic, constructSummarySentenceForPicklistPayload.availableColumns, constructSummarySentenceForPicklistPayload.depth ); expect(sentence).to.equal(this.constructedSentenceForPicklistContainsOption); } @TestCase('should be able to display sentence contains object') testDisplaySentenceContainsObject (service: LogicBuilderService) { const constructSummarySentenceForPicklistPayload = { availableColumns: [{ column: [ 'referenceFields', 'alienType' ], filterOptions: [ {label: 'Blorp', value: 'blorp'}, {label: 'Bleep', value: 'bleep'} ], label: 'Alien Type', otherColumnOptions: [], type: 'multiListFuzzyText' }] as LogicColumnDisplay[], depth: 0, logic: { conditions: [ this.picklistEqualsObjectCondition ], evaluationType: 0, identifier: '9b72950a55094a1e8fced6d8aa3f0a8c6400b833946640eda248d1cb1ed7bd93', result: 'nahh', resultType: 0, useAnd: false } as GlobalLogicGroupType }; const sentence = service.constructSummarySentence( constructSummarySentenceForPicklistPayload.logic, constructSummarySentenceForPicklistPayload.availableColumns, constructSummarySentenceForPicklistPayload.depth ); expect(sentence).to.equal(this.constructedSentenceForPicklistOneOf); } @TestCase('should be able to get record value') getRecordValue (service: LogicBuilderService) { let recordValue = service.getRecordValue( this.record, ['application', 'designation'] as NestedPropColumn ); expect(recordValue).to.be.equal(this.record.application.designation); recordValue = service.getRecordValue( this.record, ['referenceFields', this.currencyKey] as NestedPropColumn ); expect(recordValue).to.be.equal(this.record.referenceFields[this.currencyKey].amountForControl); } @TestCase('should be able to get is currency type') isCurrencyType (service: LogicBuilderService) { let isCurrencyType = service.isCurrencyType(''); expect(isCurrencyType).to.be.false; isCurrencyType = service.isCurrencyType({}); expect(isCurrencyType).to.be.false; isCurrencyType = service.isCurrencyType([]); expect(isCurrencyType).to.be.false; isCurrencyType = service.isCurrencyType(2); expect(isCurrencyType).to.be.false; isCurrencyType = service.isCurrencyType({ currency: 'USD', amountForControl: 599 }); expect(isCurrencyType).to.be.true; } @TestCase('should be able to get numeric value - number') getNumericValueNumber (service: LogicBuilderService) { const value = '135321532'; const numeric = service.getNumericValue(value); expect(numeric).to.be.equal(+value); } @TestCase('should be able to get numeric value - date') getNumericValueDate (service: LogicBuilderService) { // Supports moment and ISO strings let value: any = moment('05/27/2022'); let numeric = service.getNumericValue(value); expect(numeric).to.be.equal(+value); value = '2022-07-01T17:37:34Z'; numeric = service.getNumericValue(value); expect(numeric).to.be.equal(+moment(value)); } @TestCase('should be able to get numeric value - other') getNumericValueOther (service: LogicBuilderService) { const value = ['14-25']; const numeric = service.getNumericValue(value); const noNumeric = !numeric; expect(noNumeric).to.be.true; } }