diff --git a/frontend/e2e/README.md b/frontend/e2e/README.md index 0911bc7..72f0d7e 100644 --- a/frontend/e2e/README.md +++ b/frontend/e2e/README.md @@ -2,7 +2,7 @@ One automated happy path through the real Angular UI and Spring Boot API: sign in as `agent` → land on the home screen → open customer lookup → search -**Amina** → open **CUS-1001** → record an interaction → see it on her timeline → soft-delete it again (keeps runs repeatable). +**Amina** → open **CUS-1001** → record an interaction → see it on her timeline → soft-delete it again, accepting the confirm (keeps runs repeatable). It is **not** part of `ng test` or `mvn test` and not in default CI: it needs a running backend, PostgreSQL, Kafka, and a real Chrome. diff --git a/frontend/e2e/crm-happy-path.e2e.mjs b/frontend/e2e/crm-happy-path.e2e.mjs index 71381bd..a57486b 100644 --- a/frontend/e2e/crm-happy-path.e2e.mjs +++ b/frontend/e2e/crm-happy-path.e2e.mjs @@ -101,7 +101,11 @@ test('agent records an interaction for Amina and sees it on her timeline', async assert.match(await row.getText(), /NOTE/); // 5. Clean up: soft-delete it (audit row stays in PostgreSQL by design). + // The UI asks before deleting; accept the browser confirm. await row.findElement(byTestId('delete-interaction')).click(); + const prompt = await driver.wait(until.alertIsPresent(), WAIT_MS); + assert.match(await prompt.getText(), new RegExp(`Delete "${summary}" for .*CUS-1001`)); + await prompt.accept(); await driver.wait(async () => { for (const r of await driver.findElements(byTestId('interaction-row'))) { if ((await r.getText()).includes(summary)) return false; diff --git a/frontend/src/app/features/customers/customer-detail-page.component.ts b/frontend/src/app/features/customers/customer-detail-page.component.ts index 6f90177..31b37fe 100644 --- a/frontend/src/app/features/customers/customer-detail-page.component.ts +++ b/frontend/src/app/features/customers/customer-detail-page.component.ts @@ -105,6 +105,7 @@ export class CustomerDetailPageComponent implements OnInit { close(): void { const current = this.customer(); if (!current) return; + if (!window.confirm(`Close ${current.fullName} (${current.customerId})?`)) return; this.closing.set(true); this.error.set(null); this.api.delete(current.customerId).subscribe({ diff --git a/frontend/src/app/features/customers/customer-pages.spec.ts b/frontend/src/app/features/customers/customer-pages.spec.ts index 66b1792..cb9deb8 100644 --- a/frontend/src/app/features/customers/customer-pages.spec.ts +++ b/frontend/src/app/features/customers/customer-pages.spec.ts @@ -88,12 +88,29 @@ describe('customer pages', () => { expect(api.getById).toHaveBeenCalledWith('CUS-1001'); expect(fixture.nativeElement.textContent).toContain('Amina Khan'); + const confirm = spyOn(window, 'confirm').and.returnValue(true); fixture.componentInstance.close(); + expect(confirm).toHaveBeenCalledWith('Close Amina Khan (CUS-1001)?'); expect(api.delete).toHaveBeenCalledWith('CUS-1001'); expect(celebration.celebrate).toHaveBeenCalledTimes(1); expect(navigate).toHaveBeenCalledWith(['/customers']); }); + it('detail page does nothing when the close is not confirmed', async () => { + await configure('CUS-1001'); + router = TestBed.inject(Router); + const navigate = spyOn(router, 'navigate').and.returnValue(Promise.resolve(true)); + const fixture = TestBed.createComponent(CustomerDetailPageComponent); + fixture.detectChanges(); + + spyOn(window, 'confirm').and.returnValue(false); + fixture.componentInstance.close(); + + expect(api.delete).not.toHaveBeenCalled(); + expect(celebration.celebrate).not.toHaveBeenCalled(); + expect(navigate).not.toHaveBeenCalled(); + }); + it('detail page shows the error and skips confetti when the close is refused', async () => { api.delete.and.returnValue( throwError(() => new HttpErrorResponse({ status: 403, statusText: 'Forbidden' })), @@ -104,6 +121,7 @@ describe('customer pages', () => { const fixture = TestBed.createComponent(CustomerDetailPageComponent); fixture.detectChanges(); + spyOn(window, 'confirm').and.returnValue(true); fixture.componentInstance.close(); expect(api.delete).toHaveBeenCalledWith('CUS-1001'); diff --git a/frontend/src/app/features/interactions/interaction-detail-page.component.ts b/frontend/src/app/features/interactions/interaction-detail-page.component.ts index b53c2a6..3249870 100644 --- a/frontend/src/app/features/interactions/interaction-detail-page.component.ts +++ b/frontend/src/app/features/interactions/interaction-detail-page.component.ts @@ -148,6 +148,7 @@ export class InteractionDetailPageComponent implements OnInit { remove(): void { const current = this.interaction(); if (!current) return; + if (!window.confirm(`Delete "${current.summary}" for ${current.customerId}?`)) return; this.deleting.set(true); this.error.set(null); this.api.delete(current.id).subscribe({ diff --git a/frontend/src/app/features/interactions/interaction-list-page.component.ts b/frontend/src/app/features/interactions/interaction-list-page.component.ts index 9c6cc35..617edab 100644 --- a/frontend/src/app/features/interactions/interaction-list-page.component.ts +++ b/frontend/src/app/features/interactions/interaction-list-page.component.ts @@ -120,6 +120,9 @@ export class InteractionListPageComponent { } remove(row: Interaction): void { + const customer = this.customers().find((c) => c.customerId === row.customerId); + const who = customer ? `${customer.fullName} (${row.customerId})` : row.customerId; + if (!window.confirm(`Delete "${row.summary}" for ${who}?`)) return; this.savedNotice.set(''); this.error.set(null); this.api.delete(row.id).subscribe({ diff --git a/frontend/src/app/features/interactions/interaction-pages.spec.ts b/frontend/src/app/features/interactions/interaction-pages.spec.ts index c2bc1bd..3fa4225 100644 --- a/frontend/src/app/features/interactions/interaction-pages.spec.ts +++ b/frontend/src/app/features/interactions/interaction-pages.spec.ts @@ -68,6 +68,33 @@ describe('interaction pages', () => { expect(fixture.nativeElement.textContent).toContain('Requested address update'); }); + it('list page deletes a row only after the user confirms', () => { + const fixture: ComponentFixture = + TestBed.createComponent(InteractionListPageComponent); + fixture.detectChanges(); + const confirm = spyOn(window, 'confirm').and.returnValue(false); + + fixture.componentInstance.remove(sample); + expect(confirm).toHaveBeenCalledWith(`Delete "${sample.summary}" for CUS-1001?`); + expect(api.delete).not.toHaveBeenCalled(); + + confirm.and.returnValue(true); + fixture.componentInstance.remove(sample); + expect(api.delete).toHaveBeenCalledWith(sample.id); + }); + + it('detail page keeps the interaction when the delete is not confirmed', () => { + const navigate = spyOn(router, 'navigate').and.returnValue(Promise.resolve(true)); + const fixture = TestBed.createComponent(InteractionDetailPageComponent); + fixture.detectChanges(); + spyOn(window, 'confirm').and.returnValue(false); + + fixture.componentInstance.remove(); + + expect(api.delete).not.toHaveBeenCalled(); + expect(navigate).not.toHaveBeenCalled(); + }); + it('create page submits the Lab 49 DTO and routes to the created detail', () => { const navigate = spyOn(router, 'navigate').and.returnValue(Promise.resolve(true)); const fixture = TestBed.createComponent(InteractionCreatePageComponent); @@ -99,7 +126,9 @@ describe('interaction pages', () => { summary: 'Updated', }); + const confirm = spyOn(window, 'confirm').and.returnValue(true); fixture.componentInstance.remove(); + expect(confirm).toHaveBeenCalledWith('Delete "Updated" for CUS-1001?'); expect(api.delete).toHaveBeenCalledWith(sample.id); expect(navigate).toHaveBeenCalledWith(['/interactions'], { queryParams: { customerId: 'CUS-1001' },