Skip to content

Commit

Permalink
fix unit and e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel7373 committed Jan 23, 2025
1 parent 6bcb37d commit 56d0bae
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('KeyResultDialogComponent', () => {
id: 2,
state: State.ONGOING,
quarter: new Quarter(
1, 'GJ 22/23-Q2', new Date(), new Date()
1, 'GJ 22/23-Q2', new Date(), new Date(), false
)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('KeyResultFormComponent', () => {
id: 2,
state: State.ONGOING,
quarter: new Quarter(
1, 'GJ 22/23-Q2', new Date(), new Date()
1, 'GJ 22/23-Q2', new Date(), new Date(), false
)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ const overviewService = {

const quarters = [
new Quarter(
999, 'Backlog', null, null
999, 'Backlog', null, null, true
),
new Quarter(
2, '23.02.2025', new Date(), new Date()
2, '23.02.2025', new Date(), new Date(), false
),
new Quarter(
5, '23.02.2025', new Date(), new Date()
5, '23.02.2025', new Date(), new Date(), false
),
new Quarter(
7, '23.02.2025', new Date(), new Date()
7, '23.02.2025', new Date(), new Date(), false
)
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ interface MatDialogDataInterface {
const quarterService = {
getAllQuarters(): Observable<Quarter[]> {
return of([new Quarter(
1, quarter.label, quarter.startDate, quarter.endDate
1, quarter.label, quarter.startDate, quarter.endDate, quarter.isBacklogQuarter
),
new Quarter(
2, quarter.label, quarter.startDate, quarter.endDate
2, quarter.label, quarter.startDate, quarter.endDate, quarter.isBacklogQuarter
),
new Quarter(
999, 'Backlog', null, null
999, 'Backlog', null, null, true
)]);
},
getCurrentQuarter(): Observable<Quarter> {
return of(new Quarter(
2, quarter.label, quarter.startDate, quarter.endDate
2, quarter.label, quarter.startDate, quarter.endDate, quarter.isBacklogQuarter
));
}
};
Expand Down Expand Up @@ -343,8 +343,7 @@ 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);


component.data.action = 'duplicate';
fixture.detectChanges();
Expand All @@ -365,28 +364,25 @@ describe('ObjectiveDialogComponent', () => {
.toBeFalsy();

component.objectiveForm.controls.quarter.setValue(2);
isBacklogQuarterSpy.mockReturnValue(true);
fixture.detectChanges();
expect(component.allowedToSaveBacklog())
.toBeTruthy();

component.objectiveForm.controls.quarter.setValue(999);
component.data.objective.objectiveId = undefined;
isBacklogQuarterSpy.mockReturnValue(false);
fixture.detectChanges();
expect(component.allowedToSaveBacklog())
.toBeFalsy();

component.objectiveForm.controls.quarter.setValue(2);
isBacklogQuarterSpy.mockReturnValue(true);
fixture.detectChanges();
expect(component.allowedToSaveBacklog())
.toBeTruthy();
});

it('should return if option is allowed for quarter select', async() => {
const quarter: Quarter = new Quarter(
1, 'Backlog', null, null
1, 'Backlog', null, null, true
);

const data = {
Expand Down Expand Up @@ -488,9 +484,6 @@ describe('ObjectiveDialogComponent', () => {
action: 'releaseBacklog'
};

const isBacklogQuarterSpy = jest.spyOn(component, 'isBacklogQuarter');
isBacklogQuarterSpy.mockReturnValue(false);

const routerHarness = await RouterTestingHarness.create();
await routerHarness.navigateByUrl('/?quarter=999');
objectiveService.getFullObjective.mockReturnValue(of(objective));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { ActivatedRoute } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { DialogService } from '../../../services/dialog.service';
import { KeyResultDto } from '../../types/DTOs/key-result-dto';
import { quarter } from '../../test-data';

@Component({
selector: 'app-objective-form',
Expand Down Expand Up @@ -147,8 +146,7 @@ export class ObjectiveFormComponent implements OnInit, OnDestroy {
const teamId = isEditing ? objective.teamId : this.data.objective.teamId;
const newEditQuarter = isEditing ? currentQuarter.id : objective.quarterId;
let quarterId = getValueFromQuery(this.route.snapshot.queryParams['quarter'], newEditQuarter)[0];

if (currentQuarter && currentQuarter.isBacklogQuarter && this.data.action == 'releaseBacklog') {
if (currentQuarter && !currentQuarter.isBacklogQuarter && this.data.action == 'releaseBacklog') {
quarterId = quarters[1].id;
}

Expand Down Expand Up @@ -261,7 +259,7 @@ export class ObjectiveFormComponent implements OnInit, OnDestroy {
allowedToSaveBacklog() {
const currentQuarter: Quarter | undefined = this.quarters.find((quarter) => quarter.id == this.objectiveForm.value.quarter);
if (currentQuarter) {
const isBacklogCurrent = quarter.isBacklogQuarter;
const isBacklogCurrent = currentQuarter.isBacklogQuarter;
if (this.data.action == 'duplicate') {
return true;
}
Expand Down

0 comments on commit 56d0bae

Please sign in to comment.