PluginProbe
Extendify / 3.0.4
Extendify v3.0.4
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Agent / workflows / theme / components / __tests__ / UpdateMenuConfirm.test.jsx

UpdateMenuConfirm.test.jsx in Extendify 3.0.4, at src/Agent/workflows/theme/components/__tests__/UpdateMenuConfirm.test.jsx

63 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { render, screen } from '@testing-library/react';
2 import userEvent from '@testing-library/user-event';
3 import { UpdateMenuConfirm } from '../UpdateMenuConfirm';
4
5 jest.mock('@wordpress/api-fetch', () => ({
6 __esModule: true,
7 default: jest.fn(() => Promise.resolve('<li>New Menu</li>')),
8 }));
9
10 describe('UpdateMenuConfirm — undo on cancel/unmount', () => {
11 let nav;
12
13 beforeEach(() => {
14 nav = document.createElement('nav');
15 nav.setAttribute('data-extendify-menu-id', 'nav-1');
16 nav.innerHTML = '<li>Original Menu</li>';
17 document.body.appendChild(nav);
18 });
19
20 afterEach(() => {
21 nav.remove();
22 });
23
24 const inputs = {
25 id: 'nav-1',
26 replacements: [
27 { original: '<li>Original Menu</li>', updated: '<li>New Menu</li>' },
28 ],
29 };
30
31 test('restores original menu HTML when unmounted without confirming', async () => {
32 const { unmount } = render(
33 <UpdateMenuConfirm
34 inputs={inputs}
35 onConfirm={jest.fn()}
36 onCancel={jest.fn()}
37 />,
38 );
39 // apiFetch updates nav asynchronously
40 await screen.findByText(/review and confirm/i);
41 unmount();
42 expect(nav.innerHTML).toBe('<li>Original Menu</li>');
43 });
44
45 test('does not restore menu after confirming', async () => {
46 const onConfirm = jest.fn();
47 const user = userEvent.setup();
48 const { unmount } = render(
49 <UpdateMenuConfirm
50 inputs={inputs}
51 onConfirm={onConfirm}
52 onCancel={jest.fn()}
53 />,
54 );
55 await screen.findByText(/review and confirm/i);
56 await user.click(screen.getByRole('button', { name: /save/i }));
57 expect(onConfirm).toHaveBeenCalled();
58 unmount();
59 // Menu should NOT be restored since it was confirmed
60 expect(nav.innerHTML).not.toBe('<li>Original Menu</li>');
61 });
62 });
63