import { Injectable } from '@angular/core'; import { ComponentFixture } from '@angular/core/testing'; import { GCMockModule } from '@core/mocks/gc-module.mock'; import { UsersAndRoutesLevel, WorkflowLevelOptions } from '@core/typings/workflow.typing'; import { BeforeEach, Spec, TestCase } from '@yourcause/test-decorators'; import { DescribeAngularComponent } from '@yourcause/test-decorators/angular'; import { expect } from 'chai'; import { AddEditLevelModalComponent } from './add-edit-level-modal.component'; @Injectable({ providedIn: 'root' }) @DescribeAngularComponent(AddEditLevelModalComponent, { imports: [ GCMockModule ] }) export class AddEditLevelModalComponentSpec implements Spec> { private levelA: UsersAndRoutesLevel; private levelB: UsersAndRoutesLevel; @BeforeEach() setupValues () { this.levelA = { id: 1, name: 'level A', description: 'test level', allowDeclination: true, allowApproval: true, allowAward: true, allowUserToViewAwardsAndPayments: true, allowUserToArchiveAndUnarchive: true, allowUserToRequestRevision: true, allowFormDueDateExtension: true, allowRecommendedFunding: true, showMaskedApplicantInfo: true, showBudgetSummaryInfo: true }; this.levelB = { id: 2, name: 'level B', description: 'test level', allowDeclination: false, allowApproval: false, allowAward: false, allowUserToViewAwardsAndPayments: false, allowUserToArchiveAndUnarchive: false, allowUserToRequestRevision: false, allowFormDueDateExtension: false, allowRecommendedFunding: true, showMaskedApplicantInfo: false, showBudgetSummaryInfo: false }; } @TestCase('should exist') testShouldExist (fixture: ComponentFixture) { expect(fixture).to.exist; } @TestCase('should observe correct award setting when true') testShouldObserveAwardSetting (fixture: ComponentFixture) { const compInst = fixture.componentInstance; compInst.level = this.levelA; compInst.ngOnInit(); const formGroup = compInst.formGroup; const control = formGroup.get('allowUserToViewAwardsAndPayments'); expect(control.value).to.equal(this.levelA.allowUserToViewAwardsAndPayments); } @TestCase('should observe correct award setting when false') testShouldObserveCorrectAwardSettingWhenFalse (fixture: ComponentFixture) { const compInst = fixture.componentInstance; compInst.level = this.levelB; compInst.ngOnInit(); const formGroup = compInst.formGroup; const control = formGroup.get('allowUserToViewAwardsAndPayments'); expect(control.value).to.equal(this.levelB.allowUserToViewAwardsAndPayments); } @TestCase('should observe correct levelActions on init') testShouldObserveCorrectLevelActions (fixture: ComponentFixture) { const compInst = fixture.componentInstance; compInst.level = this.levelA; compInst.ngOnInit(); const formGroup = compInst.formGroup; const control = formGroup.get('levelActions'); const levelActions = compInst.getLevelActions(); // have.members will check that members of both arrays are the same expect(control.value).to.have.members(levelActions); } @TestCase('should correctly include actions based on level data') testShouldCorrectlyIncludeLevelActions (fixture: ComponentFixture) { const compInst = fixture.componentInstance; compInst.level = this.levelA; compInst.ngOnInit(); const formGroup = compInst.formGroup; const control = formGroup.get('levelActions'); expect(control.value).to.include(WorkflowLevelOptions.ALLOW_AWARD_ACTIONS); } @TestCase('should correctly exclude actions based on level data') testShouldCorrectlyExcludeActions (fixture: ComponentFixture) { const compInst = fixture.componentInstance; compInst.level = this.levelB; compInst.ngOnInit(); const formGroup = compInst.formGroup; const control = formGroup.get('levelActions'); expect(control.value).to.not.include(WorkflowLevelOptions.ALLOW_AWARD_ACTIONS); } }