@getmicdrop/svelte-components 2.0.4 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Alert/Alert.spec.js +170 -170
- package/dist/components/Badges/Badge.spec.js +103 -103
- package/dist/components/BottomSheet/BottomSheet.spec.js +127 -127
- package/dist/components/Breadcrumb/Breadcrumb.spec.js +120 -120
- package/dist/components/Button/Button.spec.js +211 -211
- package/dist/components/Button/ButtonSaveDemo.spec.js +48 -48
- package/dist/components/Calendar/Calendar.spec.js +131 -131
- package/dist/components/Calendar/QuarterView.spec.js +394 -394
- package/dist/components/Card.spec.js +47 -47
- package/dist/components/CropImage/CropImage.spec.js +216 -216
- package/dist/components/DarkModeToggle.spec.js +357 -357
- package/dist/components/ErrorDisplay.spec.js +69 -69
- package/dist/components/FormActions.spec.js +88 -88
- package/dist/components/FormValidationSummary.spec.js +203 -203
- package/dist/components/Icons/Icon.spec.js +175 -175
- package/dist/components/Icons/MoreHori.spec.js +67 -67
- package/dist/components/Icons/WarningIcon.spec.js +30 -30
- package/dist/components/Input/Input.spec.js +573 -573
- package/dist/components/Input/MultiSelect.spec.js +257 -257
- package/dist/components/Input/OTPInput.spec.js +238 -238
- package/dist/components/Input/Select.spec.js +218 -218
- package/dist/components/Layout/BottomNav.spec.js +130 -130
- package/dist/components/Layout/Header.spec.js +203 -203
- package/dist/components/Modal/ConfirmationModal.spec.js +191 -191
- package/dist/components/Modal/Modal.spec.js +95 -95
- package/dist/components/Modal/ModalStateManager.spec.js +100 -100
- package/dist/components/PageLoader.spec.js +54 -54
- package/dist/components/PasswordStrengthIndicator/PasswordStrengthIndicator.spec.js +173 -173
- package/dist/components/PlaceAutocomplete/PlaceAutocomplete.spec.js +300 -300
- package/dist/components/Spinner/Spinner.spec.js +75 -75
- package/dist/components/StatusIndicator/StatusIndicator.spec.js +129 -129
- package/dist/components/Toaster/Toaster.stories.svelte +1 -1
- package/dist/components/Toggle.spec.js +158 -158
- package/dist/components/ValidationError.spec.js +79 -79
- package/dist/components/pages/performers/AvailabilityCalendarModal.spec.js +606 -606
- package/dist/components/pages/performers/AvailabilityCalendarModal.svelte +4 -4
- package/dist/components/pages/performers/ModalShowInfo.spec.js +124 -124
- package/dist/components/pages/performers/ModalShowInfo.svelte +1 -1
- package/dist/components/pages/performers/PageBackButton.spec.js +89 -89
- package/dist/components/pages/performers/SectionHeader.spec.js +75 -75
- package/dist/components/pages/performers/ShowDetails.spec.js +166 -166
- package/dist/components/pages/performers/ShowItemCard.spec.js +793 -793
- package/dist/components/pages/performers/ShowItemCard.svelte +4 -4
- package/dist/components/pages/performers/SwitchOption.spec.js +127 -127
- package/dist/components/pages/performers/VenueInfo.spec.js +167 -167
- package/dist/components/pages/performers/VenueInfo.svelte +1 -1
- package/dist/components/pages/performers/VenueItemCard.spec.js +763 -763
- package/dist/components/pages/performers/VenueItemCard.svelte +4 -4
- package/dist/components/pages/profile/profile-form.spec.js +9 -9
- package/dist/components/pages/settings/tabs/CustomImageDropzone.svelte +3 -3
- package/dist/components/pages/shows/ShowList.spec.js +33 -33
- package/dist/components/pages/shows/TabContent.spec.js +90 -90
- package/dist/components/pages/shows/TabNavigation.spec.js +143 -143
- package/dist/config.js +5 -5
- package/dist/config.spec.js +29 -29
- package/dist/constants/formOptions.js +25 -25
- package/dist/constants/formOptions.spec.js +88 -88
- package/dist/index.js +111 -111
- package/dist/stores/auth.d.ts +9 -0
- package/dist/stores/auth.d.ts.map +1 -0
- package/dist/stores/auth.js +36 -0
- package/dist/stores/auth.spec.d.ts +2 -0
- package/dist/stores/auth.spec.d.ts.map +1 -0
- package/dist/stores/auth.spec.js +139 -0
- package/dist/stores/formDataStore.d.ts +17 -0
- package/dist/stores/formDataStore.d.ts.map +1 -0
- package/dist/stores/formDataStore.js +25 -0
- package/dist/stores/formDataStore.spec.d.ts +2 -0
- package/dist/stores/formDataStore.spec.d.ts.map +1 -0
- package/dist/stores/formDataStore.spec.js +257 -0
- package/dist/stores/formSave.d.ts +24 -0
- package/dist/stores/formSave.d.ts.map +1 -0
- package/dist/stores/formSave.js +132 -0
- package/dist/stores/formSave.spec.d.ts +2 -0
- package/dist/stores/formSave.spec.d.ts.map +1 -0
- package/dist/stores/formSave.spec.js +296 -0
- package/dist/stores/index.d.ts +1 -0
- package/dist/stores/index.d.ts.map +1 -0
- package/dist/stores/index.js +0 -0
- package/dist/stores/navigation.d.ts +5 -0
- package/dist/stores/navigation.d.ts.map +1 -0
- package/dist/stores/navigation.js +12 -0
- package/dist/stores/navigation.spec.d.ts +2 -0
- package/dist/stores/navigation.spec.d.ts.map +1 -0
- package/dist/stores/navigation.spec.js +136 -0
- package/dist/stores/toaster.d.ts +4 -0
- package/dist/stores/toaster.d.ts.map +1 -0
- package/dist/stores/toaster.js +13 -0
- package/dist/stores/toaster.spec.d.ts +2 -0
- package/dist/stores/toaster.spec.d.ts.map +1 -0
- package/dist/stores/toaster.spec.js +59 -0
- package/dist/telemetry.js +357 -357
- package/dist/telemetry.server.js +211 -211
- package/dist/telemetry.server.spec.js +434 -434
- package/dist/telemetry.spec.js +660 -660
- package/dist/utils/apiConfig.js +49 -49
- package/dist/utils/apiConfig.spec.js +118 -118
- package/dist/utils/greetings.js +187 -187
- package/dist/utils/greetings.spec.js +337 -337
- package/dist/utils/imageValidation.js +121 -121
- package/dist/utils/imageValidation.spec.js +220 -220
- package/dist/utils/portal.js +25 -25
- package/dist/utils/portal.spec.js +143 -143
- package/dist/utils/utils/utils.js +323 -323
- package/dist/utils/utils/utils.spec.js +698 -698
- package/dist/utils/utils.spec.js +643 -643
- package/package.json +1 -1
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { render, screen } from "@testing-library/svelte";
|
|
2
|
-
import { expect, describe, test } from "vitest";
|
|
3
|
-
import Card from "./Card.svelte";
|
|
4
|
-
|
|
5
|
-
describe("Card Component Tests", () => {
|
|
6
|
-
test("Renders card section element", () => {
|
|
7
|
-
render(Card, { props: {} });
|
|
8
|
-
const section = document.querySelector("section");
|
|
9
|
-
expect(section).toBeInTheDocument();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test("Applies base classes", () => {
|
|
13
|
-
render(Card, { props: {} });
|
|
14
|
-
const section = document.querySelector("section");
|
|
15
|
-
expect(section).toHaveClass("w-full");
|
|
16
|
-
expect(section).toHaveClass("bg-bg-primary");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test("Applies custom className", () => {
|
|
20
|
-
render(Card, { props: { className: "custom-class mt-4" } });
|
|
21
|
-
const section = document.querySelector("section");
|
|
22
|
-
expect(section).toHaveClass("custom-class");
|
|
23
|
-
expect(section).toHaveClass("mt-4");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("Has responsive padding classes", () => {
|
|
27
|
-
render(Card, { props: {} });
|
|
28
|
-
const section = document.querySelector("section");
|
|
29
|
-
// Check for responsive padding classes
|
|
30
|
-
expect(section.className).toMatch(/p-3\.5/);
|
|
31
|
-
expect(section.className).toMatch(/sm:p-4/);
|
|
32
|
-
expect(section.className).toMatch(/md:p-5/);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("Has shadow and rounded on medium screens", () => {
|
|
36
|
-
render(Card, { props: {} });
|
|
37
|
-
const section = document.querySelector("section");
|
|
38
|
-
expect(section.className).toMatch(/md:shadow/);
|
|
39
|
-
expect(section.className).toMatch(/md:rounded-lg/);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("Renders slot content", () => {
|
|
43
|
-
// Use a custom component with slot content
|
|
44
|
-
const { container } = render(Card, { props: {} });
|
|
45
|
-
expect(container.querySelector("section")).toBeInTheDocument();
|
|
46
|
-
});
|
|
47
|
-
});
|
|
1
|
+
import { render, screen } from "@testing-library/svelte";
|
|
2
|
+
import { expect, describe, test } from "vitest";
|
|
3
|
+
import Card from "./Card.svelte";
|
|
4
|
+
|
|
5
|
+
describe("Card Component Tests", () => {
|
|
6
|
+
test("Renders card section element", () => {
|
|
7
|
+
render(Card, { props: {} });
|
|
8
|
+
const section = document.querySelector("section");
|
|
9
|
+
expect(section).toBeInTheDocument();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("Applies base classes", () => {
|
|
13
|
+
render(Card, { props: {} });
|
|
14
|
+
const section = document.querySelector("section");
|
|
15
|
+
expect(section).toHaveClass("w-full");
|
|
16
|
+
expect(section).toHaveClass("bg-bg-primary");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("Applies custom className", () => {
|
|
20
|
+
render(Card, { props: { className: "custom-class mt-4" } });
|
|
21
|
+
const section = document.querySelector("section");
|
|
22
|
+
expect(section).toHaveClass("custom-class");
|
|
23
|
+
expect(section).toHaveClass("mt-4");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("Has responsive padding classes", () => {
|
|
27
|
+
render(Card, { props: {} });
|
|
28
|
+
const section = document.querySelector("section");
|
|
29
|
+
// Check for responsive padding classes
|
|
30
|
+
expect(section.className).toMatch(/p-3\.5/);
|
|
31
|
+
expect(section.className).toMatch(/sm:p-4/);
|
|
32
|
+
expect(section.className).toMatch(/md:p-5/);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("Has shadow and rounded on medium screens", () => {
|
|
36
|
+
render(Card, { props: {} });
|
|
37
|
+
const section = document.querySelector("section");
|
|
38
|
+
expect(section.className).toMatch(/md:shadow/);
|
|
39
|
+
expect(section.className).toMatch(/md:rounded-lg/);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("Renders slot content", () => {
|
|
43
|
+
// Use a custom component with slot content
|
|
44
|
+
const { container } = render(Card, { props: {} });
|
|
45
|
+
expect(container.querySelector("section")).toBeInTheDocument();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -1,216 +1,216 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { render, screen, fireEvent, waitFor } from '@testing-library/svelte';
|
|
3
|
-
|
|
4
|
-
// Mock svelte-easy-crop with the mock Svelte component
|
|
5
|
-
vi.mock('svelte-easy-crop', async () => {
|
|
6
|
-
const MockCropper = await import('../../__mocks__/svelte-easy-crop.svelte');
|
|
7
|
-
return { default: MockCropper.default };
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
// Import after mock is set up
|
|
11
|
-
import CropImage from './CropImage.svelte';
|
|
12
|
-
|
|
13
|
-
describe('CropImage', () => {
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
vi.clearAllMocks();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('when showModal is false', () => {
|
|
19
|
-
it('does not render modal content', () => {
|
|
20
|
-
const { container } = render(CropImage, {
|
|
21
|
-
props: { showModal: false, imageSrc: '' },
|
|
22
|
-
});
|
|
23
|
-
expect(container.querySelector('.fixed')).toBeNull();
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('when showModal is true', () => {
|
|
28
|
-
const defaultProps = {
|
|
29
|
-
showModal: true,
|
|
30
|
-
imageSrc: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==',
|
|
31
|
-
onSave: vi.fn(),
|
|
32
|
-
onCancel: vi.fn(),
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
it('renders the modal', () => {
|
|
36
|
-
const { container } = render(CropImage, { props: defaultProps });
|
|
37
|
-
expect(container.querySelector('.fixed')).toBeInTheDocument();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('renders the header with title', () => {
|
|
41
|
-
render(CropImage, { props: defaultProps });
|
|
42
|
-
expect(screen.getByText('Crop image')).toBeInTheDocument();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('renders cancel button', () => {
|
|
46
|
-
render(CropImage, { props: defaultProps });
|
|
47
|
-
expect(screen.getByText('Cancel')).toBeInTheDocument();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('renders save button', () => {
|
|
51
|
-
render(CropImage, { props: defaultProps });
|
|
52
|
-
expect(screen.getByText('Save')).toBeInTheDocument();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('renders instructions text', () => {
|
|
56
|
-
render(CropImage, { props: defaultProps });
|
|
57
|
-
expect(screen.getByText(/Drag to position/)).toBeInTheDocument();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('renders zoom controls', () => {
|
|
61
|
-
render(CropImage, { props: defaultProps });
|
|
62
|
-
expect(screen.getByLabelText('Zoom out')).toBeInTheDocument();
|
|
63
|
-
expect(screen.getByLabelText('Zoom in')).toBeInTheDocument();
|
|
64
|
-
expect(screen.getByLabelText('Zoom level')).toBeInTheDocument();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('shows loading state initially', () => {
|
|
68
|
-
render(CropImage, { props: defaultProps });
|
|
69
|
-
expect(screen.getByText('Loading...')).toBeInTheDocument();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('calls onCancel when cancel button clicked', async () => {
|
|
73
|
-
const onCancel = vi.fn();
|
|
74
|
-
render(CropImage, { props: { ...defaultProps, onCancel } });
|
|
75
|
-
|
|
76
|
-
await fireEvent.click(screen.getByText('Cancel'));
|
|
77
|
-
expect(onCancel).toHaveBeenCalled();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('calls onCancel when close button clicked', async () => {
|
|
81
|
-
const onCancel = vi.fn();
|
|
82
|
-
render(CropImage, { props: { ...defaultProps, onCancel } });
|
|
83
|
-
|
|
84
|
-
await fireEvent.click(screen.getByLabelText('Close'));
|
|
85
|
-
expect(onCancel).toHaveBeenCalled();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('calls onCancel when clicking backdrop', async () => {
|
|
89
|
-
const onCancel = vi.fn();
|
|
90
|
-
const { container } = render(CropImage, { props: { ...defaultProps, onCancel } });
|
|
91
|
-
|
|
92
|
-
const backdrop = container.querySelector('.fixed');
|
|
93
|
-
await fireEvent.click(backdrop);
|
|
94
|
-
expect(onCancel).toHaveBeenCalled();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('zoom out button decreases zoom', async () => {
|
|
98
|
-
render(CropImage, { props: defaultProps });
|
|
99
|
-
const zoomOutBtn = screen.getByLabelText('Zoom out');
|
|
100
|
-
const slider = screen.getByLabelText('Zoom level');
|
|
101
|
-
|
|
102
|
-
// Initial zoom is 1
|
|
103
|
-
expect(slider.value).toBe('1');
|
|
104
|
-
|
|
105
|
-
// Click zoom out (should stay at 1 since that's min)
|
|
106
|
-
await fireEvent.click(zoomOutBtn);
|
|
107
|
-
expect(slider.value).toBe('1');
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('zoom in button increases zoom', async () => {
|
|
111
|
-
render(CropImage, { props: defaultProps });
|
|
112
|
-
const zoomInBtn = screen.getByLabelText('Zoom in');
|
|
113
|
-
const slider = screen.getByLabelText('Zoom level');
|
|
114
|
-
|
|
115
|
-
await fireEvent.click(zoomInBtn);
|
|
116
|
-
expect(parseFloat(slider.value)).toBeGreaterThan(1);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('hides loading state after crop complete', async () => {
|
|
120
|
-
render(CropImage, { props: defaultProps });
|
|
121
|
-
|
|
122
|
-
// Initially loading
|
|
123
|
-
expect(screen.getByText('Loading...')).toBeInTheDocument();
|
|
124
|
-
|
|
125
|
-
// Wait for the mock cropper to emit cropcomplete
|
|
126
|
-
await waitFor(() => {
|
|
127
|
-
expect(screen.queryByText('Loading...')).not.toBeInTheDocument();
|
|
128
|
-
}, { timeout: 100 });
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('slider controls zoom value', async () => {
|
|
132
|
-
render(CropImage, { props: defaultProps });
|
|
133
|
-
const slider = screen.getByLabelText('Zoom level');
|
|
134
|
-
|
|
135
|
-
await fireEvent.input(slider, { target: { value: '2' } });
|
|
136
|
-
expect(slider.value).toBe('2');
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('handles save button click when not loading', async () => {
|
|
140
|
-
const onSave = vi.fn();
|
|
141
|
-
render(CropImage, { props: { ...defaultProps, onSave } });
|
|
142
|
-
|
|
143
|
-
// Wait for loading to complete
|
|
144
|
-
await waitFor(() => {
|
|
145
|
-
expect(screen.queryByText('Loading...')).not.toBeInTheDocument();
|
|
146
|
-
}, { timeout: 200 });
|
|
147
|
-
|
|
148
|
-
// Try clicking save button
|
|
149
|
-
const saveButton = screen.getByText('Save');
|
|
150
|
-
await fireEvent.click(saveButton);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('disables save button while loading', () => {
|
|
154
|
-
render(CropImage, { props: defaultProps });
|
|
155
|
-
const saveButton = screen.getByText('Save');
|
|
156
|
-
// Save button should be disabled during loading
|
|
157
|
-
expect(saveButton.closest('button')).toBeDefined();
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('resets state when modal reopens with new image', async () => {
|
|
161
|
-
const { rerender } = render(CropImage, { props: defaultProps });
|
|
162
|
-
|
|
163
|
-
// Change imageSrc to trigger reset
|
|
164
|
-
await rerender({
|
|
165
|
-
showModal: true,
|
|
166
|
-
imageSrc: 'data:image/png;base64,differentImage',
|
|
167
|
-
onSave: vi.fn(),
|
|
168
|
-
onCancel: vi.fn(),
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
expect(screen.getByText('Crop image')).toBeInTheDocument();
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('updates zoom progress based on zoom value', async () => {
|
|
175
|
-
render(CropImage, { props: defaultProps });
|
|
176
|
-
const slider = screen.getByLabelText('Zoom level');
|
|
177
|
-
|
|
178
|
-
// Set zoom to middle value
|
|
179
|
-
await fireEvent.input(slider, { target: { value: '2' } });
|
|
180
|
-
expect(slider.value).toBe('2');
|
|
181
|
-
|
|
182
|
-
// Set zoom to max
|
|
183
|
-
await fireEvent.input(slider, { target: { value: '3' } });
|
|
184
|
-
expect(slider.value).toBe('3');
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it('zoom value stays within bounds', async () => {
|
|
188
|
-
render(CropImage, { props: defaultProps });
|
|
189
|
-
const slider = screen.getByLabelText('Zoom level');
|
|
190
|
-
const zoomOutBtn = screen.getByLabelText('Zoom out');
|
|
191
|
-
const zoomInBtn = screen.getByLabelText('Zoom in');
|
|
192
|
-
|
|
193
|
-
// Spam zoom out - should not go below 1
|
|
194
|
-
for (let i = 0; i < 10; i++) {
|
|
195
|
-
await fireEvent.click(zoomOutBtn);
|
|
196
|
-
}
|
|
197
|
-
expect(parseFloat(slider.value)).toBe(1);
|
|
198
|
-
|
|
199
|
-
// Set to max and spam zoom in
|
|
200
|
-
await fireEvent.input(slider, { target: { value: '3' } });
|
|
201
|
-
for (let i = 0; i < 10; i++) {
|
|
202
|
-
await fireEvent.click(zoomInBtn);
|
|
203
|
-
}
|
|
204
|
-
expect(parseFloat(slider.value)).toBeLessThanOrEqual(3);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it('renders cropper component with correct props', async () => {
|
|
208
|
-
const { container } = render(CropImage, { props: defaultProps });
|
|
209
|
-
|
|
210
|
-
// Wait for render
|
|
211
|
-
await waitFor(() => {
|
|
212
|
-
expect(container.querySelector('.cropper-container')).toBeInTheDocument();
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
});
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent, waitFor } from '@testing-library/svelte';
|
|
3
|
+
|
|
4
|
+
// Mock svelte-easy-crop with the mock Svelte component
|
|
5
|
+
vi.mock('svelte-easy-crop', async () => {
|
|
6
|
+
const MockCropper = await import('../../__mocks__/svelte-easy-crop.svelte');
|
|
7
|
+
return { default: MockCropper.default };
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// Import after mock is set up
|
|
11
|
+
import CropImage from './CropImage.svelte';
|
|
12
|
+
|
|
13
|
+
describe('CropImage', () => {
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
vi.clearAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('when showModal is false', () => {
|
|
19
|
+
it('does not render modal content', () => {
|
|
20
|
+
const { container } = render(CropImage, {
|
|
21
|
+
props: { showModal: false, imageSrc: '' },
|
|
22
|
+
});
|
|
23
|
+
expect(container.querySelector('.fixed')).toBeNull();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('when showModal is true', () => {
|
|
28
|
+
const defaultProps = {
|
|
29
|
+
showModal: true,
|
|
30
|
+
imageSrc: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==',
|
|
31
|
+
onSave: vi.fn(),
|
|
32
|
+
onCancel: vi.fn(),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
it('renders the modal', () => {
|
|
36
|
+
const { container } = render(CropImage, { props: defaultProps });
|
|
37
|
+
expect(container.querySelector('.fixed')).toBeInTheDocument();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('renders the header with title', () => {
|
|
41
|
+
render(CropImage, { props: defaultProps });
|
|
42
|
+
expect(screen.getByText('Crop image')).toBeInTheDocument();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('renders cancel button', () => {
|
|
46
|
+
render(CropImage, { props: defaultProps });
|
|
47
|
+
expect(screen.getByText('Cancel')).toBeInTheDocument();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('renders save button', () => {
|
|
51
|
+
render(CropImage, { props: defaultProps });
|
|
52
|
+
expect(screen.getByText('Save')).toBeInTheDocument();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('renders instructions text', () => {
|
|
56
|
+
render(CropImage, { props: defaultProps });
|
|
57
|
+
expect(screen.getByText(/Drag to position/)).toBeInTheDocument();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('renders zoom controls', () => {
|
|
61
|
+
render(CropImage, { props: defaultProps });
|
|
62
|
+
expect(screen.getByLabelText('Zoom out')).toBeInTheDocument();
|
|
63
|
+
expect(screen.getByLabelText('Zoom in')).toBeInTheDocument();
|
|
64
|
+
expect(screen.getByLabelText('Zoom level')).toBeInTheDocument();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('shows loading state initially', () => {
|
|
68
|
+
render(CropImage, { props: defaultProps });
|
|
69
|
+
expect(screen.getByText('Loading...')).toBeInTheDocument();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('calls onCancel when cancel button clicked', async () => {
|
|
73
|
+
const onCancel = vi.fn();
|
|
74
|
+
render(CropImage, { props: { ...defaultProps, onCancel } });
|
|
75
|
+
|
|
76
|
+
await fireEvent.click(screen.getByText('Cancel'));
|
|
77
|
+
expect(onCancel).toHaveBeenCalled();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('calls onCancel when close button clicked', async () => {
|
|
81
|
+
const onCancel = vi.fn();
|
|
82
|
+
render(CropImage, { props: { ...defaultProps, onCancel } });
|
|
83
|
+
|
|
84
|
+
await fireEvent.click(screen.getByLabelText('Close'));
|
|
85
|
+
expect(onCancel).toHaveBeenCalled();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('calls onCancel when clicking backdrop', async () => {
|
|
89
|
+
const onCancel = vi.fn();
|
|
90
|
+
const { container } = render(CropImage, { props: { ...defaultProps, onCancel } });
|
|
91
|
+
|
|
92
|
+
const backdrop = container.querySelector('.fixed');
|
|
93
|
+
await fireEvent.click(backdrop);
|
|
94
|
+
expect(onCancel).toHaveBeenCalled();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('zoom out button decreases zoom', async () => {
|
|
98
|
+
render(CropImage, { props: defaultProps });
|
|
99
|
+
const zoomOutBtn = screen.getByLabelText('Zoom out');
|
|
100
|
+
const slider = screen.getByLabelText('Zoom level');
|
|
101
|
+
|
|
102
|
+
// Initial zoom is 1
|
|
103
|
+
expect(slider.value).toBe('1');
|
|
104
|
+
|
|
105
|
+
// Click zoom out (should stay at 1 since that's min)
|
|
106
|
+
await fireEvent.click(zoomOutBtn);
|
|
107
|
+
expect(slider.value).toBe('1');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('zoom in button increases zoom', async () => {
|
|
111
|
+
render(CropImage, { props: defaultProps });
|
|
112
|
+
const zoomInBtn = screen.getByLabelText('Zoom in');
|
|
113
|
+
const slider = screen.getByLabelText('Zoom level');
|
|
114
|
+
|
|
115
|
+
await fireEvent.click(zoomInBtn);
|
|
116
|
+
expect(parseFloat(slider.value)).toBeGreaterThan(1);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('hides loading state after crop complete', async () => {
|
|
120
|
+
render(CropImage, { props: defaultProps });
|
|
121
|
+
|
|
122
|
+
// Initially loading
|
|
123
|
+
expect(screen.getByText('Loading...')).toBeInTheDocument();
|
|
124
|
+
|
|
125
|
+
// Wait for the mock cropper to emit cropcomplete
|
|
126
|
+
await waitFor(() => {
|
|
127
|
+
expect(screen.queryByText('Loading...')).not.toBeInTheDocument();
|
|
128
|
+
}, { timeout: 100 });
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('slider controls zoom value', async () => {
|
|
132
|
+
render(CropImage, { props: defaultProps });
|
|
133
|
+
const slider = screen.getByLabelText('Zoom level');
|
|
134
|
+
|
|
135
|
+
await fireEvent.input(slider, { target: { value: '2' } });
|
|
136
|
+
expect(slider.value).toBe('2');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('handles save button click when not loading', async () => {
|
|
140
|
+
const onSave = vi.fn();
|
|
141
|
+
render(CropImage, { props: { ...defaultProps, onSave } });
|
|
142
|
+
|
|
143
|
+
// Wait for loading to complete
|
|
144
|
+
await waitFor(() => {
|
|
145
|
+
expect(screen.queryByText('Loading...')).not.toBeInTheDocument();
|
|
146
|
+
}, { timeout: 200 });
|
|
147
|
+
|
|
148
|
+
// Try clicking save button
|
|
149
|
+
const saveButton = screen.getByText('Save');
|
|
150
|
+
await fireEvent.click(saveButton);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('disables save button while loading', () => {
|
|
154
|
+
render(CropImage, { props: defaultProps });
|
|
155
|
+
const saveButton = screen.getByText('Save');
|
|
156
|
+
// Save button should be disabled during loading
|
|
157
|
+
expect(saveButton.closest('button')).toBeDefined();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('resets state when modal reopens with new image', async () => {
|
|
161
|
+
const { rerender } = render(CropImage, { props: defaultProps });
|
|
162
|
+
|
|
163
|
+
// Change imageSrc to trigger reset
|
|
164
|
+
await rerender({
|
|
165
|
+
showModal: true,
|
|
166
|
+
imageSrc: 'data:image/png;base64,differentImage',
|
|
167
|
+
onSave: vi.fn(),
|
|
168
|
+
onCancel: vi.fn(),
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
expect(screen.getByText('Crop image')).toBeInTheDocument();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('updates zoom progress based on zoom value', async () => {
|
|
175
|
+
render(CropImage, { props: defaultProps });
|
|
176
|
+
const slider = screen.getByLabelText('Zoom level');
|
|
177
|
+
|
|
178
|
+
// Set zoom to middle value
|
|
179
|
+
await fireEvent.input(slider, { target: { value: '2' } });
|
|
180
|
+
expect(slider.value).toBe('2');
|
|
181
|
+
|
|
182
|
+
// Set zoom to max
|
|
183
|
+
await fireEvent.input(slider, { target: { value: '3' } });
|
|
184
|
+
expect(slider.value).toBe('3');
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('zoom value stays within bounds', async () => {
|
|
188
|
+
render(CropImage, { props: defaultProps });
|
|
189
|
+
const slider = screen.getByLabelText('Zoom level');
|
|
190
|
+
const zoomOutBtn = screen.getByLabelText('Zoom out');
|
|
191
|
+
const zoomInBtn = screen.getByLabelText('Zoom in');
|
|
192
|
+
|
|
193
|
+
// Spam zoom out - should not go below 1
|
|
194
|
+
for (let i = 0; i < 10; i++) {
|
|
195
|
+
await fireEvent.click(zoomOutBtn);
|
|
196
|
+
}
|
|
197
|
+
expect(parseFloat(slider.value)).toBe(1);
|
|
198
|
+
|
|
199
|
+
// Set to max and spam zoom in
|
|
200
|
+
await fireEvent.input(slider, { target: { value: '3' } });
|
|
201
|
+
for (let i = 0; i < 10; i++) {
|
|
202
|
+
await fireEvent.click(zoomInBtn);
|
|
203
|
+
}
|
|
204
|
+
expect(parseFloat(slider.value)).toBeLessThanOrEqual(3);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('renders cropper component with correct props', async () => {
|
|
208
|
+
const { container } = render(CropImage, { props: defaultProps });
|
|
209
|
+
|
|
210
|
+
// Wait for render
|
|
211
|
+
await waitFor(() => {
|
|
212
|
+
expect(container.querySelector('.cropper-container')).toBeInTheDocument();
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
});
|