import { Injectable } from '@angular/core'; import { ComponentFixture } from '@angular/core/testing'; import { GCMockModule } from '@core/mocks/gc-module.mock'; import { ClientSettings } from '@core/typings/api/admin-client.typing'; import { ReferenceFieldAPI } from '@core/typings/api/reference-fields.typing'; import { ReferenceFieldsUI } from '@core/typings/ui/reference-fields.typing'; import { FormAudience } from '@features/configure-forms/form.typing'; import { CustomDataTable, PicklistDataType } from '@features/custom-data-tables/custom-data-tables.typing'; import { AsTypePipe } from '@yourcause/common'; import { AfterEach, BeforeEach, Spec, TestCase } from '@yourcause/test-decorators'; import { DescribeAngularComponent } from '@yourcause/test-decorators/angular'; import { expect, spy } from 'chai'; import { DoesRefHaveDependencyPipe } from '../pipes/does-ref-have-dependency.pipe'; import { DoesRefTypeHaveOptionsPipe } from '../pipes/does-ref-type-have-options.pipe'; import { CreateEditReferenceFieldComponent } from './create-edit-reference-field.component'; @Injectable({ providedIn: 'root' }) @DescribeAngularComponent(CreateEditReferenceFieldComponent, { imports: [ GCMockModule ], declarations: [ DoesRefTypeHaveOptionsPipe, DoesRefHaveDependencyPipe, AsTypePipe ] }) export class CreateEditReferenceFieldComponentSpec implements Spec< CreateEditReferenceFieldComponentSpec, ComponentFixture > { textId = 123; textKey = 'textKey'; textField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { customDataTableGuid: '', parentReferenceFieldId: null, name: 'Text field', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.TextField, formatType: ReferenceFieldAPI.ReferenceFieldFormattingType.EMAIL, key: this.textKey, supportsMultiple: false, categoryId: null, formAudience: FormAudience.APPLICANT, aggregateType: null, isSingleResponse: true, isEncrypted: false, isMasked: false, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, isStandardProductField: false, standardComponentIsPublished: false, subsetCollectionType: null, referenceFieldId: this.textId, formCount: 1, usedOnReports: true, createdBy: '', createDate: '', updatedBy: '', updateDate: '' }; parentFieldId = 575; aggregateFieldId = 787; aggregateFieldKey = 'aggregateFieldKey'; parentFieldKey = 'parentFieldKey'; multiPicklistId = 375; singleParentPicklistId = 765; multiPicklistKey = 'multiPicklistKey'; singlePicklistParentKey = 'singlePicklistParentKey'; cdtId1 = 1; cdtId2 = 2; cdtId3 = 3; cdtGuid1 = 'guid1'; cdtGuid2 = 'guid2'; cdtGuid3 = 'guid3'; multiPicklist: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.cdtId2, parentReferenceFieldId: this.singleParentPicklistId, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: this.cdtGuid2, name: 'Multi Custom data table', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable, key: this.multiPicklistKey, supportsMultiple: true, categoryId: null, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; singlePicklistParent: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.singleParentPicklistId, parentReferenceFieldId: null, formCount: 0, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: this.cdtGuid1, name: 'Parent Custom data table', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable, key: this.singlePicklistParentKey, supportsMultiple: false, categoryId: null, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; parentAggregateField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.parentFieldId, parentReferenceFieldId: null, formCount: 1, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: null, name: 'Number', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Number, key: this.parentFieldKey, supportsMultiple: false, categoryId: null, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; aggregateField: ReferenceFieldAPI.ReferenceFieldDisplayModel = { isEncrypted: false, isMasked: false, aggregateType: null, referenceFieldId: this.aggregateFieldId, parentReferenceFieldId: this.parentFieldId, formCount: 1, usedOnReports: false, createdBy: '', createDate: '', updatedBy: '', updateDate: '', customDataTableGuid: null, name: 'Aggregate', description: '', type: ReferenceFieldsUI.ReferenceFieldTypes.Aggregate, key: this.aggregateFieldKey, supportsMultiple: false, categoryId: null, formAudience: FormAudience.APPLICANT, isSingleResponse: true, tableAllowsImport: false, isTableField: false, aggregateTableReferenceFieldId: null, referenceFieldTableId: null, standardComponentIsPublished: true, isStandardProductField: false, subsetCollectionType: null }; 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 }]; allReferenceFields: ReferenceFieldAPI.ReferenceFieldDisplayModel[] = [ this.textField, this.multiPicklist, this.singlePicklistParent, this.aggregateField, this.parentAggregateField ]; /** * Component @Inputs that can be modified and will be set when mock is called */ existingReferenceField: ReferenceFieldAPI.ReferenceFieldDisplayModel; addingFieldToForm = false; forcedAudienceSelection: FormAudience = null; forceIsTableField = false; forceIsDataPoint = false; pendingKeyToBeCreated: string; uniqueKeys: string[]; existingKeys: string[]; lockFormatType: boolean; isViewOnly = false; lockCollectionType: boolean; tableImportNotAllowed: boolean; isMerge: boolean; @BeforeEach() async setupData ({ componentInstance }: ComponentFixture) { componentInstance['clientSettingsService']['set']('clientSettings', {} as ClientSettings); componentInstance['referenceFieldService']['referenceFieldsResources'].searchReferenceFields = async () => { return { records: this.allReferenceFields, recordCount: this.allReferenceFields.length }; }; componentInstance['referenceFieldService']['referenceFieldsResources'].getCategories = async () => { return []; }; await componentInstance['referenceFieldService'].resolve(); componentInstance['customDataTableService']['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, 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: '' }], [this.cdtGuid2]: [{ key: '1', sortOrder: 1, inUse: true, value: 'Steelers', parentKeys: [], parentKeysString: '' }, { key: '2', sortOrder: 2, inUse: true, 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: '' }] } ); componentInstance['customDataTableService']['set']( 'customDataTables', this.customDataTables ); } @AfterEach() afterEach () { this.resetInputs(); } private async mock ( instance: CreateEditReferenceFieldComponent, hasTable = false, hasWflAutomation = false, hasResponses = false ) { instance.existingReferenceField = this.existingReferenceField; instance.addingFieldToForm = this.addingFieldToForm; instance.forcedAudienceSelection = this.forcedAudienceSelection; instance.forceIsTableField = this.forceIsTableField; instance.forceIsDataPoint = this.forceIsDataPoint; instance.pendingKeyToBeCreated = this.pendingKeyToBeCreated; instance.uniqueKeys = this.uniqueKeys; instance.existingKeys = this.existingKeys; instance.lockFormatType = this.lockFormatType; instance.isViewOnly = this.isViewOnly; instance.tableImportNotAllowed = this.tableImportNotAllowed; instance.isMerge = this.isMerge; if (this.existingReferenceField) { instance['referenceFieldService']['referenceFieldsResources'].getReferenceFieldDetail = async () => { return { ...this.existingReferenceField, hasTable, hasWflAutomation, hasResponses }; }; } await instance.ngOnInit(); } resetInputs () { this.existingReferenceField = null; this.addingFieldToForm = false; this.forcedAudienceSelection = null; this.forceIsTableField = false; this.forceIsDataPoint = false; this.pendingKeyToBeCreated = ''; this.uniqueKeys = []; this.existingKeys = []; this.lockFormatType = false; this.isViewOnly = false; this.lockCollectionType = false; this.tableImportNotAllowed = false; } @TestCase('should be able to render') async testShouldRender ( fixture: ComponentFixture ) { await this.mock(fixture.componentInstance); expect(fixture.componentInstance).to.exist; } @TestCase('should have correct value for is type table - existing') async isTypeTableExisting ( fixture: ComponentFixture ) { this.existingReferenceField = { type: ReferenceFieldsUI.ReferenceFieldTypes.Table } as ReferenceFieldAPI.ReferenceFieldDisplayModel; await this.mock(fixture.componentInstance); expect(fixture.componentInstance.isTypeTable).to.be.true; this.existingReferenceField = { type: ReferenceFieldsUI.ReferenceFieldTypes.Subset } as ReferenceFieldAPI.ReferenceFieldDisplayModel; await this.mock(fixture.componentInstance); expect(fixture.componentInstance.isTypeTable).to.be.false; } @TestCase('should have correct value for is type table - new') async isTypeTableNew ( fixture: ComponentFixture ) { await this.mock(fixture.componentInstance); fixture.componentInstance.formGroup.get('type').setValue( ReferenceFieldsUI.ReferenceFieldTypes.Table ); expect(fixture.componentInstance.isTypeTable).to.be.true; fixture.componentInstance.formGroup.get('type').setValue( ReferenceFieldsUI.ReferenceFieldTypes.TextArea ); expect(fixture.componentInstance.isTypeTable).to.be.false; } @TestCase('should be able to get aggregate field parent exists on form') async aggregateFieldParentExistsOnForm ( fixture: ComponentFixture ) { this.existingReferenceField = this.aggregateField; await this.mock(fixture.componentInstance); expect(fixture.componentInstance.aggregateFieldParentExistsOnForm).to.be.true; this.existingReferenceField = null; await this.mock(fixture.componentInstance); expect(fixture.componentInstance.aggregateFieldParentExistsOnForm).to.be.false; } @TestCase('should be able to get is root zone') isRootZone ( fixture: ComponentFixture ) { fixture.componentInstance['clientSettingsService']['set']('clientSettings', { ...fixture.componentInstance['clientSettingsService'].clientSettings, isRootClient: true }); expect(fixture.componentInstance.isRootZone).to.be.true; fixture.componentInstance['clientSettingsService']['set']('clientSettings', { ...fixture.componentInstance['clientSettingsService'].clientSettings, isRootClient: false }); expect(fixture.componentInstance.isRootZone).to.be.false; } @TestCase('should be able to get is standard product field') async isStandardProductField ( fixture: ComponentFixture ) { fixture.componentInstance['clientSettingsService']['set']('clientSettings', { ...fixture.componentInstance['clientSettingsService'].clientSettings, isRootClient: true }); expect(fixture.componentInstance.isStandardProductField).to.be.false; fixture.componentInstance['clientSettingsService']['set']('clientSettings', { ...fixture.componentInstance['clientSettingsService'].clientSettings, isRootClient: false }); this.existingReferenceField = { ...this.textField, isStandardProductField: true }; await this.mock(fixture.componentInstance); expect(fixture.componentInstance.isStandardProductField).to.be.true; } @TestCase('should have correct value for supportsMultipleDisabled - base rules') async supportsMultipleDisabledBaseRules ( fixture: ComponentFixture ) { // Existing table field or data point - disabled this.existingReferenceField = { ...this.textField, isTableField: true }; await this.mock(fixture.componentInstance, true); expect(fixture.componentInstance.supportsMultipleDisabled).to.be.true; this.resetInputs(); // View Only this.isViewOnly = true; await this.mock(fixture.componentInstance); expect(fixture.componentInstance.supportsMultipleDisabled).to.be.true; this.resetInputs(); // Merge this.isMerge = true; await this.mock(fixture.componentInstance); expect(fixture.componentInstance.supportsMultipleDisabled).to.be.true; } @TestCase('should have correct value for supportsMultipleDisabled - additional rules') async supportsMultipleDisabledAdditional ( fixture: ComponentFixture ) { this.existingReferenceField = this.multiPicklist; await this.mock(fixture.componentInstance); fixture.componentInstance.fieldDetail = { ...this.multiPicklist, hasWflAutomation: false, hasResponses: true, hasTable: false }; // should be true bc it's checked and already has responses expect(fixture.componentInstance.supportsMultipleDisabled).to.be.true; this.existingReferenceField = this.textField; await this.mock(fixture.componentInstance); fixture.componentInstance.fieldDetail = { ...this.textField, hasWflAutomation: true, hasResponses: false, hasTable: false }; // should be true bc it's unchecked and already has WFL automation expect(fixture.componentInstance.supportsMultipleDisabled).to.be.true; } @TestCase('should be able to set type to data point') async setTypeToDataPoint ( fixture: ComponentFixture ) { await this.mock(fixture.componentInstance); fixture.componentInstance.setTypeToDataPoint(); expect(fixture.componentInstance.formGroup.value.type).to.be.equal( ReferenceFieldsUI.ReferenceFieldTypes.DataPoint ); } @TestCase('should be able to filter type options') async filterTypeOptions ( fixture: ComponentFixture ) { this.forceIsTableField = true; await this.mock(fixture.componentInstance); fixture.componentInstance.filterTypeOptions(); const filteredCorrectly = fixture.componentInstance.typeOptions.every((opt) => { return opt.value !== ReferenceFieldsUI.ReferenceFieldTypes.Subset && opt.value !== ReferenceFieldsUI.ReferenceFieldTypes.SelectBoxes; }); expect(filteredCorrectly).to.be.true; const onlyApplicantAudience = fixture.componentInstance.formAudienceOptions.every((opt) => { return opt.value === FormAudience.APPLICANT; }); expect(onlyApplicantAudience).to.be.true; } @TestCase('should be able to set is existing table field or data point') async setIsExistingTableFieldOrDataPoint ( fixture: ComponentFixture ) { this.existingReferenceField = { ...this.textField, isTableField: true }; await this.mock(fixture.componentInstance, true); fixture.componentInstance.setIsExistingTableFieldOrDataPoint(); expect(fixture.componentInstance.isExistingTableFieldOrDataPoint).to.be.equal(true); this.resetInputs(); this.existingReferenceField = this.textField; await this.mock(fixture.componentInstance); fixture.componentInstance.setIsExistingTableFieldOrDataPoint(); expect(fixture.componentInstance.isExistingTableFieldOrDataPoint).to.be.equal(false); this.resetInputs(); this.existingReferenceField = { ...this.textField, type: ReferenceFieldsUI.ReferenceFieldTypes.DataPoint }; await this.mock(fixture.componentInstance); fixture.componentInstance.setIsExistingTableFieldOrDataPoint(); expect(fixture.componentInstance.isExistingTableFieldOrDataPoint).to.be.equal(true); } @TestCase('should be able to get can update to single response') async canUpdateToSingleResponse ( fixture: ComponentFixture ) { this.existingReferenceField = { ...this.textField, formAudience: FormAudience.APPLICANT }; await this.mock(fixture.componentInstance); // applicant fields are always true let canUpdate = await fixture.componentInstance.getCanUpdateToSingleResponse(); expect(canUpdate).to.be.equal(true); this.resetInputs(); this.existingReferenceField = { ...this.textField, formAudience: FormAudience.MANAGER }; await this.mock(fixture.componentInstance); // Manager fields we have to hit an endpoint const expectedCanUpdate = true; fixture.componentInstance['referenceFieldService']['referenceFieldsResources'].getCanUpdateRefFieldToSingleResponse = async () => { return expectedCanUpdate; }; canUpdate = await fixture.componentInstance.getCanUpdateToSingleResponse(); expect(canUpdate).to.be.equal(expectedCanUpdate); } @TestCase('should be able to get can update cdt') async canUpdateCdt ( fixture: ComponentFixture ) { this.isViewOnly = true; await this.mock(fixture.componentInstance); let canUpdateCdt = await fixture.componentInstance.getCanUpdateCdtOnField(); expect(canUpdateCdt).to.be.false; this.resetInputs(); this.existingReferenceField = this.multiPicklist; await this.mock(fixture.componentInstance); const expectedCanUpdate = false; spy.on(fixture.componentInstance['referenceFieldService']['referenceFieldsResources'], 'canUpdateCdtOnField', async () => { return expectedCanUpdate; }); canUpdateCdt = await fixture.componentInstance.getCanUpdateCdtOnField(); expect(fixture.componentInstance['referenceFieldService']['referenceFieldsResources']['canUpdateCdtOnField']).to.have.been.called.once; expect(canUpdateCdt).to.be.equal(expectedCanUpdate); } @TestCase('should generate unique key on blur of name') async onBlurOfName ( fixture: ComponentFixture ) { await this.mock(fixture.componentInstance); fixture.componentInstance.formGroup.get('name').setValue('Text Field'); fixture.componentInstance.onBlurOfName(); const expectedKey = 'textField'; expect(fixture.componentInstance.formGroup.value.key).to.be.equal(expectedKey); } @TestCase('should be able to set parent ref field') async setParentReferenceField ( fixture: ComponentFixture ) { this.existingReferenceField = this.aggregateField; await this.mock(fixture.componentInstance); fixture.componentInstance.setParentReferenceField(); expect(fixture.componentInstance.parentFieldExistsOnForm).to.be.true; } @TestCase('should be able to handle type change') async handleTypeChange ( fixture: ComponentFixture ) { this.existingReferenceField = this.textField; await this.mock(fixture.componentInstance); fixture.componentInstance.formGroup.get('formAudience').setValue( FormAudience.MANAGER ); fixture.componentInstance.formGroup.get('type').setValue( ReferenceFieldsUI.ReferenceFieldTypes.Table ); fixture.detectChanges(); fixture.componentInstance.handleTypeChange(); // Should have cleared formatting type const clearedFormatType = !fixture.componentInstance.formGroup.value.formatType; expect(clearedFormatType).to.be.equal(true); // Should have reset parent ref field const clearedParentField = !fixture.componentInstance.formGroup.value.parentReferenceFieldId; expect(clearedParentField).to.be.true; // Should make sure audience is correct const changedAudienceToApplicant = fixture.componentInstance.formGroup.value.formAudience === FormAudience.APPLICANT; expect(changedAudienceToApplicant).to.be.true; } @TestCase('should be able to update help text') async updateHelpText ( fixture: ComponentFixture ) { this.existingReferenceField = { type: ReferenceFieldsUI.ReferenceFieldTypes.DataPoint } as ReferenceFieldAPI.ReferenceFieldDisplayModel; await this.mock(fixture.componentInstance); fixture.componentInstance.updateHelpText(); expect(fixture.componentInstance.typeSelectHelp).to.be.equal( fixture.componentInstance.dataPointHelpText ); } @TestCase('should be able to reset formatting') async resetFormattingIfNeeded ( fixture: ComponentFixture ) { await this.mock(fixture.componentInstance); fixture.componentInstance.resetFormattingIfNeeded(); const formattingIsEmpty = !fixture.componentInstance.formGroup.value.formatType; expect(formattingIsEmpty).to.be.true; } @TestCase('should be able to ensure audience is accurate') async ensureAudienceIsAccurate ( fixture: ComponentFixture ) { this.existingReferenceField = { type: ReferenceFieldsUI.ReferenceFieldTypes.Table, formAudience: FormAudience.MANAGER } as ReferenceFieldAPI.ReferenceFieldDisplayModel; await this.mock(fixture.componentInstance); fixture.componentInstance.ensureAudienceIsAccurate(); const audienceIsApplicant = fixture.componentInstance.formGroup.value.formAudience === FormAudience.APPLICANT; expect(audienceIsApplicant).to.be.true; } @TestCase('should be able to set supports table field') async setSupportsTableField ( fixture: ComponentFixture ) { this.existingReferenceField = this.textField; await this.mock(fixture.componentInstance); fixture.componentInstance.setSupportsTableField(); // true for text fields expect(fixture.componentInstance.supportsTableField).to.be.true; this.resetInputs(); this.existingReferenceField = this.multiPicklist; await this.mock(fixture.componentInstance); fixture.componentInstance.setSupportsTableField(); // false for multi picklists expect(fixture.componentInstance.supportsTableField).to.be.false; } @TestCase('should be able to clear table field') async clearTableField ( fixture: ComponentFixture ) { this.existingReferenceField = { ...this.textField, isTableField: true }; await this.mock(fixture.componentInstance); fixture.componentInstance.clearTableField(); const isCleared = !fixture.componentInstance.formGroup.value.isTableField; expect(isCleared).to.be.true; } @TestCase('should be able to set supports mask and encrypt') async setSupportsMaskAndEncrypt ( fixture: ComponentFixture ) { this.existingReferenceField = this.textField; await this.mock(fixture.componentInstance); fixture.componentInstance.setSupportsMaskAndEncrypt(); expect(fixture.componentInstance.supportsEncryption).to.be.true; expect(fixture.componentInstance.supportsMultipleDisabled).to.be.false; // TODO: talk to Tina about this one, the logic seemed to indicate that this should be false this.resetInputs(); this.existingReferenceField = { ...this.textField, isTableField: true }; await this.mock(fixture.componentInstance); expect(fixture.componentInstance.supportsEncryption).to.be.false; expect(fixture.componentInstance.supportsMasking).to.be.false; } @TestCase('should be able to clear encryption') async clearEncryption ( fixture: ComponentFixture ) { this.existingReferenceField = { ...this.textField, isEncrypted: true }; await this.mock(fixture.componentInstance); fixture.componentInstance.clearEncryption(); const isCleared = !fixture.componentInstance.formGroup.value.isEncrypted; expect(isCleared).to.be.true; } @TestCase('should be able to clear masking') async clearMasking ( fixture: ComponentFixture ) { this.existingReferenceField = { ...this.textField, isMasked: true }; await this.mock(fixture.componentInstance); fixture.componentInstance.clearMasking(); const isCleared = !fixture.componentInstance.formGroup.value.isMasked; expect(isCleared).to.be.true; } @TestCase('should be able to reset parent ref field') async resetParentRefField ( fixture: ComponentFixture ) { this.existingReferenceField = this.aggregateField; await this.mock(fixture.componentInstance); fixture.componentInstance.resetParentRefField(); const isReset = !fixture.componentInstance.formGroup.value.parentReferenceFieldId; expect(isReset).to.be.true; } @TestCase('should be able to get parent picklist options') async getParentPicklistOptions ( fixture: ComponentFixture ) { this.existingReferenceField = this.multiPicklist; await this.mock(fixture.componentInstance); fixture.componentInstance.getParentPicklistOptions(this.existingReferenceField.customDataTableGuid); // should have 1 option (single parent picklist) expect(fixture.componentInstance.parentPicklistOptions.length).to.be.equal(1); // should set form control when only one option expect(fixture.componentInstance.formGroup.value.parentReferenceFieldId).to.be.equal( this.singleParentPicklistId ); } @TestCase('should be able to get data table has parent') async dataTableHasParent ( fixture: ComponentFixture ) { this.existingReferenceField = this.multiPicklist; await this.mock(fixture.componentInstance); let pass = fixture.componentInstance.dataTableHasParent(this.existingReferenceField.customDataTableGuid); expect(pass).to.be.true; this.resetInputs(); this.existingReferenceField = this.singlePicklistParent; await this.mock(fixture.componentInstance); pass = fixture.componentInstance.dataTableHasParent(this.existingReferenceField.customDataTableGuid); expect(pass).to.be.false; } @TestCase('should be able to generate unique key') async generateUniqueKey ( fixture: ComponentFixture ) { this.existingReferenceField = this.textField; await this.mock(fixture.componentInstance); fixture.componentInstance.generateUniqueKey(); expect(fixture.componentInstance.formGroup.value.key).to.be.equal('textField'); } @TestCase('should be able to validate selected cdt - required') async forceSelectCustomDataTableRequired ( fixture: ComponentFixture ) { await this.mock(fixture.componentInstance); fixture.componentInstance.formGroup.get('type').setValue( ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable ); fixture.detectChanges(); const hasError = !!fixture.componentInstance.formGroup.errors['mustSelectDataTable']; expect(hasError).to.be.true; } @TestCase('should be able to validate selected cdt - not required') async forceSelectCustomDataTableNotRequired ( fixture: ComponentFixture ) { await this.mock(fixture.componentInstance); fixture.componentInstance.formGroup.get('type').setValue( ReferenceFieldsUI.ReferenceFieldTypes.TextArea ); fixture.detectChanges(); const hasNoError = !fixture.componentInstance.formGroup.errors; expect(hasNoError).to.be.true; } @TestCase('should be able to forcce parent selection - required') async forceSelectParentPicklistIfChildRequired ( fixture: ComponentFixture ) { await this.mock(fixture.componentInstance); fixture.componentInstance.formGroup.get('type').setValue( ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable ); fixture.componentInstance.formGroup.get('customDataTableGuid').setValue( this.cdtGuid2 ); fixture.detectChanges(); const hasError = !!fixture.componentInstance.formGroup.errors['parentPicklistRequired']; expect(hasError).to.be.true; } @TestCase('should be able to force parent selection - not required') async forceSelectParentPicklistIfChildNotRequired ( fixture: ComponentFixture ) { await this.mock(fixture.componentInstance); fixture.componentInstance.formGroup.get('type').setValue( ReferenceFieldsUI.ReferenceFieldTypes.CustomDataTable ); fixture.componentInstance.formGroup.get('customDataTableGuid').setValue( this.cdtGuid1 ); fixture.detectChanges(); const hasNoError = !fixture.componentInstance.formGroup.errors; expect(hasNoError).to.be.true; } @TestCase('should be able to force data set collection type - required') async forceSelectDataSetCollectionTypeRequired ( fixture: ComponentFixture ) { await this.mock(fixture.componentInstance); fixture.componentInstance.formGroup.get('type').setValue( ReferenceFieldsUI.ReferenceFieldTypes.Subset ); fixture.detectChanges(); const hasError = !!fixture.componentInstance.formGroup.errors['dataSetCollectionTypeRequired']; expect(hasError).to.be.true; } @TestCase('should be able to force data set collection type - not required') async forceSelectDataSetCollectionTypeNotRequired ( fixture: ComponentFixture ) { await this.mock(fixture.componentInstance); fixture.componentInstance.formGroup.get('type').setValue( ReferenceFieldsUI.ReferenceFieldTypes.TextArea ); fixture.detectChanges(); const hasNoError = !fixture.componentInstance.formGroup.errors; expect(hasNoError).to.be.true; } }