|
20 | 20 | * (objectui#12456): five tabs, Objects the landing, each other tab its |
21 | 21 | * section, the facet panels kept mounted for the Save gate, the bulk strip |
22 | 22 | * on every row with keyboard focus marking the row, CRUD granting the four |
23 | | - * cells, and the sharing chip and the object count. |
| 23 | + * cells, and the sharing chip and the object count; |
| 24 | + * - the sharing chip leaves a dirty matrix only after the unsaved-edits |
| 25 | + * question: declined, the page stays on the set with the edit; confirmed, |
| 26 | + * it opens the overview; a clean matrix asks nothing (CONTROL). |
24 | 27 | */ |
25 | 28 |
|
26 | 29 | import '@testing-library/jest-dom/vitest'; |
@@ -505,3 +508,44 @@ describe('the matrix\'s five sections on the page (objectui#12456)', () => { |
505 | 508 | await waitFor(() => expect(where()).toBe(`/studio/${CUSTOM_PKG}/owd?object=crm_lead`)); |
506 | 509 | }); |
507 | 510 | }); |
| 511 | + |
| 512 | +/** |
| 513 | + * The sharing chip is a `role="button"` badge that calls `navigate()`: the |
| 514 | + * shell's link-click listener never sees it, so the page's own guard is all |
| 515 | + * that keeps a dirty matrix's edits (`confirmUnsavedLeave`). |
| 516 | + */ |
| 517 | +describe('the sharing chip asks before it leaves a dirty matrix (objectstack#36905)', () => { |
| 518 | + const editCell = () => screen.getByRole('checkbox', { name: `crm_lead ${en('perm.action.edit')}` }); |
| 519 | + |
| 520 | + async function openDirty() { |
| 521 | + mount(CUSTOM_PKG); |
| 522 | + await screen.findByTestId('perm-row-crm_lead', undefined, { timeout: 8000 }); |
| 523 | + fireEvent.click(editCell()); |
| 524 | + expect(editCell()).toBeChecked(); |
| 525 | + } |
| 526 | + |
| 527 | + it('declined, the page stays on the set and keeps the edit', async () => { |
| 528 | + await openDirty(); |
| 529 | + window.confirm = vi.fn(() => false) as unknown as typeof window.confirm; |
| 530 | + fireEvent.click(screen.getByTestId('owd-badge-crm_lead')); |
| 531 | + expect(window.confirm).toHaveBeenCalledTimes(1); |
| 532 | + expect(window.confirm).toHaveBeenCalledWith(en('engine.edit.unsavedLeaveConfirm')); |
| 533 | + expect(where()).toBe(`/studio/${CUSTOM_PKG}/metadata/permission/${SET}?package=${CUSTOM_PKG}`); |
| 534 | + expect(editCell()).toBeChecked(); |
| 535 | + }); |
| 536 | + |
| 537 | + it('confirmed, it opens the overview on its object', async () => { |
| 538 | + await openDirty(); |
| 539 | + fireEvent.click(screen.getByTestId('owd-badge-crm_lead')); |
| 540 | + expect(window.confirm).toHaveBeenCalledTimes(1); |
| 541 | + await waitFor(() => expect(where()).toBe(`/studio/${CUSTOM_PKG}/owd?object=crm_lead`)); |
| 542 | + }); |
| 543 | + |
| 544 | + it('CONTROL: a clean matrix asks nothing', async () => { |
| 545 | + mount(CUSTOM_PKG); |
| 546 | + await screen.findByTestId('perm-row-crm_lead', undefined, { timeout: 8000 }); |
| 547 | + fireEvent.click(screen.getByTestId('owd-badge-crm_lead')); |
| 548 | + await waitFor(() => expect(where()).toBe(`/studio/${CUSTOM_PKG}/owd?object=crm_lead`)); |
| 549 | + expect(window.confirm).not.toHaveBeenCalled(); |
| 550 | + }); |
| 551 | +}); |
0 commit comments