PluginProbe
Extendify / 3.1.1
Extendify v3.1.1
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 / tests / unit / Agent / workflows / theme / components / UpdateLogoConfirm.test.jsx

UpdateLogoConfirm.test.jsx in Extendify 3.1.1, at tests/unit/Agent/workflows/theme/components/UpdateLogoConfirm.test.jsx

60 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { UpdateLogoConfirm } from '@agent/workflows/theme/components/UpdateLogoConfirm';
2 import { render } from '@testing-library/react';
3
4 jest.mock('@agent/components/ImageUploader', () => ({
5 ImageUploader: ({ onSave, onCancel }) => (
6 <div>
7 <button type="button" onClick={() => onSave({ imageId: 1 })}>
8 Save
9 </button>
10 <button type="button" onClick={onCancel}>
11 Cancel
12 </button>
13 </div>
14 ),
15 }));
16 jest.mock('@quick-edit/state/store', () => ({
17 useQuickEditStore: (selector) => selector({ agentBlock: { id: 'logo-1' } }),
18 }));
19
20 describe('UpdateLogoConfirm — undo on cancel/unmount', () => {
21 let logoImg;
22
23 beforeEach(() => {
24 const logoWrapper = document.createElement('div');
25 logoWrapper.className = 'wp-block-site-logo';
26 logoImg = document.createElement('img');
27 logoImg.src = 'http://example.com/original-logo.png';
28 logoWrapper.appendChild(logoImg);
29 document.body.appendChild(logoWrapper);
30 });
31
32 afterEach(() => {
33 document.querySelector('.wp-block-site-logo')?.remove();
34 });
35
36 test('restores original logo src on unmount without confirming', () => {
37 const { unmount } = render(
38 <UpdateLogoConfirm onConfirm={jest.fn()} onCancel={jest.fn()} />,
39 );
40 // Simulate a selection changing the logo
41 logoImg.src = 'http://example.com/new-logo.png';
42 unmount();
43 expect(logoImg.src).toBe('http://example.com/original-logo.png');
44 });
45
46 test('does not restore logo after confirming', async () => {
47 const onConfirm = jest.fn();
48 const { unmount, getByText } = render(
49 <UpdateLogoConfirm onConfirm={onConfirm} onCancel={jest.fn()} />,
50 );
51 logoImg.src = 'http://example.com/new-logo.png';
52 const saveBtn = getByText('Save');
53 saveBtn.click();
54 await Promise.resolve(); // flush async onConfirm
55 unmount();
56 // Should not have restored because confirmed was set
57 expect(logoImg.src).toBe('http://example.com/new-logo.png');
58 });
59 });
60