Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1654,11 +1654,6 @@
"count": 1
}
},
"src/app/features/tasks/checker-inbox/checker-inbox.component.ts": {
"no-restricted-imports": {
"count": 1
}
},
"src/app/features/tasks/checker-inbox/view-payload-dialog.component.spec.ts": {
"no-restricted-imports": {
"count": 1
Expand Down
121 changes: 121 additions & 0 deletions src/app/features/tasks/checker-inbox/checker-inbox.component.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { of, throwError } from 'rxjs';
import { MakerCheckerOr4EyeFunctionalityService } from '../../../api';
import { provideFakeAdapters } from '../../../testing/adapters';
import { provideTranslateTesting } from '../../../testing/i18n-testing';
import { createSpyObj, SpyObj } from '../../../testing/mocks';
import { CheckerInboxComponent } from './checker-inbox.component';

describe('CheckerInboxComponent', () => {
let component: CheckerInboxComponent;
let fixture: ComponentFixture<CheckerInboxComponent>;
let serviceSpy: SpyObj<MakerCheckerOr4EyeFunctionalityService>;
let adapters: ReturnType<typeof provideFakeAdapters>;

beforeEach(async () => {
serviceSpy = createSpyObj([
'getMakercheckers',
'postMakercheckersAuditId',
'deleteMakercheckersAuditId',
]);
serviceSpy.getMakercheckers.mockReturnValue(
of([]) as unknown as ReturnType<MakerCheckerOr4EyeFunctionalityService['getMakercheckers']>,
);
serviceSpy.postMakercheckersAuditId.mockReturnValue(
of({}) as unknown as ReturnType<
MakerCheckerOr4EyeFunctionalityService['postMakercheckersAuditId']
>,
);
adapters = provideFakeAdapters();

await TestBed.configureTestingModule({
imports: [CheckerInboxComponent],
providers: [
...provideTranslateTesting(),
...adapters.providers,
{ provide: MakerCheckerOr4EyeFunctionalityService, useValue: serviceSpy },
],
}).compileComponents();

fixture = TestBed.createComponent(CheckerInboxComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('rejects through the reject command without deleting the audit entry', async () => {
adapters.overlay.nextModalResult = true;

await component.onReject({ id: 7 });

expect(serviceSpy.postMakercheckersAuditId).toHaveBeenCalledWith(7, 'reject');
expect(serviceSpy.deleteMakercheckersAuditId).not.toHaveBeenCalled();
expect(serviceSpy.getMakercheckers).toHaveBeenCalledTimes(2);
expect(adapters.overlay.lastToast).toEqual(
expect.objectContaining({
message: 'CHECKER_INBOX.REJECT_SUCCESS',
cssClass: 'success-toast',
}),
);
});

it('uses the standard destructive confirmation dialog', async () => {
adapters.overlay.nextModalResult = false;

await component.onReject({ id: 7 });

expect(adapters.overlay.lastModal?.inputs?.['data']).toEqual(
expect.objectContaining({
title: 'CHECKER_INBOX.REJECT_TITLE',
message: 'CHECKER_INBOX.CONFIRM_REJECT',
destructive: true,
}),
);
});

it('does not call either endpoint when rejection is cancelled', async () => {
adapters.overlay.nextModalResult = false;

await component.onReject({ id: 7 });

expect(serviceSpy.postMakercheckersAuditId).not.toHaveBeenCalled();
expect(serviceSpy.deleteMakercheckersAuditId).not.toHaveBeenCalled();
});

it('reports a failed rejection without refreshing the inbox', async () => {
adapters.overlay.nextModalResult = true;
serviceSpy.postMakercheckersAuditId.mockReturnValue(
throwError(() => new Error('request failed')) as ReturnType<
MakerCheckerOr4EyeFunctionalityService['postMakercheckersAuditId']
>,
);

await component.onReject({ id: 7 });

expect(serviceSpy.getMakercheckers).toHaveBeenCalledTimes(1);
expect(adapters.overlay.lastToast).toEqual(
expect.objectContaining({
message: 'CHECKER_INBOX.REJECT_ERROR',
cssClass: 'error-toast',
}),
);
});
});
40 changes: 23 additions & 17 deletions src/app/features/tasks/checker-inbox/checker-inbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@

import { Component, inject, signal } from '@angular/core';

import { TranslateModule } from '@ngx-translate/core';
import { Subject, of } from 'rxjs';
import { catchError, map, startWith, switchMap, tap } from 'rxjs/operators';
import { DataTableComponent, CellTemplateDirective, ColumnDef } from '../../../shared';
import { MakerCheckerOr4EyeFunctionalityService, AuditData } from '../../../api';
import { ViewPayloadDialogComponent } from './view-payload-dialog.component';
import { IonButton, IonIcon } from '@ionic/angular/standalone';
import { I18N, TranslatePipe } from '../../../core/adapters';
import { NotificationService } from '../../../core/services/notification.service';
import { DialogService } from '../../../core/services/dialog.service';

@Component({
selector: 'app-checker-inbox',
standalone: true,
imports: [TranslateModule, DataTableComponent, CellTemplateDirective, IonIcon, IonButton],
imports: [TranslatePipe, DataTableComponent, CellTemplateDirective, IonIcon, IonButton],
template: `
<app-data-table
[hasError]="hasError()"
Expand All @@ -54,23 +54,23 @@ import { DialogService } from '../../../core/services/dialog.service';
fill="clear"
color="primary"
(click)="onViewPayload(task)"
[attr.aria-label]="'CHECKER_INBOX.VIEW_PAYLOAD' | translate"
[attr.aria-label]="'CHECKER_INBOX.VIEW_PAYLOAD' | appTranslate"
>
<ion-icon name="eye-outline"></ion-icon>
</ion-button>
<ion-button
fill="clear"
class="approve-btn"
(click)="onApprove(task)"
[attr.aria-label]="'ACTIONS.APPROVE' | translate"
[attr.aria-label]="'ACTIONS.APPROVE' | appTranslate"
>
<ion-icon name="checkmark-circle-outline"></ion-icon>
</ion-button>
<ion-button
fill="clear"
color="danger"
(click)="onReject(task)"
[attr.aria-label]="'ACTIONS.REJECT' | translate"
[attr.aria-label]="'ACTIONS.REJECT' | appTranslate"
>
<ion-icon name="close-circle-outline"></ion-icon>
</ion-button>
Expand All @@ -97,6 +97,7 @@ export class CheckerInboxComponent {
private readonly makerCheckerService = inject(MakerCheckerOr4EyeFunctionalityService);
private readonly notifications = inject(NotificationService);
private readonly dialogService = inject(DialogService);
private readonly i18n = inject(I18N);

columns: ColumnDef[] = [
{ key: 'id', label: 'COMMON.ID', sortable: true },
Expand Down Expand Up @@ -161,18 +162,23 @@ export class CheckerInboxComponent {
});
}

onReject(task: Record<string, unknown>) {
if (confirm('Are you sure you want to reject this task?')) {
this.makerCheckerService.deleteMakercheckersAuditId(task['id'] as number).subscribe({
next: () => {
this.notifications.success('Task rejected successfully');
this.refreshSubject.next();
},
error: () => {
this.notifications.error('Failed to reject task');
},
});
}
async onReject(task: Record<string, unknown>): Promise<void> {
const confirmed = await this.dialogService.confirm({
title: this.i18n.translate('CHECKER_INBOX.REJECT_TITLE'),
message: this.i18n.translate('CHECKER_INBOX.CONFIRM_REJECT'),
destructive: true,
});
if (!confirmed) return;

this.makerCheckerService.postMakercheckersAuditId(task['id'] as number, 'reject').subscribe({
next: () => {
this.notifications.success(this.i18n.translate('CHECKER_INBOX.REJECT_SUCCESS'));
this.refreshSubject.next();
},
error: () => {
this.notifications.error(this.i18n.translate('CHECKER_INBOX.REJECT_ERROR'));
},
});
}

formatDate(dateArray: unknown): string {
Expand Down
6 changes: 5 additions & 1 deletion src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2074,7 +2074,11 @@
"NO_STEPS": "No steps configured for this job."
},
"CHECKER_INBOX": {
"VIEW_PAYLOAD": "View payload"
"VIEW_PAYLOAD": "View payload",
"REJECT_TITLE": "Reject task",
"CONFIRM_REJECT": "Are you sure you want to reject this task?",
"REJECT_SUCCESS": "Task rejected successfully",
"REJECT_ERROR": "Failed to reject task"
},
"BUSINESS_DATES": {
"TITLE": "Business Date Management",
Expand Down