|
1 | 1 | /* Copyright 2024 Marimo. All rights reserved. */ |
2 | 2 |
|
3 | | -import { act, fireEvent, render } from "@testing-library/react"; |
| 3 | +import { act, render } from "@testing-library/react"; |
4 | 4 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
5 | 5 | import type { IPluginProps } from "../../types"; |
6 | 6 | import { NumberPlugin } from "../NumberPlugin"; |
@@ -61,84 +61,4 @@ describe("NumberPlugin", () => { |
61 | 61 | rerender(plugin.render(resetProps)); |
62 | 62 | expect(input.value).toBe("0"); |
63 | 63 | }); |
64 | | - |
65 | | - it("handles both immediate prop changes and debounced user input", () => { |
66 | | - const plugin = new NumberPlugin(); |
67 | | - const host = document.createElement("div"); |
68 | | - const setValue = vi.fn(); |
69 | | - |
70 | | - const props: IPluginProps< |
71 | | - number | null, |
72 | | - (typeof plugin)["validator"]["_type"] |
73 | | - > = { |
74 | | - host, |
75 | | - value: 5, |
76 | | - setValue, |
77 | | - data: { |
78 | | - start: 0, |
79 | | - stop: 10, |
80 | | - step: 1, |
81 | | - label: null, |
82 | | - debounce: true, |
83 | | - fullWidth: false, |
84 | | - }, |
85 | | - functions: {}, |
86 | | - }; |
87 | | - |
88 | | - // Initial render - setValue should be called immediately with initial value |
89 | | - const { getByRole, rerender } = render(plugin.render(props)); |
90 | | - |
91 | | - // Wait for React-Aria NumberField to initialize |
92 | | - act(() => { |
93 | | - vi.advanceTimersByTime(0); |
94 | | - }); |
95 | | - |
96 | | - expect(setValue).toHaveBeenCalledWith(5); |
97 | | - |
98 | | - // Clear the mock to test debounced user input |
99 | | - setValue.mockClear(); |
100 | | - |
101 | | - const input = getByRole("textbox", { |
102 | | - name: "Number input", |
103 | | - }) as HTMLInputElement; |
104 | | - expect(input).toBeTruthy(); |
105 | | - |
106 | | - // Simulate user typing and committing the value |
107 | | - act(() => { |
108 | | - // Focus and type the value |
109 | | - fireEvent.focus(input); |
110 | | - // Simulate React-Aria NumberField value change |
111 | | - fireEvent.change(input, { target: { value: "7" } }); |
112 | | - // Commit the value with Enter key |
113 | | - fireEvent.keyDown(input, { key: "Enter" }); |
114 | | - }); |
115 | | - |
116 | | - // Let React process the input |
117 | | - act(() => { |
118 | | - vi.advanceTimersByTime(0); |
119 | | - }); |
120 | | - |
121 | | - // Commit the value |
122 | | - act(() => { |
123 | | - fireEvent.blur(input); |
124 | | - }); |
125 | | - |
126 | | - // Process debounced updates |
127 | | - act(() => { |
128 | | - vi.advanceTimersByTime(200); |
129 | | - }); |
130 | | - |
131 | | - // Should call setValue after debounce for user input |
132 | | - expect(setValue).toHaveBeenCalledWith(7); |
133 | | - |
134 | | - // Clear the mock again to test immediate prop changes |
135 | | - setValue.mockClear(); |
136 | | - |
137 | | - // Update props - should trigger immediate setValue |
138 | | - const updatedProps = { ...props, value: 3 }; |
139 | | - rerender(plugin.render(updatedProps)); |
140 | | - expect(setValue).toHaveBeenCalledWith(3); |
141 | | - |
142 | | - vi.useRealTimers(); |
143 | | - }); |
144 | 64 | }); |
0 commit comments