Skip to content

Commit 542e632

Browse files
authored
Merge pull request #103 from toddaheath/feature/app-authenticated-tests
Add App authenticated feature tests
2 parents 3317650 + 0a53aa0 commit 542e632

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

src/shed-builder-ui/src/components/__tests__/App.test.tsx

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,131 @@ describe('App', () => {
204204
expect(screen.getByText(/too many requests/i)).toBeInTheDocument();
205205
});
206206
});
207+
208+
it('toggles dark mode when authenticated', async () => {
209+
const { getStoredToken } = await getApi();
210+
vi.mocked(getStoredToken).mockReturnValue('valid-token');
211+
212+
const { unmount } = render(<App />);
213+
214+
await waitFor(() => {
215+
expect(screen.getByLabelText('Toggle dark mode')).toBeInTheDocument();
216+
});
217+
218+
// Click the dark mode toggle
219+
await userEvent.click(screen.getByLabelText('Toggle dark mode'));
220+
221+
// The button should still be present after toggle
222+
expect(screen.getByLabelText('Toggle dark mode')).toBeInTheDocument();
223+
224+
unmount();
225+
});
226+
227+
it('shows empty state when no design is selected', async () => {
228+
const { getStoredToken } = await getApi();
229+
vi.mocked(getStoredToken).mockReturnValue('valid-token');
230+
231+
const { unmount } = render(<App />);
232+
233+
await waitFor(() => {
234+
expect(screen.getByText('Select or create a design to begin')).toBeInTheDocument();
235+
});
236+
237+
// Should not show undo/redo when no design is selected
238+
expect(screen.queryByLabelText('Undo')).not.toBeInTheDocument();
239+
expect(screen.queryByLabelText('Redo')).not.toBeInTheDocument();
240+
241+
unmount();
242+
});
243+
244+
it('shows 3D viewer after creating a design', async () => {
245+
const { getStoredToken, api: mockApi } = await getApi();
246+
vi.mocked(getStoredToken).mockReturnValue('valid-token');
247+
248+
const newDesign = {
249+
id: 'new-id',
250+
name: 'New Shed',
251+
widthFeet: 10,
252+
widthInches: 0,
253+
depthFeet: 12,
254+
depthInches: 0,
255+
heightFeet: 8,
256+
heightInches: 0,
257+
roofPitch: 4,
258+
roofType: 'Gable' as const,
259+
openings: [],
260+
createdAt: '2024-01-01T00:00:00Z',
261+
updatedAt: '2024-01-01T00:00:00Z',
262+
};
263+
vi.mocked(mockApi.createDesign).mockResolvedValue(newDesign);
264+
vi.mocked(mockApi.listDesigns)
265+
.mockResolvedValueOnce({ items: [], totalCount: 0 })
266+
.mockResolvedValue({ items: [newDesign], totalCount: 1 });
267+
268+
const { unmount } = render(<App />);
269+
270+
await waitFor(() => {
271+
expect(screen.getByText('Select or create a design to begin')).toBeInTheDocument();
272+
});
273+
274+
// Open create dialog
275+
await userEvent.click(screen.getByLabelText('Create new design'));
276+
277+
// Fill in the name and submit
278+
const nameInput = screen.getByLabelText('Design Name');
279+
await userEvent.type(nameInput, 'New Shed');
280+
await userEvent.click(screen.getByRole('button', { name: 'Create' }));
281+
282+
await waitFor(() => {
283+
expect(screen.getByTestId('shed-viewer')).toBeInTheDocument();
284+
});
285+
286+
// Undo/Redo should now be visible (design is active)
287+
expect(screen.getByLabelText('Undo')).toBeInTheDocument();
288+
expect(screen.getByLabelText('Redo')).toBeInTheDocument();
289+
290+
unmount();
291+
});
292+
293+
it('shows tabs when a design is selected', async () => {
294+
const { getStoredToken, api: mockApi } = await getApi();
295+
vi.mocked(getStoredToken).mockReturnValue('valid-token');
296+
297+
const design = {
298+
id: 'd1',
299+
name: 'Test Shed',
300+
widthFeet: 10,
301+
widthInches: 0,
302+
depthFeet: 12,
303+
depthInches: 0,
304+
heightFeet: 8,
305+
heightInches: 0,
306+
roofPitch: 4,
307+
roofType: 'Gable' as const,
308+
openings: [],
309+
createdAt: '2024-01-01T00:00:00Z',
310+
updatedAt: '2024-01-01T00:00:00Z',
311+
};
312+
vi.mocked(mockApi.createDesign).mockResolvedValue(design);
313+
vi.mocked(mockApi.listDesigns)
314+
.mockResolvedValueOnce({ items: [], totalCount: 0 })
315+
.mockResolvedValue({ items: [design], totalCount: 1 });
316+
317+
const { unmount } = render(<App />);
318+
319+
// Open create dialog and create a design to get tabs to show
320+
await userEvent.click(screen.getByLabelText('Create new design'));
321+
const nameInput = screen.getByLabelText('Design Name');
322+
await userEvent.type(nameInput, 'Test Shed');
323+
await userEvent.click(screen.getByRole('button', { name: 'Create' }));
324+
325+
await waitFor(() => {
326+
expect(screen.getByRole('tab', { name: 'Design' })).toBeInTheDocument();
327+
});
328+
329+
expect(screen.getByRole('tab', { name: 'BOM' })).toBeInTheDocument();
330+
expect(screen.getByRole('tab', { name: 'Versions' })).toBeInTheDocument();
331+
332+
unmount();
333+
});
207334
});

0 commit comments

Comments
 (0)