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 / settings / components / UpdateSettingConfirm.test.jsx

UpdateSettingConfirm.test.jsx in Extendify 3.1.1, at tests/unit/Agent/workflows/settings/components/UpdateSettingConfirm.test.jsx

57 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { UpdateSettingConfirm } from '@agent/workflows/settings/components/UpdateSettingConfirm';
2 import { render, screen } from '@testing-library/react';
3 import userEvent from '@testing-library/user-event';
4
5 describe('UpdateSettingConfirm — undo on cancel/unmount', () => {
6 let header;
7
8 beforeEach(() => {
9 header = document.createElement('div');
10 header.className = 'wp-block-site-title';
11 header.textContent = 'Original Title';
12 document.body.appendChild(header);
13 });
14
15 afterEach(() => {
16 header.remove();
17 });
18
19 const inputs = { settingName: 'title', newSettingValue: 'New Title' };
20
21 test('reverts the title when unmounted without confirming', () => {
22 const { unmount } = render(
23 <UpdateSettingConfirm
24 inputs={inputs}
25 onConfirm={jest.fn()}
26 onCancel={jest.fn()}
27 />,
28 );
29
30 expect(header.textContent).toBe('New Title');
31 unmount();
32 expect(header.textContent).toBe('Original Title');
33 });
34
35 test('does not revert the title after confirming', async () => {
36 const onConfirm = jest.fn();
37 const user = userEvent.setup();
38
39 const { unmount } = render(
40 <UpdateSettingConfirm
41 inputs={inputs}
42 onConfirm={onConfirm}
43 onCancel={jest.fn()}
44 />,
45 );
46
47 await user.click(screen.getByRole('button', { name: /confirm/i }));
48 expect(onConfirm).toHaveBeenCalledWith({
49 data: inputs,
50 shouldRefreshPage: true,
51 });
52
53 unmount();
54 expect(header.textContent).toBe('New Title');
55 });
56 });
57