Skip to content

Add JavaScript unit tests for Redux state management #794

@GaryJones

Description

@GaryJones

Summary

The JavaScript codebase lacks unit test coverage for critical state management code. Adding tests will prevent regressions and enable confident refactoring.

Scope

Priority 1: Redux Reducers (src/react/reducers/)

  • apiReducer - Entry CRUD operations, polling state, error handling
  • userReducer - Author selection, config loading
  • Test state shape, immutability, edge cases

Priority 2: Redux-Observable Epics (src/react/epics/)

  • getEntriesEpic - Pagination, error handling
  • pollingEpic - Start/stop, interval handling
  • crudEpic - Create/update/delete operations
  • Use RxJS marble testing for async flows

Priority 3: React Components

  • AuthorSelectOption - Keyboard navigation, focus states
  • EntryContainer - Edit mode, delete confirmation
  • Use React Testing Library

Technical Approach

# Dependencies already available
npm test -- --coverage
// Example reducer test
describe('apiReducer', () => {
  it('handles GET_ENTRIES_SUCCESS', () => {
    const action = { type: 'GET_ENTRIES_SUCCESS', payload: [entry1] };
    const state = apiReducer(initialState, action);
    expect(state.entries).toHaveLength(1);
    expect(state.loading).toBe(false);
  });
});

Acceptance Criteria

  • 80%+ coverage for reducers
  • All epics tested with marble diagrams
  • Critical user flows covered
  • Tests run in CI pipeline

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions