feat(cart): integrate confirmation modals for item removal in cart component
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
BrowserTestingModule,
|
||||
platformBrowserTesting
|
||||
} from '@angular/platform-browser/testing';
|
||||
import { of } from 'rxjs';
|
||||
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { ModalService } from '../../../../core/services/modal.service';
|
||||
@@ -47,20 +48,11 @@ function createToastServiceStub() {
|
||||
};
|
||||
}
|
||||
|
||||
function createModalRefStub() {
|
||||
return {
|
||||
afterClosed$: {
|
||||
subscribe: vi.fn()
|
||||
},
|
||||
dismissReason: vi.fn().mockReturnValue(null)
|
||||
};
|
||||
}
|
||||
|
||||
function createModalServiceStub() {
|
||||
return {
|
||||
open: vi.fn().mockReturnValue(createModalRefStub()),
|
||||
openConfirm: vi.fn().mockReturnValue(createModalRefStub()),
|
||||
openConfirmDelete: vi.fn().mockReturnValue(createModalRefStub())
|
||||
open: vi.fn(),
|
||||
openConfirm: vi.fn().mockReturnValue(of(true)),
|
||||
openConfirmDelete: vi.fn().mockReturnValue(of(false))
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -198,15 +198,15 @@ export class ReutilizablesTestPageComponent {
|
||||
}
|
||||
|
||||
protected openConfirmDeleteModal(): void {
|
||||
const ref = this.modalService.openConfirmDelete({
|
||||
this.modalService.openConfirmDelete({
|
||||
title: 'Eliminar producto',
|
||||
content:
|
||||
'Esta accion eliminara el producto del catalogo. Podras volver a crearlo manualmente.',
|
||||
confirmLabel: 'Eliminar',
|
||||
cancelLabel: 'Conservar'
|
||||
}).subscribe((confirmed) => {
|
||||
this.lastModalResult = `Resultado: ${confirmed}`;
|
||||
});
|
||||
|
||||
this.handleModalResult(ref);
|
||||
}
|
||||
|
||||
protected openLockedModal(): void {
|
||||
@@ -230,18 +230,8 @@ export class ReutilizablesTestPageComponent {
|
||||
}
|
||||
|
||||
private openConfirmModal(config: Parameters<ModalService['openConfirm']>[0]): void {
|
||||
const ref = this.modalService.openConfirm(config);
|
||||
|
||||
this.handleModalResult(ref);
|
||||
}
|
||||
|
||||
private handleModalResult(ref: ReturnType<ModalService['openConfirm']>): void {
|
||||
ref.afterClosed$.subscribe((result) => {
|
||||
const dismissReason = ref.dismissReason();
|
||||
this.lastModalResult =
|
||||
typeof result === 'boolean'
|
||||
? `Resultado: ${result}`
|
||||
: `Cerrado sin resultado${dismissReason ? ` (${dismissReason})` : ''}.`;
|
||||
this.modalService.openConfirm(config).subscribe((confirmed) => {
|
||||
this.lastModalResult = `Resultado: ${confirmed}`;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user