import { Injectable } from '@angular/core'; import { CLIENT_SETTINGS_SERVICE_MOCK } from '@core/mocks/client-settings.service.mock'; import { FormExportMock } from '@core/mocks/form-export.mock'; import { GCMockModule } from '@core/mocks/gc-module.mock'; import { ReferenceFieldAPI } from '@core/typings/api/reference-fields.typing'; import { ViewTranslationsBlank } from '@core/typings/translation.typing'; import { ReferenceFieldsUI } from '@core/typings/ui/reference-fields.typing'; import { BasicForm, ExportFormResponse, FormAudience, FormStates, FormTypes } from '@features/configure-forms/form.typing'; import { FormsService } from '@features/configure-forms/services/forms/forms.service'; import { StandardFormTemplate } from '@features/platform-admin/standard-product-configuration/standard-product-configuration.typing'; import { Column } from '@yourcause/common'; import { AfterEach, BeforeEach, Spec, TestCase } from '@yourcause/test-decorators'; import { DescribeAngularService } from '@yourcause/test-decorators/angular'; import { expect, spy } from 'chai'; @Injectable({ providedIn: 'root' }) @DescribeAngularService(FormsService, { imports: [ GCMockModule ], providers: [ CLIENT_SETTINGS_SERVICE_MOCK ] }) export class FormsServiceSpec implements Spec { uniqueId = '1234'; cdtGuid1 = 'guid1'; cdtGuid2 = 'guid2'; cdtGuid3 = 'guid3'; draftApplicantForm: BasicForm = { availableForTranslation: false, defaultLanguageId: 'es-MX', revisions: [], name: 'z2.10', description: 'Test Form', createdDate: '2018-12-14T18:06:44.6263801Z', updatedDate: '2018-12-14T18:22:30.3521994Z', revisionId: 2439, revisionVersion: 1, formId: 46342, formType: FormTypes.REQUEST, canModify: false, canBeRemoved: true, programIds: [], standardComponentIsPublished: false, isDraft: true }; publishedApplicantForm: BasicForm = { availableForTranslation: false, defaultLanguageId: 'es-MX', revisions: [], name: 'z2.10', description: 'Test Form', createdDate: '2018-12-14T18:06:44.6263801Z', updatedDate: '2018-12-14T18:22:30.3521994Z', revisionId: 23001, revisionVersion: 1, formId: 436433, formType: FormTypes.REQUEST, canModify: false, canBeRemoved: true, programIds: [], standardComponentIsPublished: false, isDraft: false }; publishedApplicantForm2: BasicForm = { revisions: [{ formRevisionId: 13305, version: 1, createdDate: '2018-12-14T21:57:04.457719Z', updatedDate: '2018-12-14T22:14:21.6561779Z', formId: 9420, revisionCanBeRemoved: false }], availableForTranslation: false, defaultLanguageId: null, name: 'Applicant form', description: '', createdDate: '2018-12-14T22:43:32.7029393Z', updatedDate: '2018-12-14T22:43:42.1987871Z', revisionId: 13314, revisionVersion: 2, formId: 9420, formType: FormTypes.ELIGIBILITY, canModify: false, canBeRemoved: false, programIds: [], standardComponentIsPublished: false, isDraft: false }; publishedManagerForm3: BasicForm = { revisions: [{ formRevisionId: 13354, version: 1, createdDate: '2018-12-15T17:26:57.1427708Z', updatedDate: '2018-12-15T17:28:31.7821327Z', formId: 13054, revisionCanBeRemoved: false }], availableForTranslation: false, defaultLanguageId: null, name: 'Manager form', description: '', createdDate: '2018-12-17T15:54:52.2184816Z', updatedDate: '2018-12-17T15:55:03.6043116Z', revisionId: 13479, revisionVersion: 2, formId: 13054, formType: FormTypes.REVIEW, canModify: false, canBeRemoved: false, programIds: [], standardComponentIsPublished: false, isDraft: false }; draftRoutingForm: BasicForm = { revisions: [{ formRevisionId: 54322, version: 1, createdDate: '2018-12-15T17:26:57.1427708Z', updatedDate: '2018-12-15T17:28:31.7821327Z', formId: 13054, revisionCanBeRemoved: false }], availableForTranslation: false, defaultLanguageId: null, name: 'Routing form', description: '', createdDate: '2018-12-17T15:54:52.2184816Z', updatedDate: '2018-12-17T15:55:03.6043116Z', revisionId: 134792, revisionVersion: 2, formId: 543343, formType: FormTypes.ROUTING, canModify: false, canBeRemoved: false, programIds: [], standardComponentIsPublished: false, isDraft: true }; publishedRoutingForm: BasicForm = { revisions: [{ formRevisionId: 54322, version: 1, createdDate: '2018-12-15T17:26:57.1427708Z', updatedDate: '2018-12-15T17:28:31.7821327Z', formId: 13054, revisionCanBeRemoved: false }], availableForTranslation: false, defaultLanguageId: null, name: 'Routing form', description: '', createdDate: '2018-12-17T15:54:52.2184816Z', updatedDate: '2018-12-17T15:55:03.6043116Z', revisionId: 13479, revisionVersion: 2, formId: 54334, formType: FormTypes.ROUTING, canModify: false, canBeRemoved: false, programIds: [], standardComponentIsPublished: false, isDraft: false }; draftForms = [ this.draftApplicantForm, this.draftRoutingForm ]; publishedForms = [ this.publishedApplicantForm, this.publishedApplicantForm2, this.publishedManagerForm3, this.publishedRoutingForm ]; allForms = [ ...this.draftForms, ...this.publishedForms ]; standardFormTemplates: StandardFormTemplate[] = [{ name: 'Standard Request Form', description: '', createdDate: '', updatedDate: '', revisionId: 124, revisionVersion: 1, formId: 235, formTypeId: FormTypes.REQUEST, defaultLanguageId: 'en-US' }]; numberField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: 2353, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Number', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Number, key: 'number', supportsMultiple: false, categoryId: 3, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; maskedField = { ...this.numberField, isMasked: true, key: 'maskedNumber', type: ReferenceFieldsUI.ReferenceFieldTypes.Checkbox, referenceFieldId: 23533 }; encryptedTextField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { 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: 'encrypted', supportsMultiple: false, categoryId: 2, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; tableField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: 444, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: '', name: 'Table field', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Table, key: 'table', supportsMultiple: false, categoryId: null, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; managerField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: true, aggregateType: null, referenceFieldId: 23523, parentReferenceFieldId: null, formCount: 1, usedOnReports: false, createdBy: '', createDate: '', updateDate: '', updatedBy: '', customDataTableGuid: '', name: 'Manager Text Field', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.TextField, key: 'managerField', supportsMultiple: false, categoryId: 2, formAudience: FormAudience.MANAGER, isSingleResponse: false, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; myFormIds = [this.publishedApplicantForm.formId, this.publishedManagerForm3.formId]; @BeforeEach() async mock (service: FormsService) { service['formResources'].getForms = async () => { return this.allForms; }; service['formResources'].getFormsSegmented = async () => { return this.myFormIds; }; service.setFormTypes(); await service.prepareForms(); service.setStandardFormTemplates([]); service['translationService'].setViewTranslationsOnState(ViewTranslationsBlank); service['referenceFieldService'].setAllReferenceFields([ this.numberField, this.encryptedTextField, this.tableField, this.managerField, this.maskedField ]); } @AfterEach() restore () { spy.restore(); } @TestCase('should be able to set standard form templates') setStandardFormTemplates (service: FormsService) { service.setStandardFormTemplates(this.standardFormTemplates); expect(service.standardFormTemplates).to.deep.equal(this.standardFormTemplates); } @TestCase('should be able to set loaded') setLoaded (service: FormsService) { service.setLoaded(false); expect(service.loaded).to.be.equal(false); service.setLoaded(true); expect(service.loaded).to.be.equal(true); } @TestCase('should be able to set draft forms') setDraftForms (service: FormsService) { service.setDraftForms([]); expect(service.draft).to.deep.equal([]); const draftForms: BasicForm[] = [{ name: 'Draft', formId: 134, revisionId: 235 } as BasicForm]; service.setDraftForms(draftForms); expect(service.draft).to.deep.equal(draftForms); } @TestCase('should be able to set published forms') setPublishedForms (service: FormsService) { service.setPublishedForms([]); expect(service.published).to.deep.equal([]); const publishedForms: BasicForm[] = [{ name: 'Published', formId: 134, revisionId: 235 } as BasicForm]; service.setPublishedForms(publishedForms); expect(service.published).to.deep.equal(publishedForms); } @TestCase('should be able to get form type options') getFormTypeOptions (service: FormsService) { const options = service.getFormTypeOptions(); const hasReview = options.some((opt) => { return opt.value === FormTypes.REVIEW; }); expect(hasReview).to.be.equal(true); const hasRequest = options.some((opt) => { return opt.value === FormTypes.REQUEST; }); expect(hasRequest).to.be.equal(true); } @TestCase('should be able to refresh forms') async refreshForms (service: FormsService) { service.setPublishedForms([]); service.setDraftForms([]); await service.refreshForms(); expect(service.published).to.deep.equal(this.publishedForms); } @TestCase('should be able to get form type from form id') getFormTypeFromFormId (service: FormsService) { const type = service.getFormTypeFromFormId(this.publishedApplicantForm.formId); expect(type).to.be.equal(FormTypes.REQUEST); } @TestCase('should be able to set forms') setForms (service: FormsService) { service.setForms([this.draftApplicantForm], this.publishedForms); const foundDraft = service.forms.find((form) => { return form.formId === this.draftApplicantForm.formId; }); expect(foundDraft.state).to.be.equal(FormStates.DRAFT); const foundPublished = service.forms.find((form) => { return form.formId === this.publishedApplicantForm.formId; }); expect(foundPublished.state).to.be.equal(FormStates.PUBLISHED); } @TestCase('should be able to prepare forms') async prepareForms (service: FormsService) { service.setLoaded(false); let gotForms = false; let setOptions = false; service['getAndSetForms'] = async () => { gotForms = true; }; service['setFormOptions'] = async () => { setOptions = true; }; await service.prepareForms(); expect(gotForms).to.be.true; expect(setOptions).to.be.true; } @TestCase('should be able to prepare form types') prepareFormTypes (service: FormsService) { service.prepareFormTypes(); const hasFormTypes = service.formTypes.length > 0; const hasFormTypeMap = Object.keys(service.formTypeMap).length > 0; expect(hasFormTypes).to.be.true; expect(hasFormTypeMap).to.be.true; } @TestCase('should be able to set form options - applicant form options') async setFormOptionsApplicant (service: FormsService) { await service.setFormOptions(); const expectedApplicantFormIds = [ this.publishedApplicantForm.formId, this.publishedApplicantForm2.formId, this.publishedRoutingForm.formId ]; const applicantFormOptionIds = service.applicantFormOptions.map((opt) => { return opt.value; }); expect(service.applicantFormOptions.length).to.be.equal(expectedApplicantFormIds.length); const hasAll = expectedApplicantFormIds.every((id) => { return applicantFormOptionIds.includes(id); }); expect(hasAll).to.be.true; } @TestCase('should be able to set form options - manager form options') async setFormOptionsManager (service: FormsService) { await service.setFormOptions(); const expectedManagerFormIds = [ this.publishedManagerForm3.formId ]; const managerFormOptionIds = service.managerFormOptions.map((opt) => { return opt.value; }); expect(service.managerFormOptions.length).to.be.equal(expectedManagerFormIds.length); const hasAll = expectedManagerFormIds.every((id) => { return managerFormOptionIds.includes(id); }); expect(hasAll).to.be.true; } @TestCase('should be able to get audience from form type') getAudienceFromFormType (service: FormsService) { const audience = service.getAudienceFromFormType(FormTypes.REQUEST); expect(audience).to.be.equal(FormAudience.APPLICANT); } @TestCase('should be able to get is manager form') isManagerForm (service: FormsService) { let isManagerForm = service.isManagerForm(this.draftApplicantForm.formId); expect(isManagerForm).to.be.false; isManagerForm = service.isManagerForm(this.publishedManagerForm3.formId); expect(isManagerForm).to.be.true; } @TestCase('should be able to get default lang from form ID') getDefaultLangFromFormId (service: FormsService) { const lang = service.getDefaultLangFromFormId(this.publishedApplicantForm.formId); expect(lang).to.be.equal(this.publishedApplicantForm.defaultLanguageId); } @TestCase('should be able to get most common default from lang array') getMostCommonDefaultLangFromArray (service: FormsService) { let calledTranslationFunc = false; service['translationService']['getMostCommonDefaultLangFromArray'] = () => { calledTranslationFunc = true; return 'es-MX'; }; service.getMostCommonDefaultLangFromArray([this.publishedApplicantForm.formId]); expect(calledTranslationFunc).to.be.true; } @TestCase('should be able to get lastest revision id') getLatestRevisionId (service: FormsService) { const latestRevisionId = service.getLatestRevisionId( this.publishedForms[0].formId, true ); expect(latestRevisionId).to.be.equal(this.publishedForms[0].revisionId); } @TestCase('should be able to get lastest revision id - template') getLatestRevisionIdTemplate (service: FormsService) { service.setStandardFormTemplates(this.standardFormTemplates); const latestRevisionId = service.getLatestRevisionId( this.standardFormTemplates[0].formId, true ); expect(latestRevisionId).to.be.equal(this.standardFormTemplates[0].revisionId); } @TestCase('should be able to get revision options') getFormRevisionOptions (service: FormsService) { const options = service.getFormRevisionOptions( this.publishedForms[1].formId, true, false ); expect(options.length).to.be.equal(2); expect( options.some((opt) => opt.value === this.publishedForms[1].revisionId) ).to.be.true; } @TestCase('should be able to get revision options - doNotAllowUpdateCurrentRevision') getFormRevisionOptionsDoNotAllow (service: FormsService) { const doNotAllowUpdateCurrentRevision = true; const options = service.getFormRevisionOptions( this.publishedApplicantForm.formId, true, doNotAllowUpdateCurrentRevision ); expect(options.length).to.be.equal(1); expect(options[0].value).to.be.equal(this.publishedApplicantForm.revisionId); } @TestCase('should be able to get isEligibilityForm') getIsEligibilityForm (service: FormsService) { let isEligibility = service.getIsEligibilityForm(this.publishedApplicantForm.formId); expect(isEligibility).to.be.false; isEligibility = service.getIsEligibilityForm(this.publishedApplicantForm2.formId); expect(isEligibility).to.be.true; } @TestCase('should be able to get routing form options') getRoutingFormOptions (service: FormsService) { const forms = service.getRoutingFormOptions(); // should only return published one expect(forms.length).to.be.equal(1); const hasForm = forms.some((form) => { return form.value === this.publishedRoutingForm.formId; }); expect(hasForm).to.be.true; } @TestCase('should be able to handle remove revision') async handleRemoveRevision (service: FormsService) { spy.on(service['formResources'], 'deleteRevision', async () => {}); spy.on(service['formResources'], 'deleteAllRevisionsOfForm', async () => {}); spy.on(service, 'refreshForms'); spy.on(service['referenceFieldService'], 'resetFieldsAndCategories', async () => {}); await service.handleRemoveFormOrRevision( this.publishedApplicantForm.formId, this.publishedApplicantForm.revisionId, true ); expect(service['formResources']['deleteRevision']).to.have.been.called.once; expect(service['formResources']['deleteAllRevisionsOfForm']).to.not.have.been.called; expect(service['refreshForms']).to.have.been.called.once; expect(service['referenceFieldService']['resetFieldsAndCategories']).to.have.been.called.once; } @TestCase('should be able to handle remove form') async handleRemoveForm (service: FormsService) { spy.on(service['formResources'], 'deleteRevision', async () => {}); spy.on(service['formResources'], 'deleteAllRevisionsOfForm', async () => {}); spy.on(service, 'refreshForms'); spy.on(service['referenceFieldService'], 'resetFieldsAndCategories', async () => {}); await service.handleRemoveFormOrRevision( this.publishedApplicantForm.formId, this.publishedApplicantForm.revisionId, false ); expect(service['formResources']['deleteAllRevisionsOfForm']).to.have.been.called.once; expect(service['formResources']['deleteRevision']).to.not.have.been.called; expect(service['refreshForms']).to.have.been.called.once; expect(service['referenceFieldService']['resetFieldsAndCategories']).to.have.been.called.once; } @TestCase('should be able to handle remove form - fail program') async handleRemoveFormFail (service: FormsService) { let errorMessage = ''; spy.on(service['notifier'], 'error', (_err) => { errorMessage = _err; }); spy.on(service['formResources'], 'deleteRevision', async () => { // eslint-disable-next-line no-throw-literal throw { error: { message: 'This form is currently tied to the following Grant Program(s)' } }; }); await service.handleRemoveFormOrRevision( this.publishedApplicantForm.formId, this.publishedApplicantForm.revisionId, true ); expect(errorMessage).to.be.equal('This form cannot be removed because it is tied to a grant program'); } @TestCase('should be able to handle remove form - fail other') async handleRemoveFormFailOther (service: FormsService) { let errorMessage = ''; spy.on(service['notifier'], 'error', (_err) => { errorMessage = _err; }); spy.on(service['formResources'], 'deleteRevision', async () => { // eslint-disable-next-line no-throw-literal throw { error: { message: 'error' } }; }); await service.handleRemoveFormOrRevision( this.publishedApplicantForm.formId, this.publishedApplicantForm.revisionId, true ); expect(errorMessage).to.be.equal('There was an error removing your revision'); } @TestCase('should be able to export forms - pass') async exportForms (service: FormsService) { spy.on(service['formResources'], 'exportForms', async () => { return [{ id: 1, name: 'Form name' }]; }); spy.on(service['fileService'], 'downloadRaw', () => {}); const formsToExport = [{ formId: 1, revisionId: 2 }]; await service.exportForms(formsToExport); expect(service['formResources']['exportForms']).to.have.been.called.once; expect(service['fileService']['downloadRaw']).to.have.been.called.once; } @TestCase('should be able to export forms - error') async exportFormsError (service: FormsService) { spy.on(service['notifier'], 'error'); spy.on(service['formResources'], 'exportForms', async () => { // eslint-disable-next-line no-throw-literal throw { error: { message: 'error' } }; }); spy.on(service['fileService'], 'downloadRaw', () => {}); const formsToExport = [{ formId: 1, revisionId: 2 }]; await service.exportForms(formsToExport); expect(service['formResources']['exportForms']).to.have.been.called.once; expect(service['fileService']['downloadRaw']).to.not.have.been.called; expect(service['notifier']['error']).to.have.been.called.once; } @TestCase('should be able to parse form export') parseFormExport (service: FormsService) { const parsed: ExportFormResponse[] = service.parseFormExport(FormExportMock); expect(parsed.length).to.be.equal(1); expect(parsed[0].id).to.be.equal(157584); } @TestCase('should be able to parse form export - fail') parseFormExportFail (service: FormsService) { spy.on(service['notifier'], 'error'); service.parseFormExport(''); expect(service['notifier']['error']).to.have.been.called.once; } @TestCase('should be able to import forms - pass') async importForms (service: FormsService) { spy.on(service['formResources'], 'importForms', async () => {}); spy.on(service, 'refreshForms'); spy.on(service['referenceFieldService'], 'resetFieldsAndCategories', async () => {}); await service.importForms(FormExportMock); expect(service['formResources']['importForms']).to.have.been.called.once; expect(service['refreshForms']).to.have.been.called.once; expect(service['referenceFieldService']['resetFieldsAndCategories']).to.have.been.called.once; } @TestCase('should be able to import forms - fail') async importFormsFail (service: FormsService) { spy.on(service['notifier'], 'error'); spy.on(service['formResources'], 'importForms', async () => { // eslint-disable-next-line no-throw-literal throw { error: { message: 'error' } }; }); spy.on(service, 'refreshForms'); spy.on(service['referenceFieldService'], 'resetFieldsAndCategories', async () => {}); await service.importForms(FormExportMock); expect(service['formResources']['importForms']).to.have.been.called.once; expect(service['refreshForms']).to.not.have.been.called; expect(service['referenceFieldService']['resetFieldsAndCategories']).to.not.have.been.called; expect(service['notifier']['error']).to.have.been.called.once; } @TestCase('should be able to get programs related to form') async getProgramsRelatedToForm (service: FormsService) { service['translationService']['set']('viewTranslations', { ...ViewTranslationsBlank, Grant_Program: { 1: { Name: 'Program 1', Description: '', Eligibility_Fail_Message: '', Eligibility_Pass_Message: '', Charity_Bucket_Description: '' }, 2: { Name: 'Program 2', Description: '', Eligibility_Fail_Message: '', Eligibility_Pass_Message: '', Charity_Bucket_Description: '' } } }); spy.on(service['formResources'], 'getProgramsRelatedToForm', async () => { return [1, 2]; }); const progs = await service.getProgramsRelatedToForm(1); expect(progs).to.deep.equal(['Program 1', 'Program 2']); } @TestCase('should be able to handle publish form') async handlePublishForm (service: FormsService) { spy.on(service['confirmAndTakeActionService'], 'confirmAndTakeAction', async () => { return { passed: true, endpointResponse: null }; }); await service.handlePublishForm(1, 2, 'Form'); expect(service['confirmAndTakeActionService']['confirmAndTakeAction']).to.have.been.called.once; } @TestCase('should be able to get form from form id') getFormFromId (service: FormsService) { const form = service.getFormFromId(this.publishedManagerForm3.formId); expect(form.name).to.be.equal(this.publishedManagerForm3.name); expect(form.formId).to.be.equal(this.publishedManagerForm3.formId); } @TestCase('should be able to get forms with single repsonse fields') async getGmFormsWithSingleResponseFields (service: FormsService) { spy.on(service['formResources'], 'getGmFormsWithSingleResponseFields', async () => { return []; }); await service.getGmFormsWithSingleResponseFields(); expect(service['formResources']['getGmFormsWithSingleResponseFields']).to.have.been.called.once; } @TestCase('should be able to set my dependent form filter options') async setMyDependentFormFilterOptions (service: FormsService) { spy.on(service, 'prepareForms'); spy.on(service['formResources'], 'getMyFormsWithFieldDetails', async () => { return [{ formId: 1, referenceFieldIds: [ this.numberField.referenceFieldId, this.tableField.referenceFieldId, this.encryptedTextField.referenceFieldId, this.managerField.referenceFieldId, this.maskedField.referenceFieldId ] }]; }); await service.setMyDependentFormFilterOptions(); expect(service['prepareForms']).to.have.been.called.once; expect(service['formResources']['getMyFormsWithFieldDetails']).to.have.been.called.once; const options = service.myDependentFormFilteringOptions; // 1 Form expect(options.length).to.be.equal(1); const columnOpts = options[0].value.dependentColumnOptions; // Encrypted, table field, masked field, and manager field should have been filtered out expect(columnOpts.length).to.be.equal(1); const hasMyOpt = columnOpts[0].value.prop === ('' + this.numberField.referenceFieldId); expect(hasMyOpt).to.be.true; } @TestCase('should be able to get ref field column - on selected as filter') getRefFieldColumn (service: FormsService) { spy.on(service['referenceFieldService'], 'getCdtOptionsFromRefField', async () => {}); const col = service.getRefFieldColumn( this.numberField ); const column = { prop: this.numberField.referenceFieldId + '' } as Column; col.onSelectedAsFilter(column); expect(service['referenceFieldService']['getCdtOptionsFromRefField']).to.have.been.called.once; } @TestCase('should be able to get all form options') allFormOptions (service: FormsService) { const allFormOptionIds = service.allPublishedFormOptions.map((opt) => opt.value); const allFormIds = this.publishedForms.map((form) => form.formId); expect(allFormOptionIds.sort()).to.deep.equal(allFormIds.sort()); } @TestCase('should be able to get my form options') getMyFormOptions (service: FormsService) { const myFormOptionIds = service.myFormOptions.map((opt) => opt.value); expect(myFormOptionIds.sort()).to.deep.equal(this.myFormIds.sort()); } @TestCase('should be able to get my manager form options') myManagerFormOptions (service: FormsService) { const myManagerFormIds = this.myFormIds.filter((id) => id !== this.publishedApplicantForm.formId); const myManagerFormOptIds = service.myManagerFormOptions.map((opt) => opt.value); expect(myManagerFormOptIds.sort()).to.deep.equal(myManagerFormIds.sort()); } @TestCase('should be able to get my applicant form options') myApplicantFormOptions (service: FormsService) { const myApplicantFormIds = this.myFormIds.filter((id) => id !== this.publishedManagerForm3.formId); const myApplicantFormOptIds = service.myApplicantFormOptions.map((opt) => opt.value); expect(myApplicantFormOptIds.sort()).to.deep.equal(myApplicantFormIds.sort()); } @TestCase('should be able to get all form options') getAllFormOptions (service: FormsService) { const allFormOptionIds = service.allFormOptions.map((opt) => opt.value); const allFormIds = this.allForms.map((form) => form.formId); expect(allFormIds.sort()).to.deep.equal(allFormOptionIds.sort()); } }