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__ / SelectThemeVariation.test.jsx

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

70 lines 1.8 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 { SelectThemeVariation } from '../SelectThemeVariation';
4
5 const mockUndoChange = jest.fn();
6 jest.mock('@agent/hooks/useVariationOverride', () => ({
7 useVariationOverride: () => ({ undoChange: mockUndoChange }),
8 }));
9 jest.mock('@agent/hooks/useThemeVariations', () => ({
10 useThemeVariations: () => ({
11 variations: [
12 {
13 title: 'Sunset',
14 css: '.sunset{}',
15 settings: {
16 color: {
17 palette: {
18 theme: [
19 { slug: 'background', color: '#fff' },
20 { slug: 'primary', color: '#f00' },
21 ],
22 },
23 },
24 },
25 },
26 ],
27 isLoading: false,
28 }),
29 }));
30 jest.mock('@agent/state/chat', () => ({
31 useChatStore: () => ({ addMessage: jest.fn(), messages: [] }),
32 }));
33
34 beforeEach(() => mockUndoChange.mockClear());
35
36 describe('SelectThemeVariation — undo on cancel/unmount', () => {
37 test('calls undoChange on unmount without confirming', () => {
38 const { unmount } = render(
39 <SelectThemeVariation
40 onConfirm={jest.fn()}
41 onCancel={jest.fn()}
42 onLoad={jest.fn()}
43 />,
44 );
45 unmount();
46 expect(mockUndoChange).toHaveBeenCalledTimes(1);
47 });
48
49 test('does not call undoChange after confirming', async () => {
50 const onConfirm = jest.fn();
51 const user = userEvent.setup();
52 const { unmount } = render(
53 <SelectThemeVariation
54 onConfirm={onConfirm}
55 onCancel={jest.fn()}
56 onLoad={jest.fn()}
57 />,
58 );
59 // Select a variation first
60 const btn = screen
61 .getAllByRole('button')
62 .find((b) => !b.textContent.match(/cancel|save/i));
63 await user.click(btn);
64 await user.click(screen.getByRole('button', { name: /save/i }));
65 expect(onConfirm).toHaveBeenCalled();
66 unmount();
67 expect(mockUndoChange).not.toHaveBeenCalled();
68 });
69 });
70