From c3d4ffd06a3732acc5d4fc4769823946d41bec7c Mon Sep 17 00:00:00 2001 From: Nuwan Date: Sun, 8 Feb 2026 12:20:39 +0530 Subject: [PATCH] test(17-01): add tests for UNIT-01, UNIT-02, UNIT-03 requirements UNIT-01: Modal renders with currentSession props - Test privacy value displayed from currentSession - Test description value displayed from currentSession - Test modal title renders UNIT-02: Save functionality - Test onSave called with correct payload on save click - Test onSave called with updated values after user changes UNIT-03: Loading state - Test save button disabled when loading - Test cancel button disabled when loading - Test description textarea disabled when loading - Test "Saving..." text shown when loading --- .../__tests__/JKSessionSettingsModal.test.js | 116 +++++++++++++++++- 1 file changed, 112 insertions(+), 4 deletions(-) diff --git a/jam-ui/src/components/client/__tests__/JKSessionSettingsModal.test.js b/jam-ui/src/components/client/__tests__/JKSessionSettingsModal.test.js index 9ef79b770..764202ede 100644 --- a/jam-ui/src/components/client/__tests__/JKSessionSettingsModal.test.js +++ b/jam-ui/src/components/client/__tests__/JKSessionSettingsModal.test.js @@ -33,9 +33,117 @@ const renderModal = (props = {}) => { }; describe('JKSessionSettingsModal', () => { - // Placeholder test to verify setup - test('renders without crashing', () => { - renderModal(); - expect(screen.getByText('Session Settings')).toBeInTheDocument(); + // UNIT-01: Modal renders with currentSession props + describe('rendering with currentSession props (UNIT-01)', () => { + test('displays privacy value from currentSession', () => { + renderModal({ + currentSession: { + privacy: SESSION_PRIVACY_MAP.public, + description: '' + } + }); + + const privacySelect = screen.getByTestId('session-privacy'); + expect(privacySelect.value).toBe(String(SESSION_PRIVACY_MAP.public)); + }); + + test('displays description value from currentSession', () => { + const testDescription = 'My test session description'; + renderModal({ + currentSession: { + privacy: SESSION_PRIVACY_MAP.private_approve, + description: testDescription + } + }); + + const descriptionInput = screen.getByRole('textbox'); + expect(descriptionInput.value).toBe(testDescription); + }); + + test('renders modal title', () => { + renderModal(); + expect(screen.getByText('Session Settings')).toBeInTheDocument(); + }); + }); + + // UNIT-02: Save button calls onSave with correct payload + describe('save functionality (UNIT-02)', () => { + test('calls onSave with privacy and description when save clicked', () => { + const mockOnSave = jest.fn(); + renderModal({ + currentSession: { + privacy: SESSION_PRIVACY_MAP.public, + description: 'Original description' + }, + onSave: mockOnSave + }); + + const saveButton = screen.getByRole('button', { name: /save/i }); + fireEvent.click(saveButton); + + expect(mockOnSave).toHaveBeenCalledTimes(1); + expect(mockOnSave).toHaveBeenCalledWith({ + privacy: SESSION_PRIVACY_MAP.public, + description: 'Original description' + }); + }); + + test('calls onSave with updated values after user changes', () => { + const mockOnSave = jest.fn(); + renderModal({ + currentSession: { + privacy: SESSION_PRIVACY_MAP.private_approve, + description: '' + }, + onSave: mockOnSave + }); + + // Change privacy + const privacySelect = screen.getByTestId('session-privacy'); + fireEvent.change(privacySelect, { target: { value: String(SESSION_PRIVACY_MAP.public) } }); + + // Change description + const descriptionInput = screen.getByRole('textbox'); + fireEvent.change(descriptionInput, { target: { value: 'New description' } }); + + // Click save + const saveButton = screen.getByRole('button', { name: /save/i }); + fireEvent.click(saveButton); + + expect(mockOnSave).toHaveBeenCalledWith({ + privacy: String(SESSION_PRIVACY_MAP.public), + description: 'New description' + }); + }); + }); + + // UNIT-03: Loading state disables form interactions + describe('loading state (UNIT-03)', () => { + test('disables save button when loading', () => { + renderModal({ loading: true }); + + const saveButton = screen.getByRole('button', { name: /saving/i }); + expect(saveButton).toBeDisabled(); + }); + + test('disables cancel button when loading', () => { + renderModal({ loading: true }); + + const cancelButton = screen.getByRole('button', { name: /cancel/i }); + expect(cancelButton).toBeDisabled(); + }); + + test('disables description textarea when loading', () => { + renderModal({ loading: true }); + + const descriptionInput = screen.getByRole('textbox'); + expect(descriptionInput).toBeDisabled(); + }); + + test('shows "Saving..." text on save button when loading', () => { + renderModal({ loading: true }); + + expect(screen.getByRole('button', { name: /saving/i })).toBeInTheDocument(); + }); }); });