Skip to content

Commit a3513b8

Browse files
committed
Fix frontend tests
1 parent 36293d7 commit a3513b8

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

frontend/src/app/shared/dialog/objective-dialog/objective-form.component.spec.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ let objectiveService = {
5353
const quarterService = {
5454
getAllQuarters(): Observable<Quarter[]> {
5555
return of([
56+
{ id: 199, startDate: null, endDate: null, label: 'Backlog' },
5657
{ id: 1, startDate: quarter.startDate, endDate: quarter.endDate, label: quarter.label },
5758
{ id: 2, startDate: quarter.startDate, endDate: quarter.endDate, label: quarter.label },
58-
{ id: 199, startDate: null, endDate: null, label: 'Backlog' },
5959
]);
6060
},
6161
};
@@ -145,7 +145,7 @@ describe('ObjectiveDialogComponent', () => {
145145
team = teams[0].id;
146146
});
147147
quarterService.getAllQuarters().subscribe((quarters) => {
148-
quarter = quarters[1].id;
148+
quarter = quarters[2].id;
149149
});
150150

151151
// Get input elements and set values
@@ -381,8 +381,8 @@ describe('ObjectiveDialogComponent', () => {
381381

382382
it('should return correct value if allowed to save to backlog', async () => {
383383
component.quarters = quarterList;
384-
const isBacklogQuarterSpy = jest.spyOn(component, 'isBacklogQuarter');
385-
isBacklogQuarterSpy.mockReturnValue(false);
384+
const isBacklogQuarterSpy = jest.spyOn(component, 'isNotBacklogQuarter');
385+
isBacklogQuarterSpy.mockReturnValue(true);
386386

387387
component.data.action = 'duplicate';
388388
fixture.detectChanges();
@@ -396,6 +396,7 @@ describe('ObjectiveDialogComponent', () => {
396396
expect(component.allowedToSaveBacklog()).toBeTruthy();
397397

398398
component.state = 'ONGOING';
399+
isBacklogQuarterSpy.mockReturnValue(false);
399400
fixture.detectChanges();
400401
expect(component.allowedToSaveBacklog()).toBeFalsy();
401402

@@ -512,7 +513,7 @@ describe('ObjectiveDialogComponent', () => {
512513
expect(component.objectiveForm.getRawValue().alignment).toEqual(null);
513514
});
514515

515-
it('should load not include current team in alignment possibilities', async () => {
516+
it('should not include current team in alignment possibilities', async () => {
516517
objectiveService.getAlignmentPossibilities.mockReturnValue(of([alignmentPossibility1, alignmentPossibility2]));
517518
component.generateAlignmentPossibilities(3, null, 1);
518519
let alignmentPossibilities = null;
@@ -521,7 +522,7 @@ describe('ObjectiveDialogComponent', () => {
521522
});
522523

523524
expect(alignmentPossibilities).toStrictEqual([alignmentPossibility2]);
524-
expect(component.filteredOptions$.getValue()).toEqual([alignmentPossibility1, alignmentPossibility2]);
525+
expect(component.filteredOptions$.getValue()).toEqual([alignmentPossibility2]);
525526
expect(component.objectiveForm.getRawValue().alignment).toEqual(null);
526527
});
527528

@@ -679,6 +680,13 @@ describe('ObjectiveDialogComponent', () => {
679680
jest.spyOn(objectiveService, 'getAlignmentPossibilities').mockReturnValue(of([]));
680681
fixture = TestBed.createComponent(ObjectiveFormComponent);
681682
component = fixture.componentInstance;
683+
component.data = {
684+
objective: {
685+
objectiveId: 1,
686+
teamId: 1,
687+
},
688+
action: 'releaseBacklog',
689+
};
682690
fixture.detectChanges();
683691
loader = TestbedHarnessEnvironment.loader(fixture);
684692
});
@@ -688,15 +696,7 @@ describe('ObjectiveDialogComponent', () => {
688696
});
689697

690698
it('should set correct default value if objective is released in backlog', async () => {
691-
component.data = {
692-
objective: {
693-
objectiveId: 1,
694-
teamId: 1,
695-
},
696-
action: 'releaseBacklog',
697-
};
698-
699-
const isBacklogQuarterSpy = jest.spyOn(component, 'isBacklogQuarter');
699+
const isBacklogQuarterSpy = jest.spyOn(component, 'isNotBacklogQuarter');
700700
isBacklogQuarterSpy.mockReturnValue(false);
701701

702702
const routerHarness = await RouterTestingHarness.create();

frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export class ObjectiveFormComponent implements OnInit {
3838
});
3939
quarters$: Observable<Quarter[]> = of([]);
4040
quarters: Quarter[] = [];
41-
objective: Objective | null = null;
4241
teams$: Observable<Team[]> = of([]);
4342
alignmentPossibilities$: Observable<AlignmentPossibility[]> = of([]);
4443
currentTeam$: BehaviorSubject<Team | null> = new BehaviorSubject<Team | null>(null);
@@ -102,20 +101,18 @@ export class ObjectiveFormComponent implements OnInit {
102101

103102
forkJoin([objective$, this.quarters$]).subscribe(([objective, quarters]) => {
104103
this.quarters = quarters;
105-
this.objective = objective;
106104
const teamId = isCreating ? objective.teamId : this.data.objective.teamId;
107105
let quarterId = getValueFromQuery(this.route.snapshot.queryParams['quarter'], quarters[2].id)[0];
108106

109107
let currentQuarter: Quarter | undefined = this.quarters.find((quarter) => quarter.id == quarterId);
110-
if (currentQuarter && !this.isBacklogQuarter(currentQuarter.label) && this.data.action == 'releaseBacklog') {
108+
if (currentQuarter && !this.isNotBacklogQuarter(currentQuarter.label) && this.data.action == 'releaseBacklog') {
111109
quarterId = quarters[2].id;
112110
}
113111

114112
this.state = objective.state;
115113
this.version = objective.version;
116114
this.teams$.subscribe((value) => {
117-
let team: Team = value.filter((team: Team) => team.id == teamId)[0];
118-
this.currentTeam$.next(team);
115+
this.currentTeam$.next(value.filter((team: Team) => team.id == teamId)[0]);
119116
});
120117
this.generateAlignmentPossibilities(quarterId, objective, teamId!);
121118

@@ -216,12 +213,12 @@ export class ObjectiveFormComponent implements OnInit {
216213
(quarter) => quarter.id == this.objectiveForm.value.quarter,
217214
);
218215
if (currentQuarter) {
219-
let isBacklogCurrent: boolean = !this.isBacklogQuarter(currentQuarter.label);
216+
let isBacklogCurrent: boolean = this.isNotBacklogQuarter(currentQuarter.label);
220217
if (this.data.action == 'duplicate') return true;
221218
if (this.data.objective.objectiveId) {
222-
return isBacklogCurrent ? this.state == 'DRAFT' : true;
219+
return !isBacklogCurrent ? this.state == 'DRAFT' : true;
223220
} else {
224-
return !isBacklogCurrent;
221+
return isBacklogCurrent;
225222
}
226223
} else {
227224
return true;
@@ -244,7 +241,7 @@ export class ObjectiveFormComponent implements OnInit {
244241
}
245242
}
246243

247-
isBacklogQuarter(label: string) {
244+
isNotBacklogQuarter(label: string) {
248245
return GJ_REGEX_PATTERN.test(label);
249246
}
250247

frontend/src/app/shared/testData.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export const quarterBacklog: Quarter = {
137137
endDate: null,
138138
} as Quarter;
139139

140-
export const quarterList: Quarter[] = [quarter1, quarter2, quarterBacklog];
140+
export const quarterList: Quarter[] = [quarterBacklog, quarter1, quarter2];
141141

142142
export const checkInMetric: CheckInMin = {
143143
id: 815,

0 commit comments

Comments
 (0)