Skip to content

Commit

Permalink
Add Kein Alignment for removing existing alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
lkleisa committed May 22, 2024
1 parent 0fdbef7 commit ae5b684
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
class="custom-select bg-white select-width"
formControlName="alignment"
id="alignment"
(change)="changeFirstAlignmentPossibility()"
[attr.data-testId]="'alignmentSelect'"
>
<ng-container *ngFor="let alignment of alignmentPossibilities$ | async; let i = index">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('ObjectiveDialogComponent', () => {
{ provide: TeamService, useValue: teamService },
],
});
jest.spyOn(objectiveService, 'getAlignmentPossibilities').mockReturnValue(of(alignmentPossibilities));
jest.spyOn(objectiveService, 'getAlignmentPossibilities').mockReturnValue(of([]));
fixture = TestBed.createComponent(ObjectiveFormComponent);
component = fixture.componentInstance;
fixture.detectChanges();
Expand Down Expand Up @@ -432,6 +432,10 @@ describe('ObjectiveDialogComponent', () => {
});

it('should load correct alignment possibilities', async () => {
jest.spyOn(objectiveService, 'getAlignmentPossibilities').mockReturnValue(of(alignmentPossibilities));
fixture.detectChanges();
component.ngOnInit();

let generatedPossibilities = [
{
objectiveId: null,
Expand Down Expand Up @@ -465,15 +469,53 @@ describe('ObjectiveDialogComponent', () => {
it('should not load current Objective to alignment possibilities', async () => {
matDataMock.objective.objectiveId = 1;
component.objective = objectiveWithAlignment;
const routerHarness = await RouterTestingHarness.create();
await routerHarness.navigateByUrl('/?quarter=2');
objectiveService.getFullObjective.mockReturnValue(of(objectiveWithAlignment));
jest.spyOn(objectiveService, 'getAlignmentPossibilities').mockReturnValue(of(alignmentPossibilities));
fixture.detectChanges();
component.ngOnInit();

let generatedPossibilities = [
{
objectiveId: null,
objectiveTitle: 'Bitte wählen',
objectiveTitle: 'Kein Alignment',
keyResultAlignmentsDtos: [],
},
{
objectiveId: 1003,
objectiveTitle: 'O - Test Objective',
keyResultAlignmentsDtos: [],
},
{
objectiveId: 1005,
objectiveTitle: 'O - Company will grow',
keyResultAlignmentsDtos: [
{
keyResultId: 6,
keyResultTitle: 'K - New structure',
},
],
},
];

let componentValue = null;
component.alignmentPossibilities$.subscribe((value) => {
componentValue = value;
});
expect(componentValue).toStrictEqual(generatedPossibilities);
});

it('should load Kein Alignment to alignment possibilities when objective have an alignment', async () => {
component.objective = objective;
component.data.objective.objectiveId = 5;
objectiveService.getFullObjective.mockReturnValue(of(objectiveWithAlignment));
jest.spyOn(objectiveService, 'getAlignmentPossibilities').mockReturnValue(of(alignmentPossibilities));
fixture.detectChanges();
component.ngOnInit();

let generatedPossibilities = [
{
objectiveId: null,
objectiveTitle: 'Kein Alignment',
keyResultAlignmentsDtos: [],
},
{
Expand All @@ -500,6 +542,45 @@ describe('ObjectiveDialogComponent', () => {
expect(componentValue).toStrictEqual(generatedPossibilities);
});

it('should load Kein Alignment to alignment possibilities when choosing one alignment', async () => {
jest.spyOn(objectiveService, 'getAlignmentPossibilities').mockReturnValue(of(alignmentPossibilities));
objectiveService.getFullObjective.mockReturnValue(of(objective));
component.objective = objective;
component.data.objective.objectiveId = 5;
fixture.detectChanges();
component.ngOnInit();
component.changeFirstAlignmentPossibility();

let currentPossibilities = [
{
objectiveId: null,
objectiveTitle: 'Kein Alignment',
keyResultAlignmentsDtos: [],
},
{
objectiveId: 1003,
objectiveTitle: 'O - Test Objective',
keyResultAlignmentsDtos: [],
},
{
objectiveId: 1005,
objectiveTitle: 'O - Company will grow',
keyResultAlignmentsDtos: [
{
keyResultId: 6,
keyResultTitle: 'K - New structure',
},
],
},
];

let componentValue = null;
component.alignmentPossibilities$.subscribe((value) => {
componentValue = value;
});
expect(componentValue).toStrictEqual(currentPossibilities);
});

it('should call ObjectiveService when updating Alignments', async () => {
component.updateAlignments();
expect(objectiveService.getAlignmentPossibilities).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,25 @@ export class ObjectiveFormComponent implements OnInit {

generateAlignmentPossibilities(quarterId: number) {
this.alignmentPossibilities$ = this.objectiveService.getAlignmentPossibilities(quarterId);
this.alignmentPossibilities$.subscribe((value) => {
this.alignmentPossibilities$.subscribe((value: AlignmentPossibility[]) => {
if (this.objective?.id) {
value = value.filter((item) => !(item.objectiveId == this.objective!.id));
value = value.filter((item: AlignmentPossibility) => !(item.objectiveId == this.objective!.id));
}
if (value.length == 0 || value[0].objectiveTitle != 'Bitte wählen') {
let noSelectOption: AlignmentPossibility = {
objectiveId: null,
objectiveTitle: 'Bitte wählen',
keyResultAlignmentsDtos: [],
};
value.unshift(noSelectOption);
let firstSelectOption = {
objectiveId: null,
objectiveTitle: 'Kein Alignment',
keyResultAlignmentsDtos: [],
};
if (value.length != 0) {
if (this.objective?.alignedEntityId) {
if (value[0].objectiveTitle == 'Bitte wählen') {
value.splice(0, 1);
}
} else {
firstSelectOption.objectiveTitle = 'Bitte wählen';
}
}
value.unshift(firstSelectOption);
this.alignmentPossibilities$ = of(value);
});
}
Expand All @@ -263,5 +270,15 @@ export class ObjectiveFormComponent implements OnInit {
});
}

changeFirstAlignmentPossibility() {
this.alignmentPossibilities$.subscribe((value: AlignmentPossibility[]) => {
let element: AlignmentPossibility = value[0];
element.objectiveTitle = 'Kein Alignment';
value.splice(0, 1);
value.unshift(element);
this.alignmentPossibilities$ = of(value);
});
}

protected readonly getQuarterLabel = getQuarterLabel;
}

0 comments on commit ae5b684

Please sign in to comment.