Skip to content

fix: update SpeechProvider tests for ElevenLabs API key integration#2135

Open
rustforrecess wants to merge 2 commits into
cboard-org:masterfrom
rustforrecess:fix/speech-provider-tests-elevenlabs
Open

fix: update SpeechProvider tests for ElevenLabs API key integration#2135
rustforrecess wants to merge 2 commits into
cboard-org:masterfrom
rustforrecess:fix/speech-provider-tests-elevenlabs

Conversation

@rustforrecess

Copy link
Copy Markdown

Summary

Fixes failing SpeechProvider tests after the ElevenLabs API key integration (#2052).

  • Reducer test: Updated initialState to include the 5 new fields added by the ElevenLabs integration (elevenLabsApiKey, elevenLabsVoiceSettings, and three new options fields). Added test case for CHANGE_ELEVENLABS_API_KEY action.
  • Actions test: Mocked the tts module to fix the store.getState() crash (tts now depends on the Redux store). Mocked window.speechSynthesis for JSDOM compatibility. Updated changeVoice test to use mockStore dispatch since it was refactored into a thunk. Added test for changeElevenLabsApiKey action creator.

Test plan

  • Run npx react-scripts test --watchAll=false --testPathPattern=Speech — all 3 suites should pass (20 tests)
  • Confirm no regressions in the broader test suite

Closes #2052

🤖 Generated with Claude Code

- Add missing ElevenLabs fields to reducer test initialState
- Add CHANGE_ELEVENLABS_API_KEY test to reducer tests
- Mock tts module in actions tests to fix store.getState() crash
- Mock window.speechSynthesis for JSDOM compatibility
- Update changeVoice test to use mockStore dispatch (now a thunk)
- Add changeElevenLabsApiKey action test

Closes cboard-org#2052

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates SpeechProvider unit tests to align with the recent ElevenLabs API key/state integration so the Speech-related Jest suites pass again.

Changes:

  • Updated reducer test initialState to include newly added ElevenLabs-related state fields.
  • Added reducer coverage for CHANGE_ELEVENLABS_API_KEY.
  • Updated actions tests to accommodate thunk-based changeVoice and mocked tts/speech synthesis dependencies.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/providers/SpeechProvider/__tests__/SpeechProvider.reducer.test.js Aligns reducer test expectations with updated reducer initial state and adds API key action coverage.
src/providers/SpeechProvider/__tests__/SpeechProvider.actions.test.js Adjusts action tests for thunk dispatch and adds mocks/new action coverage for ElevenLabs API key changes.

Comment on lines +194 to +199
elevenLabsApiKey: 'sk-test-key'
};
expect(speechProviderReducer(initialState, changeElevenLabsApiKey)).toEqual(
{
...initialState,
elevenLabsApiKey: 'sk-test-key'

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test value "sk-test-key" looks like a real secret/API-key prefix and can trigger secret scanning / false-positive credential alerts. Prefer a clearly non-secret placeholder (e.g., "test-api-key" / "ELEVENLABS_API_KEY") to avoid CI/security tooling noise.

Suggested change
elevenLabsApiKey: 'sk-test-key'
};
expect(speechProviderReducer(initialState, changeElevenLabsApiKey)).toEqual(
{
...initialState,
elevenLabsApiKey: 'sk-test-key'
elevenLabsApiKey: 'test-api-key'
};
expect(speechProviderReducer(initialState, changeElevenLabsApiKey)).toEqual(
{
...initialState,
elevenLabsApiKey: 'test-api-key'

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Renamed to test-api-key in the latest push.

Comment on lines +16 to +24
global.window.speechSynthesis = {
getVoices: jest.fn(() => [
{ voiceURI: 'test-voice-en', lang: 'en-US', name: 'Test Voice' }
]),
speak: jest.fn(),
cancel: jest.fn(),
pause: jest.fn(),
resume: jest.fn()
};

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file already gets a window.speechSynthesis mock from src/setupTests.js. Overriding it here with a new plain object is redundant and can drift from the shared mock, making failures harder to diagnose. Prefer relying on the shared setup mock, or patch only the specific methods/return values needed for this suite (e.g., adjust getVoices) in a beforeAll/beforeEach.

Suggested change
global.window.speechSynthesis = {
getVoices: jest.fn(() => [
{ voiceURI: 'test-voice-en', lang: 'en-US', name: 'Test Voice' }
]),
speak: jest.fn(),
cancel: jest.fn(),
pause: jest.fn(),
resume: jest.fn()
};
global.window.speechSynthesis.getVoices.mockImplementation(() => [
{ voiceURI: 'test-voice-en', lang: 'en-US', name: 'Test Voice' }
]);

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! I looked into this but unfortunately setupTests.js defines getVoices as a plain function (not a jest.fn()), so .mockImplementation() isn't available on it. The cancel mock on line 36 of setupTests.js is a jest.fn(), but getVoices on line 33-35 is just a regular arrow function attached via Object.defineProperty.

Since speechSynthesis is set with writable: true in setupTests.js, overriding the whole object here is safe and each test file runs in its own Jest sandbox, so it won't affect other tests.

Comment on lines +150 to +155
it('should create an action to change ElevenLabs API key', () => {
const elevenLabsApiKey = 'sk-test-key';
const expectedAction = {
type: types.CHANGE_ELEVENLABS_API_KEY,
elevenLabsApiKey
};

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test value "sk-test-key" resembles a real API key prefix and may trigger secret scanning / credential-detection tooling. Use an unmistakably fake placeholder (e.g., "test-api-key" / "ELEVENLABS_API_KEY") to avoid false positives.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest push — renamed to test-api-key.

Addresses review feedback on cboard-org#2135. Renames sk-test-key to
test-api-key in both test files.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SpeechProvider tests fails after ElevenLabs API key integration

2 participants