Skip to content

Commit

Permalink
Fix frontend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lkleisa committed Jun 3, 2024
1 parent 7fc2620 commit cfa8873
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ let objectiveService = {
const quarterService = {
getAllQuarters(): Observable<Quarter[]> {
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' },
]);
},
};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -396,6 +396,7 @@ describe('ObjectiveDialogComponent', () => {
expect(component.allowedToSaveBacklog()).toBeTruthy();

component.state = 'ONGOING';
isBacklogQuarterSpy.mockReturnValue(false);
fixture.detectChanges();
expect(component.allowedToSaveBacklog()).toBeFalsy();

Expand Down Expand Up @@ -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;
Expand All @@ -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);
});

Expand Down Expand Up @@ -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);
});
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class ObjectiveFormComponent implements OnInit {
});
quarters$: Observable<Quarter[]> = of([]);
quarters: Quarter[] = [];
objective: Objective | null = null;
teams$: Observable<Team[]> = of([]);
alignmentPossibilities$: Observable<AlignmentPossibility[]> = of([]);
currentTeam$: BehaviorSubject<Team | null> = new BehaviorSubject<Team | null>(null);
Expand Down Expand Up @@ -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!);

Expand Down Expand Up @@ -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;
Expand All @@ -244,7 +241,7 @@ export class ObjectiveFormComponent implements OnInit {
}
}

isBacklogQuarter(label: string) {
isNotBacklogQuarter(label: string) {
return GJ_REGEX_PATTERN.test(label);
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/shared/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cfa8873

Please sign in to comment.