Просмотр исходного кода

✅ test(components): update AgoraSTTComponent tests

- add isConnecting state to test cases
- fix import method for useAgoraSTT hook

🔧 chore(config): update claude settings

- add pnpm test:components:* to allowed commands
yourname 4 месяцев назад
Родитель
Сommit
417b77a54c

+ 2 - 1
.claude/settings.local.json

@@ -29,7 +29,8 @@
       "Bash(pnpm run db:backup:latest:*)",
       "Bash(done)",
       "Bash(do sed -i '8d' \"$file\")",
-      "Bash(pnpm test:components)"
+      "Bash(pnpm test:components)",
+      "Bash(pnpm test:components:*)"
     ],
     "deny": [],
     "ask": []

+ 10 - 7
src/client/admin/components/agora-stt/__tests__/AgoraSTTComponent.test.tsx

@@ -61,13 +61,16 @@ vi.mock('lucide-react', () => ({
   WifiOff: () => <span>WifiOff</span>
 }));
 
-const mockUseAgoraSTT = vi.mocked(require('@/client/hooks/useAgoraSTT').useAgoraSTT);
+import { useAgoraSTT } from '@/client/hooks/useAgoraSTT';
+
+const mockUseAgoraSTT = vi.mocked(useAgoraSTT);
 
 describe('AgoraSTTComponent', () => {
   const defaultState = {
     isConnected: false,
     isRecording: false,
     isTranscribing: false,
+    isConnecting: false,
     error: null,
     transcriptionResults: [],
     currentTranscription: ''
@@ -102,7 +105,7 @@ describe('AgoraSTTComponent', () => {
 
   it('shows connection status when connected', () => {
     mockUseAgoraSTT.mockReturnValue({
-      state: { ...defaultState, isConnected: true },
+      state: { ...defaultState, isConnected: true, isConnecting: false },
       joinChannel: mockJoinChannel,
       leaveChannel: mockLeaveChannel,
       startRecording: mockStartRecording,
@@ -118,7 +121,7 @@ describe('AgoraSTTComponent', () => {
 
   it('shows recording status when recording', () => {
     mockUseAgoraSTT.mockReturnValue({
-      state: { ...defaultState, isConnected: true, isRecording: true },
+      state: { ...defaultState, isConnected: true, isRecording: true, isConnecting: false },
       joinChannel: mockJoinChannel,
       leaveChannel: mockLeaveChannel,
       startRecording: mockStartRecording,
@@ -134,7 +137,7 @@ describe('AgoraSTTComponent', () => {
 
   it('shows error message when there is an error', () => {
     mockUseAgoraSTT.mockReturnValue({
-      state: { ...defaultState, error: 'Configuration error' },
+      state: { ...defaultState, error: 'Configuration error', isConnecting: false },
       joinChannel: mockJoinChannel,
       leaveChannel: mockLeaveChannel,
       startRecording: mockStartRecording,
@@ -160,7 +163,7 @@ describe('AgoraSTTComponent', () => {
 
   it('calls startRecording when start button is clicked', async () => {
     mockUseAgoraSTT.mockReturnValue({
-      state: { ...defaultState, isConnected: true },
+      state: { ...defaultState, isConnected: true, isConnecting: false },
       joinChannel: mockJoinChannel,
       leaveChannel: mockLeaveChannel,
       startRecording: mockStartRecording,
@@ -189,7 +192,7 @@ describe('AgoraSTTComponent', () => {
     ];
 
     mockUseAgoraSTT.mockReturnValue({
-      state: { ...defaultState, isConnected: true, transcriptionResults },
+      state: { ...defaultState, isConnected: true, transcriptionResults, isConnecting: false },
       joinChannel: mockJoinChannel,
       leaveChannel: mockLeaveChannel,
       startRecording: mockStartRecording,
@@ -214,7 +217,7 @@ describe('AgoraSTTComponent', () => {
     ];
 
     mockUseAgoraSTT.mockReturnValue({
-      state: { ...defaultState, isConnected: true, transcriptionResults },
+      state: { ...defaultState, isConnected: true, transcriptionResults, isConnecting: false },
       joinChannel: mockJoinChannel,
       leaveChannel: mockLeaveChannel,
       startRecording: mockStartRecording,