import { Injectable } from '@angular/core'; import { GCMockModule } from '@core/mocks/gc-module.mock'; import { ClientSettings, CurrencySetting } from '@core/typings/api/admin-client.typing'; import { ReferenceFieldAPI } from '@core/typings/api/reference-fields.typing'; import { AdHocReportingUI } from '@core/typings/ui/ad-hoc-reporting.typing'; import { ReferenceFieldsUI } from '@core/typings/ui/reference-fields.typing'; import { FormAudience, FormDefinitionComponent, FormDefinitionForUi, FormioChanges } from '@features/configure-forms/form.typing'; import { CustomDataTable, PicklistDataType } from '@features/custom-data-tables/custom-data-tables.typing'; import { AdHocReportingDefinitions } from '@features/reporting/services/ad-hoc-reporting-definitions.service'; import { PaginationOptions, SimpleNumberMap, YcFile } from '@yourcause/common'; import { CurrencyValue } from '@yourcause/common/masking'; import { AfterEach, BeforeEach, Spec, TestCase } from '@yourcause/test-decorators'; import { DescribeAngularService } from '@yourcause/test-decorators/angular'; import { expect, spy } from 'chai'; import { ReferenceFieldsService } from './reference-fields.service'; @Injectable({ providedIn: 'root' }) @DescribeAngularService(ReferenceFieldsService, { imports: [ GCMockModule ] }) export class ReferenceFieldsServiceSpec implements Spec { textFieldId = 1; textAreaId = 2; checkboxId = 3; dataTableId = 4; numberId = 5; radioId = 6; dataTableId2 = 7; selectBoxesId = 8; fileUploadId = 9; aggregateId = 10; tableId = 11; standardProductFieldId = 12; parentFieldId = 13; subsetId = 14; checkboxKey = 'checkbox'; radioKey = 'radio'; numberKey = 'number'; dataTable1Key = 'customDataTable'; dataTable2Key = 'customDataTable2'; fileUploadKey = 'fileUploadKey'; textFieldKey = 'textfield'; encryptedFieldKey = 'encrypted'; maskedFieldKey = 'masked'; textAreaKey = 'textarea'; aggregateKey = 'aggregate'; selectBoxesKey = 'selectBoxesKey'; currencyKey = 'currency'; tableKey = 'table'; standardFieldKey = 'standardTextField'; singleResponseManagerFieldKey = 'singleResponseManagerFieldKey'; subsetKey = 'subsetKey'; cdtId1 = 1; cdtId2 = 2; cdtId3 = 3; cdtGuid1 = 'guid1'; cdtGuid2 = 'guid2'; cdtGuid3 = 'guid3'; defaultCategoryId = 1; tableComponentMap: SimpleNumberMap = { 3: [{ referenceFieldKey: 'number', key: 'number', type: 'referenceFields-number', label: 'Number' }] }; formComponentMap: SimpleNumberMap = { 2: [{ referenceFieldKey: null, key: this.textFieldKey, type: 'referenceFields-textfield', label: 'Text field' }] }; numberField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.numberId, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Number', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Number, key: this.numberKey, supportsMultiple: false, categoryId: 3, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; radioButtonField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.radioId, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Radio', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Radio, key: this.radioKey, supportsMultiple: false, categoryId: 2, formAudience: FormAudience.MANAGER, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; aggregateField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: ReferenceFieldAPI.ReferenceFieldAggregateType.Sum, referenceFieldId: this.aggregateId, parentReferenceFieldId: this.numberId, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Aggregation field', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Aggregate, key: this.aggregateKey, supportsMultiple: false, categoryId: this.defaultCategoryId, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: true, aggregateTableReferenceFieldId: this.tableId, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; textField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.textFieldId, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Text field', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.TextField, key: this.textFieldKey, supportsMultiple: true, categoryId: this.defaultCategoryId, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; childField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.dataTableId2, parentReferenceFieldId: this.parentFieldId, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: this.cdtGuid1, name: 'Child custom data table', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable, key: this.dataTable2Key, supportsMultiple: true, categoryId: this.defaultCategoryId, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; parentField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.parentFieldId, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Parent picklist', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable, key: 'parentFieldKey', supportsMultiple: false, categoryId: this.defaultCategoryId, formAudience: FormAudience.MANAGER, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; standardProductTextField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { ...this.textField, referenceFieldId: this.standardProductFieldId, key: this.standardFieldKey, isStandardProductField: true }; subsetTableId = 456; subsetFieldPercent: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: true, aggregateType: null, referenceFieldId: this.subsetId, parentReferenceFieldId: null, formCount: 1, usedOnReports: true, createdBy: '', createDate: '', updateDate: '', updatedBy: '', customDataTableGuid: '', name: 'Subset field - percent', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Subset, key: this.subsetKey, supportsMultiple: false, categoryId: 2, formAudience: FormAudience.MANAGER, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: this.subsetTableId, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: ReferenceFieldAPI.DataSetCollectionType.Percent }; dataPointManager: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: true, aggregateType: null, referenceFieldId: 123456, parentReferenceFieldId: null, formCount: 1, usedOnReports: true, createdBy: '', createDate: '', updateDate: '', updatedBy: '', customDataTableGuid: '', name: 'data point field - manager', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.DataPoint, key: 'dataPointManager', supportsMultiple: false, categoryId: 2, formAudience: FormAudience.MANAGER, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: this.subsetTableId, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; fileUpload: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.fileUploadId, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'File Upload', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.FileUpload, key: this.fileUploadKey, supportsMultiple: false, categoryId: 2, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; checkboxField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.checkboxId, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Checkbox', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Checkbox, key: this.checkboxKey, supportsMultiple: false, categoryId: this.defaultCategoryId, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; textArea: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.textAreaId, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Text area', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.TextArea, key: this.textAreaKey, supportsMultiple: false, categoryId: this.defaultCategoryId, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: true, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; currencyField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: 1355, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: null, name: 'Currency', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Currency, key: this.currencyKey, supportsMultiple: false, categoryId: 2, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; allReferenceFields: ReferenceFieldAPI.ReferenceFieldDisplayModel[] = [ this.textField, this.textArea, this.checkboxField, { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.dataTableId, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: this.cdtGuid2, name: 'Custom data table', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable, key: this.dataTable1Key, supportsMultiple: true, categoryId: this.defaultCategoryId, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }, { ...this.parentField }, { ...this.childField }, { ...this.numberField }, { ...this.radioButtonField }, { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.selectBoxesId, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: this.cdtGuid2, name: 'Selectboxes', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.SelectBoxes, key: this.selectBoxesKey, supportsMultiple: false, categoryId: 2, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }, this.currencyField, this.fileUpload, { isEncrypted: true, isMasked: false, aggregateType: null, referenceFieldId: null, parentReferenceFieldId: null, formCount: 1, usedOnReports: false, createdBy: '', createDate: '', updateDate: '', updatedBy: '', customDataTableGuid: '', name: 'Encrypted Text Field', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.TextField, key: this.encryptedFieldKey, supportsMultiple: false, categoryId: 2, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }, { isEncrypted: false, isMasked: true, aggregateType: null, referenceFieldId: null, parentReferenceFieldId: null, formCount: 1, usedOnReports: false, createdBy: '', createDate: '', updateDate: '', updatedBy: '', customDataTableGuid: '', name: 'Masked Text Field', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.TextField, key: this.maskedFieldKey, supportsMultiple: false, categoryId: 2, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }, { ...this.aggregateField }, { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.tableId, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Table field', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Table, key: this.tableKey, supportsMultiple: false, categoryId: this.defaultCategoryId, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }, { isEncrypted: false, isMasked: true, aggregateType: null, referenceFieldId: 23523, parentReferenceFieldId: null, formCount: 1, usedOnReports: false, createdBy: '', createDate: '', updateDate: '', updatedBy: '', customDataTableGuid: '', name: 'Single Response Manager Text Field', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.TextField, key: this.singleResponseManagerFieldKey, supportsMultiple: false, categoryId: 2, formAudience: FormAudience.MANAGER, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }, { ...this.subsetFieldPercent }, { isEncrypted: false, isMasked: true, aggregateType: null, referenceFieldId: 1234, parentReferenceFieldId: null, formCount: 1, usedOnReports: true, createdBy: '', createDate: '', updateDate: '', updatedBy: '', customDataTableGuid: '', name: 'data point field - applicant', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.DataPoint, key: 'dataPointApplicant', supportsMultiple: false, categoryId: 2, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }, { ...this.dataPointManager }, { ...this.standardProductTextField }]; numberFieldValue = 123; subsetTableResponseRows: ReferenceFieldsUI.TableResponseRowForUi[] = [ { rowId: 1, columns: [ { referenceFieldId: this.numberId, referenceFieldKey: this.numberKey, value: this.numberFieldValue, dateValue: '', currencyValue: '', numericValue: null, file: null, files: [], applicationFormId: 1, applicationId: 2 }, { referenceFieldId: this.textFieldId, referenceFieldKey: this.textFieldKey, value: 1, dateValue: '', currencyValue: '', numericValue: null, file: null, files: [], applicationFormId: 1, applicationId: 2 }, { referenceFieldId: this.checkboxId, referenceFieldKey: this.checkboxKey, value: 2, dateValue: '', currencyValue: '', numericValue: null, file: null, files: [], applicationFormId: 1, applicationId: 2 } ] } ]; responses: ReferenceFieldsUI.RefResponseMap = { number: '2', checkbox: 'true', [this.dataTable1Key]: '2', textarea: 'Some text', textfield: 'Some more text', [this.selectBoxesKey]: ['2', '4'] }; responsesForAdapting: ReferenceFieldsUI.RefResponseMapForAdapting = { number: { value: '2', referenceFieldKey: 'number', referenceFieldId: this.numberId, numericValue: 2, dateValue: '', currencyValue: null, file: null, files: [], applicationFormId: 1, applicationId: 2 }, checkbox: { value: 'true', referenceFieldKey: this.checkboxKey, referenceFieldId: this.checkboxId, numericValue: null, dateValue: '', currencyValue: null, file: null, files: [], applicationFormId: 1, applicationId: 2 }, customDataTable: { value: '24', referenceFieldKey: this.dataTable1Key, referenceFieldId: this.cdtId1, numericValue: null, dateValue: '', currencyValue: null, file: null, files: [], applicationFormId: 1, applicationId: 2 }, textarea: { value: 'Some text', referenceFieldKey: 'textarea', referenceFieldId: this.textAreaId, numericValue: null, dateValue: '', currencyValue: null, file: null, files: [], applicationFormId: 1, applicationId: 2 }, textfield: { value: 'Some more text', referenceFieldKey: 'textfield', referenceFieldId: this.textFieldId, numericValue: null, dateValue: '', currencyValue: null, file: null, files: [], applicationFormId: 1, applicationId: 2 }, selectBoxesKey: { value: '2,4', referenceFieldKey: this.selectBoxesKey, referenceFieldId: this.selectBoxesId, numericValue: null, dateValue: '', currencyValue: null, file: null, files: [], applicationFormId: 1, applicationId: 2 } }; categories: ReferenceFieldAPI.Category[] = [{ id: 1, name: 'Category 1', formFieldCount: 4, createdBy: 'Lori Smith', createdDate: new Date().toDateString(), updatedBy: 'Lori Smith', updatedDate: new Date().toDateString(), impersonatedBy: '', createImpersonatedBy: '' }, { id: 2, name: 'Category 2', formFieldCount: 4, createdBy: 'Lori Smith', createdDate: new Date().toDateString(), updatedBy: 'Lori Smith', updatedDate: new Date().toDateString(), impersonatedBy: '', createImpersonatedBy: '' }, { id: 3, name: 'Category 3', formFieldCount: 4, createdBy: 'Lori Smith', createdDate: new Date().toDateString(), updatedBy: 'Lori Smith', updatedDate: new Date().toDateString(), impersonatedBy: '', createImpersonatedBy: '' }]; appResponsesForMerge: ReferenceFieldAPI.ApplicationResponse[] = [{ applicationId: 86913, referenceField1Response: '1', referenceField2Response: null }, { applicationId: 86914, referenceField1Response: '2', referenceField2Response: null }, { applicationId: 86949, referenceField1Response: '3', referenceField2Response: null }, { applicationId: 87039, referenceField1Response: null, referenceField2Response: '4' }, { applicationId: 87040, referenceField1Response: null, referenceField2Response: '5' }]; applicantPicklistType: ReferenceFieldsUI.TypeForFormio = { type: ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable, name: 'Picklist', formAudience: FormAudience.APPLICANT }; customDataTables: CustomDataTable[] = [{ id: this.cdtId1, name: 'Parent Table', guid: this.cdtGuid1, createdDate: '', updatedDate: '', createdBy: '', updatedBy: '', isSystem: false, hasOptions: true, defaultLanguageId: '', dataType: PicklistDataType.Text, parentPicklistId: null }, { id: this.cdtId2, name: 'Child Table', guid: this.cdtGuid2, createdDate: '', updatedDate: '', createdBy: '', updatedBy: '', isSystem: false, hasOptions: true, dataType: PicklistDataType.Text, defaultLanguageId: '', parentPicklistId: this.cdtId1 }, { id: this.cdtId3, name: 'Standalone Table', guid: this.cdtGuid3, createdDate: '', updatedDate: '', createdBy: '', dataType: PicklistDataType.Text, updatedBy: '', isSystem: false, hasOptions: true, defaultLanguageId: '', parentPicklistId: null }]; numberTableFieldForUi: ReferenceFieldsUI.TableFieldForUi = { referenceFieldId: this.numberId, referenceFieldName: 'Number', label: 'Column Label', isRequired: true, showInTable: true, columnOrder: 0, aggregateColumnReferenceFieldId: null, summarizeData: true, summarizeLabel: 'Total', referenceField: this.allReferenceFields.find((field) => { return field.referenceFieldId === this.numberId; }) }; tableFieldDefinitions = [{ referenceFieldId: this.numberId, referenceFieldName: '', label: 'Number field', isRequired: true, showInTable: true, columnOrder: 0, aggregateColumnReferenceFieldId: this.aggregateId }, { referenceFieldId: this.textFieldId, referenceFieldName: '', label: 'Text field', isRequired: true, showInTable: true, columnOrder: 0, aggregateColumnReferenceFieldId: null }, { referenceFieldId: this.checkboxId, referenceFieldName: '', label: 'Checkbox field', isRequired: true, showInTable: false, columnOrder: 0, aggregateColumnReferenceFieldId: null }, { referenceFieldId: this.fileUploadId, referenceFieldName: this.fileUpload.name, label: 'File upload table field', isRequired: true, showInTable: false, columnOrder: 0, aggregateColumnReferenceFieldId: null }]; subsetFieldDefinitions = this.tableFieldDefinitions.filter((field) => { return field.referenceFieldId !== this.fileUploadId; }); culture = 'en-US'; tableResponses: ReferenceFieldAPI.TableResponse[] = [{ rowId: 1, columns: [{ referenceFieldId: this.numberId, referenceFieldKey: this.numberKey, value: '27', dateValue: '', currencyValue: '', numericValue: 27, file: null, files: [], applicationFormId: 1, applicationId: 2 }, { referenceFieldId: this.checkboxId, referenceFieldKey: this.checkboxKey, value: 'true', dateValue: '', currencyValue: '', numericValue: null, file: null, files: [], applicationFormId: 1, applicationId: 2 }] }, { rowId: 2, columns: [{ referenceFieldId: this.numberId, referenceFieldKey: this.numberKey, value: '50', dateValue: '', currencyValue: '', numericValue: 50, file: null, files: [], applicationFormId: 1, applicationId: 2 }, { referenceFieldId: this.checkboxId, referenceFieldKey: this.checkboxKey, value: 'false', dateValue: '', currencyValue: '', numericValue: null, file: null, files: [], applicationFormId: 1, applicationId: 2 }] }]; selectedCurrencies: CurrencySetting[] = [{ code: 'EUR', displayName: 'EUR', default: false }, { code: 'USD', displayName: 'USD', default: true }]; constructor ( private adHocReportingDefinitions: AdHocReportingDefinitions ) { } @BeforeEach() async mock (service: ReferenceFieldsService) { service['referenceFieldsResources'].searchReferenceFields = async () => { return { records: this.allReferenceFields, recordCount: this.allReferenceFields.length }; }; service['referenceFieldsResources'].getTableFields = async () => { return this.tableFieldDefinitions; }; service['referenceFieldsResources'].getSubsetFields = async () => { return this.subsetFieldDefinitions; }; service['referenceFieldsResources'].getCategories = async () => { return this.categories; }; service['referenceFieldsResources'].getApplicationResponsesForMerge = async () => { return this.appResponsesForMerge; }; service['referenceFieldsResources'].getReferenceFieldResponses = async () => { return []; }; service['referenceFieldsResources'].getTableResponses = async () => { return this.tableResponses; }; service['referenceFieldsResources'].bulkCreateReferenceFields = async () => { return [{ id: this.numberId, name: this.numberKey, description: this.numberKey, type: ReferenceFieldsUI.ReferenceFieldTypes.Number, key: this.numberKey, picklistId: 0, parentReferenceFieldKey: null, supportsMultiple: false, formAudience: FormAudience.MANAGER, category: { id: 1, name: 'number' }, aggregateType: 1, singleResponse: false, isEncrypted: false, isMasked: false, isTableField: false, formatType: 0 }] as ReferenceFieldAPI.BulkCreateReferenceField[]; }; service['referenceFieldsResources'].mergeFields = async () => { return; }; service['referenceFieldsResources'].getReferenceFieldDetail = async () => { return { hasWflAutomation: false, hasResponses: false } as ReferenceFieldAPI.ReferenceFieldDetail; }; service['customDataTablesService']['set']( 'customDataTableOptionsMap', { [this.cdtGuid1]: [{ key: '1', sortOrder: 1, inUse: true, value: 'Steelers', parentKeys: [], parentKeysString: '' }, { key: '2', sortOrder: 2, inUse: true, value: 'Cowboys', parentKeys: [], parentKeysString: '' }, { key: '3', sortOrder: 3, value: 'Packers', inUse: true, parentKeys: [], parentKeysString: '' }, { key: '4', sortOrder: 4, value: 'Jets', inUse: true, parentKeys: [], parentKeysString: '' }, { key: 'Vikings', sortOrder: 5, value: '5', inUse: true, parentKeys: [], parentKeysString: '' }], [this.cdtGuid2]: [{ key: '1', sortOrder: 1, inUse: true, value: 'Steelers', parentKeys: [], parentKeysString: '' }, { key: '2', sortOrder: 2, inUse: false, value: 'Cowboys', parentKeys: [], parentKeysString: '' }, { key: '3', sortOrder: 3, inUse: true, value: 'Packers', parentKeys: [], parentKeysString: '' }, { key: '4', sortOrder: 4, inUse: true, value: 'Jets', parentKeys: [], parentKeysString: '' }, { key: 'Vikings', sortOrder: 5, inUse: true, value: '5', parentKeys: [], parentKeysString: '' }] } ); service['customDataTablesService']['set']( 'customDataTables', this.customDataTables ); service['applicationFileService'].getFileFromFileInfo = async () => { return new Blob(['test']) as File; }; service['userService'].getCurrentUserCulture = () => { return this.culture; }; await service.resolve(); service['clientSettingsService'].setAllCurrencies(); service['clientSettingsService']['clientSettingsResources'].getAvailableApplicantCurrencies = async () => { return this.selectedCurrencies; }; service['clientSettingsService']['clientSettingsResources'].getSelectedCurrencies = async () => { return this.selectedCurrencies; }; service['clientSettingsService']['userService'].setLastSelectedCurrency('INR'); await service['clientSettingsService'].setCurrencySettings(); await service['clientSettingsService'].setAvailableApplicantCurrencies(1); service['clientSettingsService']['clientSettingsResources']['getClientSettings'] = async () => { return { isRootClient: false } as ClientSettings; }; service['clientSettingsService'].setClientSettings(); } @AfterEach() cleanup () { spy.restore(); } @TestCase('should be able to format reference field responses coming in') formatReferenceFieldResponses (service: ReferenceFieldsService) { const responses = this.responsesForAdapting; service.formatReferenceFieldResponses( responses, 1, 2 ); const hasCorrectSelectBoxes = (responses[this.selectBoxesKey].value as string[]).every((answer) => { return answer === '2' || answer === '4'; }); expect(responses[this.checkboxKey].value).to.be.true; expect(responses[this.selectBoxesKey].value instanceof Object).to.be.true; expect(hasCorrectSelectBoxes).to.be.true; } @TestCase('should be able to set type map') setTypeMap (service: ReferenceFieldsService) { expect(service.referenceFieldMap[this.checkboxKey].type).to.be.equal( ReferenceFieldsUI.ReferenceFieldTypes.Checkbox ); expect(service.referenceFieldMap[this.textFieldKey].type).to.be.equal( ReferenceFieldsUI.ReferenceFieldTypes.TextField ); } @TestCase('should be able to adapt checkbox responses for API') adaptCheckboxResponseValueForApi (service: ReferenceFieldsService) { let adapted = service.adaptResponseValueForApi(this.checkboxKey, null); expect(adapted.value).to.be.equal('false'); adapted = service.adaptResponseValueForApi(this.checkboxKey, true); expect(adapted.value).to.be.equal('true'); adapted = service.adaptResponseValueForApi(this.checkboxKey, false); expect(adapted.value).to.be.equal('false'); } @TestCase('should be able to adapt selectbox responses for API') adaptSelectBoxResponseValueForApi (service: ReferenceFieldsService) { let adapted = service.adaptResponseValueForApi(this.selectBoxesKey, null); expect(adapted.value).to.be.equal(''); adapted = service.adaptResponseValueForApi( this.selectBoxesKey, ['4'] ); expect(adapted.value).to.be.equal('4'); adapted = service.adaptResponseValueForApi( this.selectBoxesKey, ['2', '4'] ); expect(adapted.value).to.be.equal('2,4'); } @TestCase('should be able to adapt currency responses for API') adaptCurrencyValueForApi (service: ReferenceFieldsService) { let adapted = service.adaptResponseValueForApi(this.currencyKey, null); expect(adapted.value).to.be.equal(''); adapted = service.adaptResponseValueForApi( this.currencyKey, { amountInDefaultCurrency: 500, amountEquivalent: 500, amountForControl: 500, currency: 'CAD' } ); expect(adapted.currencyValue).to.be.equal('CAD'); expect(adapted.value).to.be.equal('500'); } @TestCase('should be able to find reference field by ID') findReferenceFieldById (service: ReferenceFieldsService) { const found = service.findReferenceFieldById(this.textAreaId); expect(found).to.not.be.undefined; expect(found.type).to.be.equal(ReferenceFieldsUI.ReferenceFieldTypes.TextArea); } @TestCase('should be able to find reference field by key') findReferenceFieldByKey (service: ReferenceFieldsService) { const found = service.getReferenceFieldByKey('textarea'); expect(found).to.not.be.undefined; expect(found.type).to.be.equal(ReferenceFieldsUI.ReferenceFieldTypes.TextArea); } @TestCase('should be able to get categories') async getCategories (service: ReferenceFieldsService) { await service.fetchAllCategories(); expect(service.categories.length).to.be.equal(3); expect(service.categories[0].id).to.be.equal(1); } @TestCase('should be able to use category name map') async useCategoryNameMap (service: ReferenceFieldsService) { await service.fetchAllCategories(); expect(service.categoryNameMap).to.not.be.undefined; expect(service.categoryNameMap[1]).to.be.equal('Category 1'); } @TestCase('should be able to guess key') guessKey (service: ReferenceFieldsService) { let key = service.guessKey('test'); expect(key).to.be.equal('test'); key = service.guessKey('textfield'); expect(key).to.be.equal('textfield2'); } @TestCase('should be able to guess key with additional passed in') guessKeyWithAdditional (service: ReferenceFieldsService) { let key = service.guessKey('test', ['test']); expect(key).to.be.equal('test2'); key = service.guessKey('textfield', ['textfield2']); expect(key).to.be.equal('textfield3'); } @TestCase('should be able to get unique category key for form builder') getUniqueCategoryKey (service: ReferenceFieldsService) { const key = service.getUniqueCategoryKey( 'Category 1', FormAudience.APPLICANT, 1 ); expect(key).to.be.equal('Category 1-1-1-Category'); } @TestCase('should be able to get merge invalid alert') getMergeInvalidAlert (service: ReferenceFieldsService) { const field1 = { ...this.allReferenceFields[0], hasResponses: false, hasWflAutomation: false, forms: [{ formId: 1, formRevisionId: 2, name: '', formRevisionVersion: 1 }], hasTable: false }; const field2 = { ...this.allReferenceFields[1], hasResponses: false, hasWflAutomation: false, forms: [{ formId: 1, formRevisionId: 2, name: '', formRevisionVersion: 2 }], hasTable: false }; let invalidMessage = service.getMergeInvalidAlert([ field1, field2 ]); expect(invalidMessage).to.not.be.equal(''); invalidMessage = service.getMergeInvalidAlert([ field1, { ...this.allReferenceFields[2], hasResponses: false, hasWflAutomation: false, hasTable: false } ]); expect(invalidMessage).to.be.equal(''); } @TestCase('should be able to handle format and add category') async handleFormatAndAddCategory (service: ReferenceFieldsService) { const field: ReferenceFieldAPI.ReferenceFieldBaseModel = { customDataTableGuid: 'asdf', parentReferenceFieldId: null, isEncrypted: false, isMasked: false, aggregateType: null, name: 'Select Boxes', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.SelectBoxes, key: 'selectBoxes', supportsMultiple: null, categoryId: null, formAudience: FormAudience.APPLICANT, isSingleResponse: false, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; const result = await service.handleFormatAndAddCategory( field, false ); expect(result.supportsMultiple).to.be.true; } @TestCase('should be able to get application responses for merge') async getApplicationResponsesForMerge (service: ReferenceFieldsService) { const responses = await service.getApplicationResponsesForMerge( this.dataTableId, this.dataTableId2 ); expect(responses[0].referenceField1Response).to.be.equal('Steelers'); expect(responses[0].referenceField2Response).to.be.equal(null); expect(responses[3].referenceField2Response).to.be.equal('Jets'); expect(responses[3].referenceField1Response).to.be.equal(null); } @TestCase('should be able to get number reference field column def') getReferenceFieldColumnDef (service: ReferenceFieldsService) { const numberField = this.allReferenceFields.find((field) => { return field.referenceFieldId === this.numberId; }); const [def] = service.getReferenceFieldColumnDef({ ...numberField, formIds: [] }); expect(def.type).to.be.equal('number'); } @TestCase('should be able to get supports multiple separator') getSupportsMultipleSeparator (service: ReferenceFieldsService) { const multiField = this.allReferenceFields.find((field) => { return field.referenceFieldId === this.textFieldId; }); let separator = service.getSupportsMultipleSeparator(multiField); expect(separator).to.be.equal('|'); separator = service.getSupportsMultipleSeparator(null); expect(separator).to.be.equal(''); } @TestCase('should be able to set all types') setAvailableApplicantTypes (service: ReferenceFieldsService) { const numberOfTypes = service.getReferenceFieldTypeOptions().length; // Times 2 to get all types for both applicant and manager for the buckets, // Then substract 1 because we don't allow GM table types expect(service.allTypes.length).to.be.equal((numberOfTypes * 2) - 1); } @TestCase('should be able to get form fields by type and audience') getFormFieldsByTypeAndAudience (service: ReferenceFieldsService) { const fields = service.getFormFieldsByTypeAndAudience( ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable, FormAudience.APPLICANT, FormAudience.APPLICANT ); expect(fields.length).to.be.equal(2); const foundPicklist1 = fields.find((field) => { return field.referenceFieldId === this.dataTableId; }); const foundPicklist2 = fields.find((field) => { return field.referenceFieldId === this.dataTableId2; }); expect(foundPicklist1).to.not.be.undefined; expect(foundPicklist2).to.not.be.undefined; } @TestCase('should be able to get form fields by type and audience with existing') getFormFieldsByTypeAndAudienceWithExisting (service: ReferenceFieldsService) { const tableData1FieldOnly = this.allReferenceFields.filter((refField) => { return refField.key === this.dataTable1Key; }); service['set']('currentFormRefFields', tableData1FieldOnly); const fields = service.getFormFieldsByTypeAndAudience( ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable, FormAudience.APPLICANT, FormAudience.APPLICANT ); expect(fields.length).to.be.equal(1); const foundPicklist1 = fields.find((field) => { return field.referenceFieldId === this.dataTableId; }); const foundPicklist2 = fields.find((field) => { return field.referenceFieldId === this.dataTableId2; }); expect(foundPicklist1).to.be.undefined; expect(foundPicklist2).to.not.be.undefined; expect(foundPicklist2.key).to.be.equal(this.dataTable2Key); } @TestCase('should be able to get single response manager fields for applicant forms') ensureSingleResponseManagerFieldsPresentOnApplicantForm (service: ReferenceFieldsService) { const fields = service.getFormFieldsByTypeAndAudience( ReferenceFieldsUI.ReferenceFieldTypes.TextField, FormAudience.MANAGER, FormAudience.APPLICANT ); const fieldsContainSingleResponseManagerKey = fields.some(field => { return field.key === this.singleResponseManagerFieldKey; }); expect(fieldsContainSingleResponseManagerKey).to.be.true; } @TestCase('should be able to get category options from form fields') getCategoryOptionsFromFields (service: ReferenceFieldsService) { const fields = service.getFormFieldsByTypeAndAudience( ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable, FormAudience.APPLICANT, FormAudience.APPLICANT ); const options = service.getCategoryOptionsFromFields(fields); expect(options.length).to.be.equal(1); expect(options[0].value).to.be.equal(1); } @TestCase('should be able to get duplicate field alert') getDuplicateFieldAlert (service: ReferenceFieldsService) { const fieldToDupe = this.allReferenceFields.find((field) => { return field.referenceFieldId === this.dataTableId; }); const dupeFormVal: ReferenceFieldAPI.ReferenceFieldBaseModel = { customDataTableGuid: fieldToDupe.customDataTableGuid, parentReferenceFieldId: null, name: fieldToDupe.name, description: fieldToDupe.description, type: fieldToDupe.type, key: fieldToDupe.key, supportsMultiple: fieldToDupe.supportsMultiple, categoryId: fieldToDupe.categoryId, formAudience: fieldToDupe.formAudience, isEncrypted: false, isMasked: false, aggregateType: null, tableAllowsImport: false, isSingleResponse: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; let dupeAlert = service.getDuplicateFieldAlert(null, dupeFormVal); expect(dupeAlert).to.not.be.undefined; dupeAlert = service.getDuplicateFieldAlert(1, dupeFormVal); expect(dupeAlert).to.be.undefined; dupeAlert = service.getDuplicateFieldAlert(null, { ...dupeFormVal, name: 'Diff name' }); expect(dupeAlert).to.be.undefined; } @TestCase('should be able to format pagination options without formIds') formatPaginationOptionsWithFormIds (service: ReferenceFieldsService) { const options: PaginationOptions = { filterColumns: [{ columnName: 'key', filters: [{ filterValue: 'asdf', filterType: 'eq' }] }], orFilterColumns: [], rowsPerPage: 10, pageNumber: 1, sortColumns: [], retrieveTotalRecordCount: true, returnAll: false }; const response = service.formatPaginationOptions(options); expect(response.formIds).to.be.undefined; expect(response.paginationOptions.filterColumns.length).to.be.equal(1); expect(response.paginationOptions.filterColumns[0].columnName).to.be.equal('key'); } @TestCase('should be able to format pagination options with formIds') formatPaginationOptionsWithoutFormIds (service: ReferenceFieldsService) { const options: PaginationOptions = { filterColumns: [{ columnName: 'key', filters: [{ filterValue: 'asdf', filterType: 'eq' }] }, { columnName: 'formIds', filters: [{ filterValue: 111, filterType: 'eq' }] }], orFilterColumns: [], rowsPerPage: 10, pageNumber: 1, sortColumns: [], retrieveTotalRecordCount: true, returnAll: false }; const response = service.formatPaginationOptions(options); expect(response.formIds.length).to.be.equal(1); expect(response.formIds[0]).to.be.equal(111); expect(response.paginationOptions.filterColumns.length).to.be.equal(1); expect(response.paginationOptions.filterColumns[0].columnName).to.be.equal('key'); } @TestCase('ensure selectboxes always have supportsMultiple as true') adaptSelectBoxesMulti (service: ReferenceFieldsService) { const foundSelectBox = service.allReferenceFields.find((field) => { return field.referenceFieldId === this.selectBoxesId; }); expect(foundSelectBox.supportsMultiple).to.be.true; } @TestCase('should be able to adapt aggregate type from import') adaptAggregateTypeFromImport (service: ReferenceFieldsService) { let value = service.adaptAggregateTypeFromImport('sum'); expect(value).to.be.equal(ReferenceFieldAPI.ReferenceFieldAggregateType.Sum); value = service.adaptAggregateTypeFromImport('average'); expect(value).to.be.equal(ReferenceFieldAPI.ReferenceFieldAggregateType.Average); } @TestCase('should be able to get needToSaveFileIds from adaptFormioChangesForSave') adaptFormioChangesForSave (service: ReferenceFieldsService) { const changeMap = { [this.textFieldKey]: 'value 1', [this.fileUploadKey]: [ new YcFile( 'file name', null, 'file url', 23 ) ] }; const response = service.adaptFormioChangesForSave( changeMap, 123, 456, 789, false, false ); expect(response.needToSaveFileIds).to.be.true; } @TestCase('should be able to get values from adaptFormioChangesForSave') adaptFormioChangesForSave2 (service: ReferenceFieldsService) { const changeMap = { [this.textFieldKey]: 'value 1', [this.fileUploadKey]: [ new YcFile( 'file name', null, 'file url', 23 ) ] }; const response = service.adaptFormioChangesForSave( changeMap, 123, 456, 789, false, false ); expect(response.standardChangeValues.length).to.be.equal(2); const hasTextFieldKey = response.standardChangeValues.some((val) => { return val.value === 'value 1'; }); expect(hasTextFieldKey).to.be.true; } @TestCase('should be able to handle change tracking with ref changes') handleChangeTracking (service: ReferenceFieldsService) { const changes: FormioChanges[] = [{ key: this.textFieldKey, isReferenceField: true, type: `referenceFields-${this.textFieldKey}`, value: 'value' }]; const response = service.handleChangeTracking( changes, { referenceFields: { [this.textFieldKey]: '' } } ); expect(response.appNeedsUpdated).to.be.false; expect(response.refChangeTracker[this.textFieldKey]).to.be.equal('value'); } @TestCase('should be able to handle change tracking with blank masked ref changes') handleChangeTrackingBlankMasked (service: ReferenceFieldsService) { const changes: FormioChanges[] = [{ key: this.maskedFieldKey, isReferenceField: true, type: `referenceFields-${this.maskedFieldKey}`, value: '' }]; const response = service.handleChangeTracking( changes, { referenceFields: { [this.maskedFieldKey]: '' } } ); expect(response.appNeedsUpdated).to.be.false; expect(this.maskedFieldKey in response.refChangeTracker).to.equal(false); } @TestCase('should be able to handle change tracking with populated masked ref changes') handleChangeTrackingPopulatedMasked (service: ReferenceFieldsService) { const changes: FormioChanges[] = [{ key: this.maskedFieldKey, isReferenceField: true, type: `referenceFields-${this.maskedFieldKey}`, value: 'asdf' }]; const response = service.handleChangeTracking( changes, { referenceFields: { [this.maskedFieldKey]: '' } } ); expect(response.appNeedsUpdated).to.be.false; expect(this.maskedFieldKey in response.refChangeTracker).to.equal(true); } @TestCase('should be able to handle change tracking with app changes') handleChangeTracking2 (service: ReferenceFieldsService) { const changes: FormioChanges[] = [{ key: 'amountRequested', isReferenceField: false, type: 'amountRequested', value: 500 }]; const response = service.handleChangeTracking( changes, {} ); expect(response.appNeedsUpdated).to.be.true; } @TestCase('should be able to check if type has options') doesTypeHaveOptions (service: ReferenceFieldsService) { let type = ReferenceFieldsUI.ReferenceFieldTypes.TextField; let hasOptions = service.doesTypeHaveOptions(type); expect(hasOptions).to.be.false; type = ReferenceFieldsUI.ReferenceFieldTypes.Radio; hasOptions = service.doesTypeHaveOptions(type); expect(hasOptions).to.be.true; } @TestCase('should be able to convert ref field keys to ids') convertRefFieldKeysToIds (service: ReferenceFieldsService) { const response = service.convertRefFieldKeysToIds([ this.textFieldKey, this.dataTable1Key ]); expect(response.length).to.be.equal(2); response; const foundTextId = response.some((id) => id === this.textFieldId); const foundDataTableId = response.some((id) => id === this.dataTableId); expect(foundTextId).to.be.true; expect(foundDataTableId).to.be.true; } @TestCase('should be able to get is correct type for mask and encrypt') isCorrectTypeForMaskAndEncyrpt (service: ReferenceFieldsService) { let passes = service.isCorrectTypeForMaskAndEncyrpt( ReferenceFieldsUI.ReferenceFieldTypes.TextField, false ); expect(passes).to.be.true; passes = service.isCorrectTypeForMaskAndEncyrpt( ReferenceFieldsUI.ReferenceFieldTypes.TextArea, false ); expect(passes).to.be.false; } @TestCase('should be able to get can be table field') canBeTableField (service: ReferenceFieldsService) { let passes = service.canBeTableField( ReferenceFieldsUI.ReferenceFieldTypes.Radio, false, FormAudience.APPLICANT, false ); // Radio non multi should pass expect(passes).to.be.true; passes = service.canBeTableField( ReferenceFieldsUI.ReferenceFieldTypes.SelectBoxes, true, FormAudience.APPLICANT, false ); // Multi value fields should not pass expect(passes).to.be.false; passes = service.canBeTableField( ReferenceFieldsUI.ReferenceFieldTypes.Currency, false, FormAudience.APPLICANT, false ); // Applicant Currency field should pass expect(passes).to.be.true; } @TestCase('should be able to get available table fields') getAvailableTableFields (service: ReferenceFieldsService) { const availableTableFields = service.getAvailableTableFields(); expect(availableTableFields.length).to.be.equal(1); const isCorrectField = availableTableFields.some((field) => { return field.referenceFieldId === this.textAreaId; }); const isIncorrectField = availableTableFields.some((field) => { return field.referenceFieldId === this.aggregateId; }); expect(isCorrectField).to.be.true; expect(isIncorrectField).to.be.false; } @TestCase('should be able to find aggregate for table column') findAggregateForTableColumn (service: ReferenceFieldsService) { const found = service.findAggregateForTableColumn( this.tableId, this.numberId ); expect(found.referenceFieldId).to.be.equal(this.aggregateId); } @TestCase('should be able to get tooltip for delete ref field') getTooltipForDeleteRefField (service: ReferenceFieldsService) { let tooltip = service.getTooltipForDeleteRefField( 2, true, this.textFieldId, false, false ); // Tooltip exists because it's on forms and reports expect(tooltip).to.not.be.equal(''); tooltip = service.getTooltipForDeleteRefField( 0, false, this.textFieldId, false, false ); // Tooltip does not exist because it's not on forms or reports expect(tooltip).to.be.equal(''); tooltip = service.getTooltipForDeleteRefField( 0, false, this.textFieldId, true, false ); // Tooltip exists because this is a standard product field that is published expect(tooltip).to.not.be.equal(''); tooltip = service.getTooltipForDeleteRefField( 0, false, this.textFieldId, false, true ); // Tooltip does not exist because root zone is deleting a non-published field expect(tooltip).to.equal(''); } @TestCase('should be able to set all table columns on a form') async setAllTableColumnsOnForm (service: ReferenceFieldsService) { await service.setAllTableAndSubsetColumnsOnForm([this.tableId]); const tableCols = service.tableColumnsMap[this.tableId]; const isSet = !!tableCols; expect(isSet).to.be.true; const hasNumberCol = tableCols.some((col) => { return col.referenceFieldId === this.numberId; }); expect(hasNumberCol).to.be.true; } @TestCase('should be able to get all table field select options') testGetTableFieldSelectOptions (service: ReferenceFieldsService) { const selectOptions = service.getTableFieldSelectOptions(); expect(selectOptions).to.not.be.undefined; const tableFields = service.allReferenceFields.filter((refField) => { return refField.referenceFieldTableId && refField.type === ReferenceFieldsUI.ReferenceFieldTypes.Table; }); const selectOptionsContainsEachTable = tableFields.every((tableField) => { return selectOptions.some((selectOption) => { return selectOption.value === tableField.key && selectOption.label === tableField.name; }); }); expect(selectOptionsContainsEachTable).to.be.true; } @TestCase('should be able to get category map from record IDs and form components') testGetCategoryMapFromRecordIdsAndFormComponents (service: ReferenceFieldsService) { // formComponents const formCompCategoryMap = service.getCategoryMapFromRecordIds([2], this.formComponentMap, AdHocReportingUI.Usage.AD_HOC, this.adHocReportingDefinitions.customForm); const formCompCategoryMapContainsAggregate = formCompCategoryMap[this.textField.categoryId].some((field) => { return field.referenceFieldId === this.aggregateField.referenceFieldId; }); const formCompCategoryMapContainsTextField = formCompCategoryMap[this.textField.categoryId].some((field) => { return field.referenceFieldId === this.textField.referenceFieldId; }); const formCompCategoryMapContainsTableField = formCompCategoryMap[this.textField.categoryId].some((field) => { return field.referenceFieldId === this.tableId; }); expect(formCompCategoryMapContainsAggregate).to.be.true; expect(formCompCategoryMapContainsTextField).to.be.true; expect(formCompCategoryMapContainsTableField).to.be.false; // On return, do the same for table comps } @TestCase('should be able to get category map from record IDs and table components') testGetCategoryMapFromRecordIdsAndTableComponents (service: ReferenceFieldsService) { const tableCompCategoryMap = service.getCategoryMapFromRecordIds([3], this.tableComponentMap, AdHocReportingUI.Usage.AD_HOC, this.adHocReportingDefinitions.table); const tableCompCategoryMapContainsAggregate = tableCompCategoryMap[this.defaultCategoryId].some((field) => { return field.referenceFieldId === this.aggregateField.referenceFieldId; }); const tableCompCategoryMapContainsNumber = tableCompCategoryMap[3].some((field) => { return field.referenceFieldId === this.numberField.referenceFieldId; }); const tableCompCategoryMapContainsTextField = tableCompCategoryMap[3].some((field) => { return field.referenceFieldId === this.textField.referenceFieldId; }); const tableCompCategoryMapContainsTableField = tableCompCategoryMap[3].some((field) => { return field.referenceFieldId === this.tableId; }); expect(tableCompCategoryMapContainsTextField).to.be.false; expect(tableCompCategoryMapContainsNumber).to.be.true; expect(tableCompCategoryMapContainsAggregate).to.be.true; expect(tableCompCategoryMapContainsTableField).to.be.false; } @TestCase('should be able to get and format reference field table responses') async getReferenceFieldResponses (service: ReferenceFieldsService) { const refResponseMap = await service.getReferenceFieldResponses( 1, 2, [], [this.tableId], null, false ); let numberFormattedCorrectly = false; let checkboxFormattedCorrectly = false; const table = refResponseMap.table as ReferenceFieldsUI.TableResponseRowForUi[]; table[0].columns.forEach((column) => { if (column.referenceFieldId === this.numberId) { numberFormattedCorrectly = typeof column.value === 'number'; } if (column.referenceFieldId === this.checkboxId) { checkboxFormattedCorrectly = typeof column.value === 'boolean'; } }); expect(numberFormattedCorrectly).to.be.true; expect(checkboxFormattedCorrectly).to.be.true; } @TestCase('should be able to convert ref value to number') convertRefValueToNumber (service: ReferenceFieldsService) { const numberVal = service.convertRefValueToNumber('27'); expect(numberVal).to.be.equal(27); } @TestCase('should be able to convert ref val to boolean') convertRefValueToBool (service: ReferenceFieldsService) { const checkboxVal = service.convertRefValueToBool('true'); expect(checkboxVal).to.be.true; } @TestCase('should be able to map table responses for API') async mapTableResponsesForAPI (service: ReferenceFieldsService) { await service.getReferenceFieldResponses( 1, 2, [], [this.tableId], null, false ); const updatedRefResponseMap: ReferenceFieldsUI.RefResponseMap = { table: [{ rowId: 1, columns: [{ referenceFieldId: this.numberId, referenceFieldKey: this.numberKey, value: 29, dateValue: '', numericValue: null, currencyValue: '', file: null, files: [], applicationFormId: 1, applicationId: 2 }, { referenceFieldKey: this.checkboxKey, referenceFieldId: this.checkboxId, value: true, dateValue: '', numericValue: null, currencyValue: '', file: null, files: [], applicationFormId: 1, applicationId: 2 }] }] }; const mapped = service.mapTableResponsesForAPI( updatedRefResponseMap, 2, 1, null, false ); const deletedRow = 2; const foundDeletedRow = mapped.deletions.some((deletion) => { return deletion.rowId === deletedRow; }); expect(foundDeletedRow).to.be.true; const updatedRow = 1; const foundUpdatedRow = mapped.updates.some((update) => { return update.rowId === updatedRow; }); expect(foundUpdatedRow).to.be.true; } @TestCase('should be able to format table row update') async formatTableRowUpdate (service: ReferenceFieldsService) { const newRow: ReferenceFieldsUI.TableResponseRowForUi = { rowId: 1, columns: [{ referenceFieldId: this.numberId, referenceFieldKey: this.numberKey, value: 29, dateValue: '', numericValue: null, currencyValue: '', file: null, files: [], applicationFormId: 1, applicationId: 2 }, { referenceFieldKey: this.checkboxKey, referenceFieldId: this.checkboxId, value: true, dateValue: '', numericValue: null, currencyValue: '', file: null, files: [], applicationFormId: 1, applicationId: 2 }] }; const formatted = service.formatTableRowUpdate( newRow, 1, this.tableId, false, 0 ); const foundCorrectFormattedNumber = formatted.values.some((val) => { return val.referenceFieldKey === this.numberKey && typeof val.value === 'string'; }); expect(foundCorrectFormattedNumber).to.be.true; const foundCorrectFormattedCheckbox = formatted.values.some((val) => { return val.referenceFieldKey === this.checkboxKey && typeof val.value === 'string'; }); expect(foundCorrectFormattedCheckbox).to.be.true; } @TestCase('should be able to adapt table info for save') adaptTableInfoForSave (service: ReferenceFieldsService) { const adapted = service.adaptTableInfoForSave( true, [this.numberTableFieldForUi] ); const hasAdaptedCorrectly = adapted.allowImport && adapted.tableFields.some((field) => { return field.isRequired === this.numberTableFieldForUi.isRequired && field.showInTable === this.numberTableFieldForUi.showInTable && field.columnOrder === this.numberTableFieldForUi.columnOrder; }); expect(hasAdaptedCorrectly).to.be.true; } @TestCase('should be able to get aggregate field changes') getAggregateFieldChanges (service: ReferenceFieldsService) { const changes = service.getAggregateFieldChanges( 'Table Field', this.tableId, [this.numberTableFieldForUi] ); const foundFieldToUpdate = changes.fieldsToCreateOrUpdate.some((field) => { return field.aggregateTableReferenceFieldId === this.tableId && field.isTableField && field.parentReferenceFieldId === this.numberId; }); changes; expect(foundFieldToUpdate).to.be.true; } @TestCase('should be able to get table form key') getTableFormKey (service: ReferenceFieldsService) { const appFormId = 1; const key = service.getTableFormKey(appFormId, this.tableId); expect(key).to.be.equal(`${appFormId}_${this.tableId}`); } @TestCase('should be able to set application form table rows map') setApplicationFormTableRowsMap (service: ReferenceFieldsService) { const appFormId = 1; service.setApplicationFormTableRowsMap( appFormId, { [this.tableKey]: [] } ); const key = `${appFormId}_${this.tableId}`; const isSet = !!service.applicationFormTableRowsMap[key]; expect(isSet).to.be.true; } @TestCase('should be able to update app form table rows after copy') async updateApplicationFormTableRowsMapAfterCopy (service: ReferenceFieldsService) { const oldAppFormId = 3; const newAppFormId = 4; await service.getReferenceFieldResponses( 1, oldAppFormId, [], [this.tableId], null, false ); service.updateApplicationFormTableRowsMapAfterCopy( oldAppFormId, newAppFormId, [this.tableId] ); const oldKey = `${oldAppFormId}_${this.tableId}`; const newKey = `${newAppFormId}_${this.tableId}`; const foundUpdatedMap = !!service.applicationFormTableRowsMap[newKey]; const didNotFinddOldMap = !service.applicationFormTableRowsMap[oldKey]; expect(foundUpdatedMap).to.be.true; expect(didNotFinddOldMap).to.be.true; } @TestCase('should be able to get table column response') getTableColumnResponse (service: ReferenceFieldsService) { const tableResponseRow: ReferenceFieldsUI.TableResponseRowForUi = { rowId: 1, columns: [{ referenceFieldId: this.numberId, referenceFieldKey: this.numberKey, value: 29, dateValue: '', numericValue: null, currencyValue: '', file: null, files: [], applicationFormId: 1, applicationId: 2 }, { referenceFieldKey: this.checkboxKey, referenceFieldId: this.checkboxId, value: true, dateValue: '', numericValue: null, currencyValue: '', file: null, files: [], applicationFormId: 1, applicationId: 2 }] }; const numberValue = service.getTableColumnResponse( tableResponseRow, this.numberTableFieldForUi, true ); expect(numberValue).to.be.equal('29'); } @TestCase('should be able to get visible table columns') async getVisibleTableColumns (service: ReferenceFieldsService) { await service.setColumnsForTable(this.tableId); const visibleColumns = service.getVisibleTableColumns( this.tableId, {} ); const numberOfVisibleColumns = this.tableFieldDefinitions.filter((field) => { return field.showInTable; }).length; expect(visibleColumns.length).to.be.equal(numberOfVisibleColumns); } @TestCase('should be able to filter out responses no longer on form') filterOutResponsesNoLongerOnForm (service: ReferenceFieldsService) { const keyNoLongerOnForm = 'keyNoLongerOnForm'; const formDefinition: FormDefinitionForUi[] = [{ tabName: 'One', index: 0, uniqueId: '235235', logic: null, components: [{ type: `referenceFields-${this.textAreaKey}` } as FormDefinitionComponent, { type: `referenceFields-${this.aggregateKey}` } as FormDefinitionComponent] }, { tabName: 'Two', index: 1, uniqueId: '235235', logic: null, components: [{ type: `referenceFields-${this.checkboxKey}` } as FormDefinitionComponent, { type: `referenceFields-${this.numberKey}` } as FormDefinitionComponent] }]; const responses: ReferenceFieldsUI.RefResponseMapForAdapting = { [this.textAreaKey]: { value: 'text area answer' } as ReferenceFieldAPI.ApplicationRefFieldResponse, [this.numberKey]: { value: 2 } as ReferenceFieldAPI.ApplicationRefFieldResponse, [this.checkboxKey]: { value: true } as ReferenceFieldAPI.ApplicationRefFieldResponse, [this.aggregateKey]: { value: 4 } as ReferenceFieldAPI.ApplicationRefFieldResponse, [keyNoLongerOnForm]: { value: 'no longer on form' } as ReferenceFieldAPI.ApplicationRefFieldResponse }; service.filterOutResponsesNoLongerOnForm( formDefinition, responses ); // Should remove key no longer on form expect(responses[keyNoLongerOnForm]).to.be.undefined; } // should be able to add to the currentFormReferenceFields @TestCase('Should be able to add to currentFormReferenceFields') testAddingToCurrentFormReferenceFields (service: ReferenceFieldsService) { const componentsToAdd = [{ type: 'referenceFields-textarea', key: this.textAreaKey }, { type: 'referenceFields-singleResponseManagerFieldKey', key: this.singleResponseManagerFieldKey }] as FormDefinitionComponent[]; service.addCurrentFormRefFields(componentsToAdd); const currentFormRefFields = service.get('currentFormRefFields'); const everyComponentAddedIsOnState = componentsToAdd.every((component) => { return currentFormRefFields.some((comp) => comp.key === component.key); }); expect(everyComponentAddedIsOnState).to.be.true; } @TestCase('should be able to get formatting map') getFormattingMap (service: ReferenceFieldsService) { const map = service.getFormattingMap(); expect(map[ReferenceFieldAPI.ReferenceFieldFormattingType.NONE]).to.be.equal( 'No formatting' ); expect(map[ReferenceFieldAPI.ReferenceFieldFormattingType.URL_OPT_HTTP]).to.be.equal( 'URL (e.g. www.website.com)' ); expect(map[ReferenceFieldAPI.ReferenceFieldFormattingType.EMAIL]).to.be.equal( 'Email (e.g. name@host.com)' ); } @TestCase('should be able to get fields available to merge with standard') getFieldsAvailableToMergeWithStandard (service: ReferenceFieldsService) { const availableFields = service.getFieldsAvailableToMergeWithStandard( this.standardProductFieldId ); // The only field that has the same required matching attributes is the text field const hasCorrectField = availableFields.every((field) => { return field.referenceFieldId === this.textFieldId; }); expect(hasCorrectField).to.be.true; } @TestCase('should be able to get category dropdown filter') getCategoryDropdownFilter (service: ReferenceFieldsService) { const filter = service.getCategoryDropdownFilter(); expect(filter.column).to.be.equal('categoryId'); expect(filter.filterType).to.be.equal('checkboxDropdown'); expect(filter.includeAllSelectedOnEmpty).to.be.true; } @TestCase('should be able to get filter for name or key') getFilterForNameOrKey (service: ReferenceFieldsService) { const filter = service.getFilterForNameOrKey(); expect(filter.filterType).to.be.equal('text'); expect(filter.placeholder).to.be.equal('Search by name or key'); const hasOrColumnForName = filter.orColumns.some((col) => { return col.column === 'name' && col.filterType === 'cn'; }); const hasOrColumnForKey = filter.orColumns.some((col) => { return col.column === 'key' && col.filterType === 'cn'; }); expect(hasOrColumnForName).to.be.true; expect(hasOrColumnForKey).to.be.true; } @TestCase('should be able to get are attributes the same') areAttributesTheSame (service: ReferenceFieldsService) { let same = service.areAttributesTheSame( [ this.textField, this.standardProductTextField ], [ 'type', 'formAudience', 'customDataTableGuid', 'supportsMultiple', 'parentReferenceFieldId', 'isSingleResponse', 'isEncrypted', 'isMasked', 'isTableField', 'formatType' ] ); // Should pass expect(same).to.be.true; same = service.areAttributesTheSame( [ this.radioButtonField, this.standardProductTextField ], [ 'type', 'formAudience', 'customDataTableGuid', 'supportsMultiple', 'parentReferenceFieldId', 'isSingleResponse', 'isEncrypted', 'isMasked', 'isTableField', 'formatType' ] ); // Should fail expect(same).to.be.false; } @TestCase('should be able to check merge for conflicts') async checkMergeForConflicts (service: ReferenceFieldsService) { service['referenceFieldsResources'].checkMergeForConflicts = async () => { /* eslint-disable no-throw-literal */ throw { error: { message: 'There are data conflicts among these reference fields. One or more reference fields exist on an application. Merge would result in data loss.' } }; }; let result = await service.checkMergeForConflicts(this.standardProductFieldId, [this.textFieldId]); expect(result.hasConflicts).to.be.true; expect(result.hasOtherError).to.be.false; service['referenceFieldsResources'].checkMergeForConflicts = async () => { throw new Error(); }; result = await service.checkMergeForConflicts(this.standardProductFieldId, [this.textFieldId]); expect(result.hasConflicts).to.be.false; expect(result.hasOtherError).to.be.true; service['referenceFieldsResources'].checkMergeForConflicts = async () => { return; }; result = await service.checkMergeForConflicts(this.standardProductFieldId, [this.textFieldId]); expect(result.hasConflicts).to.be.false; expect(result.hasOtherError).to.be.false; } @TestCase('should be able to handle dependent picklist validity - with errors') handleDependentPicklistValidityWithErrors (service: ReferenceFieldsService) { const compsToAdd = [{ ...this.childField }]; const fieldToAdd = this.childField; const invalidPicklists = service.handleDependentPicklistValidityForQuickAdd( compsToAdd, [], fieldToAdd ); expect(invalidPicklists.length).to.be.equal(1); const invalidPicklist = invalidPicklists[0]; const hasCorrectField = invalidPicklist.fieldWithoutParent.referenceFieldId === fieldToAdd.referenceFieldId; expect(hasCorrectField).to.be.true; const hasCorrectParent = invalidPicklist.parentPicklist.referenceFieldId === this.parentFieldId; expect(hasCorrectParent).to.be.true; } @TestCase('should be able to handle dependent picklist validity - no errors') handleDependentPicklistValidityNoErrors (service: ReferenceFieldsService) { const compsToAdd = [{ ...this.parentField }]; const fieldToAdd = this.parentField; const invalidPicklists = service.handleDependentPicklistValidityForQuickAdd( compsToAdd, [], fieldToAdd ); expect(invalidPicklists.length).to.be.equal(0); } @TestCase('should be able to get child of parent ref field') getChildOfParentRefField (service: ReferenceFieldsService) { const child = service.getChildOfParentRefField(this.parentFieldId); const foundCorrectChild = child.referenceFieldId === this.childField.referenceFieldId; expect(foundCorrectChild).to.be.true; } @TestCase('should be able to set and reset data points map') async resetDataPointsMap (service: ReferenceFieldsService) { await service.setDataPointsForSubset(this.subsetId); const dataPointsBeforeReset = service.dataPointsMap[this.subsetId]; expect(dataPointsBeforeReset).to.not.be.undefined; service.resetDataPointsMap(this.subsetId); const dataPointsAfterReset = service.dataPointsMap[this.subsetId]; expect(dataPointsAfterReset).to.be.undefined; } @TestCase('should be able to get the collection type map for subset fields') getCollectionTypeMap (service: ReferenceFieldsService) { const collectionTypeMap = service.getCollectionTypeMap(); const collectionTypes = [ReferenceFieldAPI.DataSetCollectionType.Number, ReferenceFieldAPI.DataSetCollectionType.Percent, ReferenceFieldAPI.DataSetCollectionType.YesOrNo]; const allCollectionTypesExistOnMap = collectionTypes.every((collectionType) => { return Object.keys(collectionTypeMap).some((key) => { return key === '' + collectionType; }); }); expect(allCollectionTypesExistOnMap).to.be.true; } @TestCase('should be able to get visible table columns for subset fields') async getVisibleTableColumnsForSubsetFields (service: ReferenceFieldsService) { await service.setDataPointsForSubset(this.subsetId); const dataPoints = service.dataPointsMap[this.subsetId]; const visibleColumns = service.getVisibleTableColumns(this.subsetId); expect(dataPoints.length).to.equal(visibleColumns.length); } @TestCase('should be able to get subset rows') async getSubsetRows (service: ReferenceFieldsService) { const subsetRows = await service.getSubsetRows(this.subsetId); const eachIsAdapted = subsetRows.every((subsetRow) => { return subsetRow.hasOwnProperty('value'); }); expect(subsetRows).to.not.be.undefined; expect(eachIsAdapted).to.be.true; } @TestCase('should be able to map rows for subset fields') async mapRowsForSubsetFields (service: ReferenceFieldsService) { await service.setDataPointsForSubset(this.subsetId); const dataPoints = service.dataPointsMap[this.subsetId]; const { dataRows, dataRowsWereUpdated } = service.mapRowsForSubset( this.subsetTableResponseRows, this.subsetId, false ); const numericColumn = dataRows[0].columns.find((column) => { return column.referenceFieldId === this.numberId; }); const everyDataPointIsInMappedRows = dataPoints.every((dataPoint) => { return dataRows[0].columns.some((column) => { return column.referenceFieldId === dataPoint.referenceFieldId; }); }); expect(numericColumn.value).to.equal(this.numberFieldValue); expect(dataRowsWereUpdated).to.be.false; expect(everyDataPointIsInMappedRows).to.be.true; } @TestCase('should be able to set all subset columns on a form') async setAllSubsetColumnsOnForm (service: ReferenceFieldsService) { await service.setAllTableAndSubsetColumnsOnForm([this.subsetId]); const subsetColumns = service.dataPointsMap[this.subsetId]; expect(subsetColumns).to.not.be.undefined; const subsetColumnsHasNumberCol = subsetColumns.some((column) => { return column.referenceFieldId === this.numberId; }); expect(subsetColumnsHasNumberCol).to.be.true; } @TestCase('should be able to get subset row fields per form audience') getSubsetRowFieldsPerFormAudience (service: ReferenceFieldsService) { const applicantDataPoints = service.getSubsetRowFields(FormAudience.APPLICANT); const managerDataPoints = service.getSubsetRowFields(FormAudience.MANAGER); expect(applicantDataPoints.length).to.not.equal(0); expect(managerDataPoints.length).to.not.equal(0); const everyApplicantDPIsCorrectAudience = applicantDataPoints.every((dp) => { return dp.formAudience === FormAudience.APPLICANT; }); const everyManagerDPIsCorrectAudience = managerDataPoints.every((dp) => { return dp.formAudience === FormAudience.MANAGER; }); expect(everyApplicantDPIsCorrectAudience).to.be.true; expect(everyManagerDPIsCorrectAudience).to.be.true; } @TestCase('should be able to get reference field column def based on subset collection type') getRefFieldColumnDefFromSubsetCollectionType (service: ReferenceFieldsService) { const columnDef = service.getReferenceFieldColumnDef({ ...this.dataPointManager, formIds: [1] }) as AdHocReportingUI.NumberColumnDefinition[];; expect(columnDef[0].format).to.equal('wholeNumberPercent'); } @TestCase('should be able to get table files needing uploaded') getTableFilesNeedingUploaded (service: ReferenceFieldsService) { const tableColumns: ReferenceFieldsUI.TableFieldForCrudUi[] = [{ referenceFieldId: this.fileUpload.referenceFieldId, referenceFieldName: this.fileUpload.name, label: this.fileUpload.name, isRequired: true, showInTable: true, columnOrder: 1, aggregateColumnReferenceFieldId: null, summarizeData: false, summarizeLabel: '', referenceField: this.fileUpload, component: {} as FormDefinitionComponent }]; const responseMap: ReferenceFieldsUI.RefResponseMap = { [this.fileUpload.key]: [ new YcFile('file to upload', null, '', null) ] }; const filesNeedingUploaded = service.getTableFilesNeedingUploaded( tableColumns, responseMap ); expect(filesNeedingUploaded.length).to.be.equal(1); const hasCorrectFile = filesNeedingUploaded[0].referenceFieldId === this.fileUpload.referenceFieldId; expect(hasCorrectFile).to.be.true; } @TestCase('should be able to update ref map with new column value') updateReferenceFieldsMapWithNewColumnValue (service: ReferenceFieldsService) { const tableKey = 'tableKey'; const map = { [tableKey]: [{ rowId: 1, columns: [{ referenceFieldId: 1, referenceFieldKey: 'fileKey', value: 'url', dateValue: '', currencyValue: '', numericValue: null }] }] as ReferenceFieldsUI.TableResponseRowForUi[] }; const newValue = 'newValue'; const rowIndex = 0; const columnIndex = 0; service.updateReferenceFieldsMapWithNewColumnValue( map, tableKey, rowIndex, columnIndex, newValue ); const updatedRow = map[tableKey][rowIndex]; const newColumnValue = updatedRow.columns[columnIndex].value; expect(newColumnValue).to.be.equal(newValue); } @TestCase('should be able to get does file need reuploaded - true') getDoesFileNeedReUploadedTrue (service: ReferenceFieldsService) { const newAppId = 123; const oldAppId = 456; const newAppFormId = 235; const oldAppFormId = 567; const needsReUploaded = service.getDoesFileNeedReUploaded( oldAppId, oldAppFormId, newAppId, newAppFormId ); expect(needsReUploaded).to.be.true; } @TestCase('should be able to get does file need reuploaded - false') getDoesFileNeedReUploadedFalse (service: ReferenceFieldsService) { const newAppId = 123; const oldAppId = 123; const newAppFormId = 235; const oldAppFormId = 235; const needsReUploaded = service.getDoesFileNeedReUploaded( oldAppId, oldAppFormId, newAppId, newAppFormId ); expect(needsReUploaded).to.be.false; } @TestCase('should be able to get files to reupload - finds one') async getFilesToReUploadFindsOne (service: ReferenceFieldsService) { const key = this.fileUpload.key; const currentAppId = 1; const currentAppFormId = 2; const oldAppId = 3; const oldAppFormId = 4; const filesToReUpload = await service.getFilesToReUpload( key, [ new YcFile( 'file name', null, `https://yourcausegrantsqa.com/apply/download-file?applicationId=${oldAppId}&applicationFormId=${oldAppFormId}=162038&fileId=6868&fileName=Screen%20Shot%202021-08-19%20at%209.02.00%20AM.png` ) ], currentAppId, currentAppFormId ); expect(filesToReUpload.length).to.be.equal(1); const fileToReUpload = filesToReUpload[0]; expect(fileToReUpload.key).to.be.equal(key); } @TestCase('should be able to get files to reupload - finds none') async getFilesToReUploadFindsNone (service: ReferenceFieldsService) { const key = this.fileUpload.key; const currentAppId = 1; const currentAppFormId = 2; const oldAppId = 1; const oldAppFormId = 2; const filesToReUpload = await service.getFilesToReUpload( key, [ new YcFile( 'file name', null, `https://yourcausegrantsqa.com/apply/download-file?applicationId=${oldAppId}&applicationFormId=${oldAppFormId}=162038&fileId=6868&fileName=Screen%20Shot%202021-08-19%20at%209.02.00%20AM.png` ) ], currentAppId, currentAppFormId ); expect(filesToReUpload.length).to.be.equal(0); } @TestCase('should be able to map new file info back to response map') mapNewFileInfoBackToResponseMap (service: ReferenceFieldsService) { const fileId = 6868; const oldAppId = 1; const oldAppFormId = 2; const file = new YcFile( 'file name', null, `https://yourcausegrantsqa.com/apply/download-file?applicationId=${oldAppId}&applicationFormId=${oldAppFormId}=162038&fileId=${fileId}&fileName=Screen%20Shot%202021-08-19%20at%209.02.00%20AM.png` ); const map = { [this.fileUpload.key]: [ file ] }; file.fileUploadId = fileId; const fileDetails = { referenceFieldId: this.fileUpload.referenceFieldId, key: this.fileUpload.key, file }; const updatedMap = service.mapNewFileInfoBackToResponseMap( fileDetails, file, map ); const filesOnMap = updatedMap[this.fileUpload.key] as YcFile[]; expect(filesOnMap[0].fileUploadId).to.be.equal(fileId); } @TestCase('should be able to get ID name map') getIdNameMap (service: ReferenceFieldsService) { const response = service.getIdNameMap(); expect(response).to.include(this.allReferenceFields.every); } @TestCase('should be able to get aggregate type options') getAggregateTypeOptions (service: ReferenceFieldsService) { const numberOfAgTypes = service.getAggregateTypeOptions().length; expect(numberOfAgTypes).to.be.equal(5); } @TestCase('should be able to get type select options for filters') getTypeSelectOptionsForFilters (service: ReferenceFieldsService) { const response = service.getTypeSelectOptionsForFilters(); expect(response[0].value).to.be.equal('ALL_SKIP_FILTER'); } @TestCase('should be able to getReferenceFieldTypeMap') getReferenceFieldTypeMap (service: ReferenceFieldsService) { const response = service.getReferenceFieldTypeToLabelMap(); expect(response).to.include(this.allReferenceFields.every); } @TestCase('should be able to add and reset current form ref fields') resetCurrentFormRefFields (service: ReferenceFieldsService) { const componentsToAdd = [{ type: 'referenceFields-textarea', key: this.textAreaKey }, { type: 'referenceFields-singleResponseManagerFieldKey', key: this.singleResponseManagerFieldKey }] as FormDefinitionComponent[]; service.addCurrentFormRefFields(componentsToAdd); const response = service.resetCurrentFormRefFields(); expect(response).to.be.undefined; } @TestCase('should be able to setParentPicklistValueMap') setParentPicklistValueMap (service: ReferenceFieldsService) { service.setParentPicklistValueMap(this.parentFieldId, this.parentField.name); const response = service.parentPicklistValueMap; expect(response).contains({13: 'Parent picklist'}); } @TestCase('should be able to reset parent picklist value map') resetParentPicklistValueMap (service: ReferenceFieldsService) { const response = service.resetParentPicklistValueMap(); expect(response).to.be.undefined; } @TestCase('should be able to getReferenceFieldFromCompType') getReferenceFieldFromCompType (service: ReferenceFieldsService) { const type = `referenceFields-textfield`; const found = service.getReferenceFieldFromCompType(type); expect(found).to.not.be.undefined; expect(found.type).to.be.equal(ReferenceFieldsUI.ReferenceFieldTypes.TextField); } @TestCase('should be able to adaptFieldIdsForAutomation') async adaptFieldIdsForAutomation (service: ReferenceFieldsService) { const response = await service.adaptFieldIdsForAutomation([this.numberId]); expect(response.columns[0].label).to.be.equal(this.numberField.name); } @TestCase('should be able to getReferenceFieldsPaginated') async getReferenceFieldsPaginated (service: ReferenceFieldsService) { const options: PaginationOptions = { filterColumns: [{ columnName: 'key', filters: [{ filterValue: 'asdf', filterType: 'eq' }] }], orFilterColumns: [], rowsPerPage: 10, pageNumber: 1, sortColumns: [], retrieveTotalRecordCount: true, returnAll: false }; const response = await service.getReferenceFieldsPaginated(options); expect(response.success).to.be.equal(true); } @TestCase('should be able to getParentPicklistComp') getParentPicklistComp (service: ReferenceFieldsService) { const response = service.getParentPicklistComp(this.customDataTables[1], true); expect(response.defaultValue).to.be.equal(this.customDataTables[0].name); } @TestCase('should be able to getHideWithoutParentResponseComp') getHideWithoutParentResponseComp (service: ReferenceFieldsService) { const response = service.getHideWithoutParentResponseComp(true); expect(response.input).to.be.true; } @TestCase('should not be able to getHideWithoutParentResponseComp') doNotGetHideWithoutParentResponseComp (service: ReferenceFieldsService) { const response = service.getHideWithoutParentResponseComp(false); expect(response).to.be.undefined; } @TestCase('should be able to getInvalidDependencyText') getInvalidDependencyText (service: ReferenceFieldsService) { const response = service.getInvalidDependencyText(this.childField, this.parentField); expect(response).to.be.equal('Parent picklist Parent picklist found in the Category 1 category must be placed on the form prior to adding Child custom data table'); } @TestCase('should be able to handleDeleteCategory') async handleDeleteCategory (service: ReferenceFieldsService) { const response = await service.handleDeleteCategory(this.parentField.categoryId); expect(response); } @TestCase('should not be able to handleDeleteCategory') dontHandleDeleteCategory (service: ReferenceFieldsService) { const response = service.handleDeleteCategory(null); expect(response).to.throw; } @TestCase('should be able to handleMergeFields') async handleMergeFields (service: ReferenceFieldsService) { const mergeFormFieldsApiPayload = { referenceFieldId1: this.numberId, referenceFieldId2: this.radioId, customDataTableGuid: this.cdtGuid1, name: 'mergeFormFieldsApiPayload', description: 'mergeFormFieldsApiPayload', type: ReferenceFieldsUI.ReferenceFieldTypes.Number, key: 'merge-form-fields-api-payload', supportsMultiple: true, categoryId: 0, formAudience: FormAudience.MANAGER, priorityReferenceFieldId: 1 }; const response = await service.handleMergeFields(mergeFormFieldsApiPayload); expect(response).to.be.undefined; } @TestCase('should be able to getCategoryTokenGroups') getCategoryTokenGroups (service: ReferenceFieldsService) { const fieldPrefix = 'ReferenceField'; const usage: AdHocReportingUI.Usage = 1; const response = service.getCategoryTokenGroups(fieldPrefix, usage); expect(response[0].groupDisplay).to.be.equal('Category 2'); } @TestCase('should be able to formatCreateEditFieldModalReturn') async formatCreateEditFieldModalReturn (service: ReferenceFieldsService) { const response = await service.formatCreateEditFieldModalReturn( this.numberField, [this.numberTableFieldForUi] ); expect(response.field.key).to.be.equal(this.numberKey); } @TestCase('should be able to formatMergeModalReturn') async formatMergeModalReturn (service: ReferenceFieldsService) { const response = await service.formatMergeModalReturn( this.numberField, this.numberId, null, 0 ); expect(response.name).to.be.equal(this.numberField.name); } @TestCase('should be able to getDetailForFields (1)') async getDetailForField (service: ReferenceFieldsService) { const response = await service.getDetailForFields([this.numberField]); expect(response.length).to.be.equal(1); } @TestCase('should be able to getDetailForFields (all)') async getDetailForFields (service: ReferenceFieldsService) { spy.on(service['referenceFieldsResources'], 'getReferenceFieldDetail', () => { return { forms: [{ formId: 1, formRevisionId: 2, name: 'Form', formRevisionVersion: 1 }] }; }); await service.getDetailForFields(this.allReferenceFields); expect(service['referenceFieldsResources']['getReferenceFieldDetail']).to.have.been.called.exactly( this.allReferenceFields.length ); } @TestCase('should be able to getFormFieldOptionsByType') getFormFieldOptionsByType (service: ReferenceFieldsService) { const response = service.getFormFieldOptionsByType(this.numberField.type); expect(response[0].label).to.be.equal(this.numberField.name); } @TestCase('should be able to getAllAggregateFields') getAllAggregateFields (service: ReferenceFieldsService) { const response = service.getAllAggregateFields(); expect(response[0].name).to.be.equal('Aggregation field'); } @TestCase('should be able to getDisableSummarizeDataTooltip') getDisableSummarizeDataTooltip (service: ReferenceFieldsService) { const response = service.getDisableSummarizeDataTooltip( true, this.dataPointManager.referenceFieldTableId, this.numberId ); //testing with an empty string because no criteria fits to change the string expect(response).to.be.equal(''); } @TestCase('should be able to mapRowsForTable') mapRowsForTable (service: ReferenceFieldsService) { const response = service.mapRowsForTable( this.subsetTableResponseRows, this.subsetId ); expect(response[0].columns[0].referenceFieldKey).to.be.equal(this.numberKey); } @TestCase('should be able to getExistingFields') getExistingFields (service: ReferenceFieldsService) { const response = service.getExistingFields( [this.numberTableFieldForUi], [this.radioButtonField] ); expect(response).to.be.true; } @TestCase('should be able to convertCheckboxValueToNumber') convertCheckboxValueToNumber (service: ReferenceFieldsService) { const response = service.convertCheckboxValueToNumber(true); expect(response).to.be.equal(1); } @TestCase('should be able to convertNumberToCheckboxValue') convertNumberToCheckboxValue (service: ReferenceFieldsService) { const response = service.convertNumberToCheckboxValue(1); expect(response).to.be.equal(true); } @TestCase('should be able to formRefFieldToAutomationType') formRefFieldToAutomationType (service: ReferenceFieldsService) { const component: FormDefinitionComponent = { type: 'referenceFields-textarea', key: this.textAreaKey, label: 'Text Area' }; const response = service.formRefFieldToAutomationType(component); expect(response.label).to.be.equal(component.label); } @TestCase('should be able to handleCopyComponents') async handleCopyComponents (service: ReferenceFieldsService) { const component: FormDefinitionComponent = { type: 'referenceFields-textarea', key: this.textAreaKey, label: 'Text Area' }; const response = await service.handleCopyComponents([component]); expect(response[0].oldKey).to.be.equal('textarea'); } @TestCase('should be able to convertMergeFieldsToOneField') convertMergeFieldsToOneField (service: ReferenceFieldsService) { const response = service.convertMergeFieldsToOneField([this.numberField, this.textField]); expect(response); } @TestCase('should be able to getCanUpdateToSingleResponse') getCanUpdateToSingleResponse (service: ReferenceFieldsService) { service.setReferenceFieldMaps(); const response = service.getCanUpdateToSingleResponse(this.numberId); expect(response).to.not.throw; expect(response).to.not.be.undefined; } @TestCase('should be able to clearOutTableRowIdsForCopy') clearOutTableRowIdsForCopy (service: ReferenceFieldsService) { service.clearOutTableRowIdsForCopy(this.responses); expect(this.responses[0]).to.be.undefined; } @TestCase('should be able to clear out inactive cdt responses - string') clearOutInactiveCdtResponsesString (service: ReferenceFieldsService) { service.clearOutInactiveCdtResponses(this.responses); expect(this.responses[this.dataTable1Key]).to.be.equal(''); } @TestCase('should be able to clear out inactive cdt responses - array') clearOutInactiveCdtResponsesArray (service: ReferenceFieldsService) { const responses = { ...this.responses, [this.dataTable1Key]: ['2'] }; service.clearOutInactiveCdtResponses(responses); expect(responses[this.dataTable1Key]).to.deep.equal([]); } @TestCase('should be able to clear out inactive cdt responses - select boxes') clearOutInactiveCdtResponsesSelectBoxes (service: ReferenceFieldsService) { service.clearOutInactiveCdtResponses(this.responses); expect(this.responses[this.selectBoxesKey]).to.deep.equal(['4']); } @TestCase('should be able to ensureFormFieldFilesAreUploadedForCopy') async ensureFormFieldFilesAreUploadedForCopy (service: ReferenceFieldsService) { const responseInfo = { applicationId: this.appResponsesForMerge[0].applicationId, applicationFormId: 88, refChangeTracker: this.responses, referenceFields: this.responses }; const response = await service.ensureFormFieldFilesAreUploadedForCopy( responseInfo.applicationId, responseInfo.applicationFormId, responseInfo.refChangeTracker, responseInfo.referenceFields ); expect(response.refChangeTracker).to.be.equal(this.responses); } @TestCase('should be able to handleMergeWithStandardField') async handleMergeWithStandardField (service: ReferenceFieldsService) { const fieldIdsToMerge = [this.textFieldId, this.radioId]; expect(await service.handleMergeWithStandardField( this.numberId, fieldIdsToMerge )).to.not.throw; } @TestCase('should be able to adaptDataSetResponse') adaptDataSetResponse (service: ReferenceFieldsService) { const dataPoints = [{ value: this.numberField.referenceFieldId, summarizeData: false, summarizeLabel: 'data-point-number-field', referenceFieldId: this.numberId }, { value: this.textField.referenceFieldId, summarizeData: false, summarizeLabel: 'data-point-text-field', referenceFieldId: this.textFieldId }] as ReferenceFieldsUI.DataPointForUI[]; const response = service.adaptDataSetResponse(dataPoints); expect(response[0].referenceFieldId).to.be.equal(this.numberId); expect(response[1].referenceFieldId).to.be.equal(this.textFieldId); } @TestCase('should be able to get files from app ref field response') getFilesFromApplicationRefFieldResponse (service: ReferenceFieldsService) { const appId = 1; const appFormId = 2; const fileId = 3; const fileName = 'fileName.png'; const files: ReferenceFieldAPI.ApplicationRefFieldFile[] = [{ fileId, fileName, value: 'url' }]; const adaptedFiles = service.getFilesFromApplicationRefFieldResponse( files, 1, 2 ); const adaptedFile = adaptedFiles[0]; const expectedFileUrl = `https://yourcausegrantsqa.com/management/download-file?applicationId=${appId}&applicationFormId=${appFormId}&fileId=${fileId}&fileName=${fileName}`; expect(adaptedFile.fileUrl).to.be.equal(expectedFileUrl); } @TestCase('should be able to convert number field to text') async testConvertingTextFieldToNumber (service: ReferenceFieldsService) { spy.on(service['referenceFieldsResources'], 'convertNumberFieldToText', async () => { return true; }); await service.handleFieldTypeConversion(1, ReferenceFieldsUI.RefFieldConversionTypes.NUMBER_TO_TEXT); expect(service['referenceFieldsResources']['convertNumberFieldToText']).to.have.been.called.once; } @TestCase('should be able to convert text field to number') async testConvertingNumberFieldToText (service: ReferenceFieldsService) { spy.on(service['referenceFieldsResources'], 'convertTextFieldToNumber', async () => { return true; }); await service.handleFieldTypeConversion(1, ReferenceFieldsUI.RefFieldConversionTypes.TEXT_TO_NUMBER); expect(service['referenceFieldsResources']['convertTextFieldToNumber']).to.have.been.called.once; } @TestCase('should be able to convert date to text') async testConvertingDateToText (service: ReferenceFieldsService) { spy.on(service['referenceFieldsResources'], 'convertDateFieldToText', async () => { return true; }); await service.handleFieldTypeConversion(1, ReferenceFieldsUI.RefFieldConversionTypes.DATE_TO_TEXT); expect(service['referenceFieldsResources']['convertDateFieldToText']).to.have.been.called.once; } @TestCase('should be able to convert text field to date') async testConvertingTexttoDate (service: ReferenceFieldsService) { spy.on(service['referenceFieldsResources'], 'convertTextFieldToDate', async () => { return true; }); await service.handleFieldTypeConversion(1, ReferenceFieldsUI.RefFieldConversionTypes.TEXT_TO_DATE); expect(service['referenceFieldsResources']['convertTextFieldToDate']).to.have.been.called.once; } @TestCase('should be able to validate number field to text conversion') async testValidatingConvertingNumberfieldToText (service: ReferenceFieldsService) { spy.on(service['referenceFieldsResources'], 'convertNumberFieldToText', async () => { return true; }); await service.handleFieldTypeConversion(1, ReferenceFieldsUI.RefFieldConversionTypes.NUMBER_TO_TEXT); expect(service['referenceFieldsResources']['convertNumberFieldToText']).to.have.been.called.once; } @TestCase('should be able to validate text field to number conversion') async testValidatingConvertingTextrFieldToNumber (service: ReferenceFieldsService) { spy.on(service['referenceFieldsResources'], 'convertTextFieldToNumber', async () => { return true; }); await service.handleFieldTypeConversion(1, ReferenceFieldsUI.RefFieldConversionTypes.TEXT_TO_NUMBER); expect(service['referenceFieldsResources']['convertTextFieldToNumber']).to.have.been.called.once; } @TestCase('should be able to check can be multi') canBeMulti (service: ReferenceFieldsService) { let canBe = service.canBeMulti(ReferenceFieldsUI.ReferenceFieldTypes.Checkbox); expect(canBe).to.be.false; canBe = service.canBeMulti(ReferenceFieldsUI.ReferenceFieldTypes.Number); expect(canBe).to.be.false; canBe = service.canBeMulti(ReferenceFieldsUI.ReferenceFieldTypes.Date); expect(canBe).to.be.false; canBe = service.canBeMulti(ReferenceFieldsUI.ReferenceFieldTypes.Currency); expect(canBe).to.be.false; canBe = service.canBeMulti(ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable); expect(canBe).to.be.true; canBe = service.canBeMulti(ReferenceFieldsUI.ReferenceFieldTypes.SelectBoxes); expect(canBe).to.be.true; canBe = service.canBeMulti(ReferenceFieldsUI.ReferenceFieldTypes.FileUpload); expect(canBe).to.be.true; canBe = service.canBeMulti(ReferenceFieldsUI.ReferenceFieldTypes.TextArea); expect(canBe).to.be.true; } @TestCase('should be able to get show supports multi checkbox') showSupportsMultiCheckbox (service: ReferenceFieldsService) { let canBe = service.showSupportsMultiCheckbox(ReferenceFieldsUI.ReferenceFieldTypes.Checkbox); expect(canBe).to.be.false; canBe = service.showSupportsMultiCheckbox(ReferenceFieldsUI.ReferenceFieldTypes.Number); expect(canBe).to.be.false; canBe = service.showSupportsMultiCheckbox(ReferenceFieldsUI.ReferenceFieldTypes.Date); expect(canBe).to.be.false; canBe = service.showSupportsMultiCheckbox(ReferenceFieldsUI.ReferenceFieldTypes.Currency); expect(canBe).to.be.false; canBe = service.showSupportsMultiCheckbox(ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable); expect(canBe).to.be.true; canBe = service.showSupportsMultiCheckbox(ReferenceFieldsUI.ReferenceFieldTypes.SelectBoxes); expect(canBe).to.be.false; canBe = service.showSupportsMultiCheckbox(ReferenceFieldsUI.ReferenceFieldTypes.FileUpload); expect(canBe).to.be.true; canBe = service.showSupportsMultiCheckbox(ReferenceFieldsUI.ReferenceFieldTypes.TextArea); expect(canBe).to.be.true; } @TestCase('should be able to get blank form value - file') getBlankValueForFormFieldFile (service: ReferenceFieldsService) { const blankFile = service.getBlankValueForFormField( this.fileUpload, {} as FormDefinitionComponent, false ); // file(s) are always stored in array format expect(blankFile).to.deep.equal([]); } @TestCase('should be able to get blank form value - text multi') getBlankValueForFormFieldTextMulti (service: ReferenceFieldsService) { const blankMultiText = service.getBlankValueForFormField( this.textField, {} as FormDefinitionComponent, false ); expect(blankMultiText).to.deep.equal(['']); } @TestCase('should be able to get blank form value - text single') getBlankValueForFormFieldTextSingle (service: ReferenceFieldsService) { const textSingle = service.getBlankValueForFormField( this.textArea, {} as FormDefinitionComponent, false ); expect(textSingle).to.deep.equal(''); } @TestCase('should be able to get blank form value - currency') getBlankValueForFormFieldCurrency (service: ReferenceFieldsService) { const currencyVal = service.getBlankValueForFormField( this.currencyField, {} as FormDefinitionComponent, false ); expect((currencyVal as CurrencyValue).currency).to.be.equal('USD'); const noAmounts = (currencyVal as CurrencyValue).amountEquivalent === null && (currencyVal as CurrencyValue).amountInDefaultCurrency === null && (currencyVal as CurrencyValue).amountForControl === 0; expect(noAmounts).to.be.true; } @TestCase('should be able to get blank form value - radio') getBlankValueForFormFieldRadio (service: ReferenceFieldsService) { const defaultVal = 'blue'; const val = service.getBlankValueForFormField( this.radioButtonField, { defaultVal } as FormDefinitionComponent, true ); expect(val).to.be.equal(defaultVal); } @TestCase('should be able to validate field type conversion - text to number') async validateFieldTypeConversionTextToNumber (service: ReferenceFieldsService) { spy.on(service['referenceFieldsResources'], 'validateTextToNumberFieldConversion', async () => {}); await service.validateFieldTypeConversion(1, ReferenceFieldsUI.RefFieldConversionTypes.TEXT_TO_NUMBER); expect(service['referenceFieldsResources']['validateTextToNumberFieldConversion']).to.have.been.called.once; } @TestCase('should be able to validate field type conversion - text to date') async validateFieldTypeConversionTextToDate (service: ReferenceFieldsService) { spy.on(service['referenceFieldsResources'], 'validateTextToDateFieldConversion', async () => {}); await service.validateFieldTypeConversion(1, ReferenceFieldsUI.RefFieldConversionTypes.TEXT_TO_DATE); expect(service['referenceFieldsResources']['validateTextToDateFieldConversion']).to.have.been.called.once; } @TestCase('should be able to validate field type conversion - date to text') async validateFieldTypeConversionDateToText (service: ReferenceFieldsService) { spy.on(service['referenceFieldsResources'], 'validateDateToTextFieldConversion', async () => {}); await service.validateFieldTypeConversion(1, ReferenceFieldsUI.RefFieldConversionTypes.DATE_TO_TEXT); expect(service['referenceFieldsResources']['validateDateToTextFieldConversion']).to.have.been.called.once; } @TestCase('should be able to validate field type conversion - number to text') async validateFieldTypeConversionNumberToText (service: ReferenceFieldsService) { spy.on(service['referenceFieldsResources'], 'validateNumberToTextFieldConversion', async () => {}); await service.validateFieldTypeConversion(1, ReferenceFieldsUI.RefFieldConversionTypes.NUMBER_TO_TEXT); expect(service['referenceFieldsResources']['validateNumberToTextFieldConversion']).to.have.been.called.once; } }