diff --git a/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.spec.ts b/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.spec.ts index b4ae56f3b4..79bd67f658 100644 --- a/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.spec.ts +++ b/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.spec.ts @@ -53,9 +53,9 @@ let objectiveService = { const quarterService = { getAllQuarters(): Observable { return of([ + { id: 199, startDate: null, endDate: null, label: 'Backlog' }, { id: 1, startDate: quarter.startDate, endDate: quarter.endDate, label: quarter.label }, { id: 2, startDate: quarter.startDate, endDate: quarter.endDate, label: quarter.label }, - { id: 199, startDate: null, endDate: null, label: 'Backlog' }, ]); }, }; @@ -145,7 +145,7 @@ describe('ObjectiveDialogComponent', () => { team = teams[0].id; }); quarterService.getAllQuarters().subscribe((quarters) => { - quarter = quarters[1].id; + quarter = quarters[2].id; }); // Get input elements and set values @@ -381,8 +381,8 @@ describe('ObjectiveDialogComponent', () => { it('should return correct value if allowed to save to backlog', async () => { component.quarters = quarterList; - const isBacklogQuarterSpy = jest.spyOn(component, 'isBacklogQuarter'); - isBacklogQuarterSpy.mockReturnValue(false); + const isBacklogQuarterSpy = jest.spyOn(component, 'isNotBacklogQuarter'); + isBacklogQuarterSpy.mockReturnValue(true); component.data.action = 'duplicate'; fixture.detectChanges(); @@ -396,6 +396,7 @@ describe('ObjectiveDialogComponent', () => { expect(component.allowedToSaveBacklog()).toBeTruthy(); component.state = 'ONGOING'; + isBacklogQuarterSpy.mockReturnValue(false); fixture.detectChanges(); expect(component.allowedToSaveBacklog()).toBeFalsy(); @@ -512,7 +513,7 @@ describe('ObjectiveDialogComponent', () => { expect(component.objectiveForm.getRawValue().alignment).toEqual(null); }); - it('should load not include current team in alignment possibilities', async () => { + it('should not include current team in alignment possibilities', async () => { objectiveService.getAlignmentPossibilities.mockReturnValue(of([alignmentPossibility1, alignmentPossibility2])); component.generateAlignmentPossibilities(3, null, 1); let alignmentPossibilities = null; @@ -521,7 +522,7 @@ describe('ObjectiveDialogComponent', () => { }); expect(alignmentPossibilities).toStrictEqual([alignmentPossibility2]); - expect(component.filteredOptions$.getValue()).toEqual([alignmentPossibility1, alignmentPossibility2]); + expect(component.filteredOptions$.getValue()).toEqual([alignmentPossibility2]); expect(component.objectiveForm.getRawValue().alignment).toEqual(null); }); @@ -679,6 +680,13 @@ describe('ObjectiveDialogComponent', () => { jest.spyOn(objectiveService, 'getAlignmentPossibilities').mockReturnValue(of([])); fixture = TestBed.createComponent(ObjectiveFormComponent); component = fixture.componentInstance; + component.data = { + objective: { + objectiveId: 1, + teamId: 1, + }, + action: 'releaseBacklog', + }; fixture.detectChanges(); loader = TestbedHarnessEnvironment.loader(fixture); }); @@ -688,15 +696,7 @@ describe('ObjectiveDialogComponent', () => { }); it('should set correct default value if objective is released in backlog', async () => { - component.data = { - objective: { - objectiveId: 1, - teamId: 1, - }, - action: 'releaseBacklog', - }; - - const isBacklogQuarterSpy = jest.spyOn(component, 'isBacklogQuarter'); + const isBacklogQuarterSpy = jest.spyOn(component, 'isNotBacklogQuarter'); isBacklogQuarterSpy.mockReturnValue(false); const routerHarness = await RouterTestingHarness.create(); diff --git a/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts b/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts index 01523bf190..ddcfbbdb6d 100644 --- a/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts +++ b/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts @@ -38,7 +38,6 @@ export class ObjectiveFormComponent implements OnInit { }); quarters$: Observable = of([]); quarters: Quarter[] = []; - objective: Objective | null = null; teams$: Observable = of([]); alignmentPossibilities$: Observable = of([]); currentTeam$: BehaviorSubject = new BehaviorSubject(null); @@ -102,20 +101,18 @@ export class ObjectiveFormComponent implements OnInit { forkJoin([objective$, this.quarters$]).subscribe(([objective, quarters]) => { this.quarters = quarters; - this.objective = objective; const teamId = isCreating ? objective.teamId : this.data.objective.teamId; let quarterId = getValueFromQuery(this.route.snapshot.queryParams['quarter'], quarters[2].id)[0]; let currentQuarter: Quarter | undefined = this.quarters.find((quarter) => quarter.id == quarterId); - if (currentQuarter && !this.isBacklogQuarter(currentQuarter.label) && this.data.action == 'releaseBacklog') { + if (currentQuarter && !this.isNotBacklogQuarter(currentQuarter.label) && this.data.action == 'releaseBacklog') { quarterId = quarters[2].id; } this.state = objective.state; this.version = objective.version; this.teams$.subscribe((value) => { - let team: Team = value.filter((team: Team) => team.id == teamId)[0]; - this.currentTeam$.next(team); + this.currentTeam$.next(value.filter((team: Team) => team.id == teamId)[0]); }); this.generateAlignmentPossibilities(quarterId, objective, teamId!); @@ -216,12 +213,12 @@ export class ObjectiveFormComponent implements OnInit { (quarter) => quarter.id == this.objectiveForm.value.quarter, ); if (currentQuarter) { - let isBacklogCurrent: boolean = !this.isBacklogQuarter(currentQuarter.label); + let isBacklogCurrent: boolean = this.isNotBacklogQuarter(currentQuarter.label); if (this.data.action == 'duplicate') return true; if (this.data.objective.objectiveId) { - return isBacklogCurrent ? this.state == 'DRAFT' : true; + return !isBacklogCurrent ? this.state == 'DRAFT' : true; } else { - return !isBacklogCurrent; + return isBacklogCurrent; } } else { return true; @@ -244,7 +241,7 @@ export class ObjectiveFormComponent implements OnInit { } } - isBacklogQuarter(label: string) { + isNotBacklogQuarter(label: string) { return GJ_REGEX_PATTERN.test(label); } diff --git a/frontend/src/app/shared/testData.ts b/frontend/src/app/shared/testData.ts index 913f76f962..86093db50f 100644 --- a/frontend/src/app/shared/testData.ts +++ b/frontend/src/app/shared/testData.ts @@ -137,7 +137,7 @@ export const quarterBacklog: Quarter = { endDate: null, } as Quarter; -export const quarterList: Quarter[] = [quarter1, quarter2, quarterBacklog]; +export const quarterList: Quarter[] = [quarterBacklog, quarter1, quarter2]; export const checkInMetric: CheckInMin = { id: 815,