Skip to content

Commit 4ec6393

Browse files
Update docs, fix misleading test
1 parent e54e60f commit 4ec6393

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/__tests__/components/ProjectModals.test.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ type StateSlot<T> = { get: () => T; set: (v: T) => void };
148148
/**
149149
* Returns a `useWebViewState` hook stub that stores values in typed per-key closures so state
150150
* persists across re-renders within the same test without requiring any type assertions.
151+
*
152+
* @returns A hook function with the signature `(key, defaultValue) => [value, setter, reset]` where
153+
* `value` is the current stored value for `key` (initially `defaultValue`), `setter` updates it,
154+
* and `reset` removes the slot so the next call re-initializes from `defaultValue`.
151155
*/
152156
function makeWebViewState() {
153157
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -176,9 +180,13 @@ function makeWebViewState() {
176180
}
177181

178182
/**
179-
* Renders ProjectModals with sensible defaults.
183+
* Renders ProjectModals with sensible defaults and returns helpers for assertions.
180184
*
181-
* @param overrides - Partial props to override defaults.
185+
* @param overrides - Partial props to merge over the defaults. Supports `activeProject`, `modal`
186+
* (defaults to `'none'`), `setModal` (defaults to a fresh `jest.fn()`), and `useWebViewState`
187+
* (defaults to a fresh {@link makeWebViewState} instance).
188+
* @returns An object containing `setModal` — either the caller-supplied function or the internally
189+
* created `jest.fn()` — so callers can assert on it after interactions.
182190
*/
183191
function renderModals(
184192
overrides: Partial<{
@@ -312,13 +320,12 @@ describe('ProjectModals', () => {
312320
expect(setModal).toHaveBeenCalledWith('select');
313321
});
314322

315-
it('sets the active project when a project is created', async () => {
323+
it('keeps the create modal open and does not call setModal when a project is created', async () => {
316324
const state = makeWebViewState();
317-
renderModals({ modal: 'create', useWebViewState: state });
325+
const { setModal } = renderModals({ modal: 'create', useWebViewState: state });
318326
await userEvent.click(screen.getByTestId('create-created'));
319-
// State is updated — verify by rendering metadata modal which uses activeProject
320-
// (we can't read state directly, so just confirm no crash)
321327
expect(screen.getByTestId('create-modal')).toBeInTheDocument();
328+
expect(setModal).not.toHaveBeenCalled();
322329
});
323330
});
324331

0 commit comments

Comments
 (0)