Selaa lähdekoodia

✅ test(agora-stt): add e2e tests for token and configuration

- 添加Token和配置统一获取验证测试
- 添加配置常量显示验证测试
- 添加Token API错误处理测试
- 验证连接状态更新和组件功能正常性
yourname 4 kuukautta sitten
vanhempi
sitoutus
dd018f39c6
1 muutettua tiedostoa jossa 70 lisäystä ja 0 poistoa
  1. 70 0
      tests/e2e/specs/admin/agora-stt.spec.ts

+ 70 - 0
tests/e2e/specs/admin/agora-stt.spec.ts

@@ -178,6 +178,76 @@ test.describe('Agora实时语音转录功能', () => {
     await expect(agoraSTTPage.page.getByRole('region', { name: '语音转文字组件' })).toBeVisible();
     await expect(agoraSTTPage.page.getByRole('region', { name: '语音转文字组件' })).toBeVisible();
   });
   });
 
 
+  test('Token和配置统一获取验证', async ({ agoraSTTPage, page }) => {
+    // 监听网络请求,验证Token API调用
+    const tokenApiRequests: string[] = [];
+
+    page.on('request', (request) => {
+      if (request.url().includes('/api/v1/agora/token')) {
+        tokenApiRequests.push(request.url());
+      }
+    });
+
+    // 加入频道,这会触发Token和配置获取
+    await agoraSTTPage.joinChannel();
+
+    // 验证Token API被调用
+    expect(tokenApiRequests.length).toBeGreaterThan(0);
+
+    // 验证请求参数包含正确的type和channel
+    const requestUrl = tokenApiRequests[0];
+    expect(requestUrl).toContain('type=rtc');
+    expect(requestUrl).toContain('channel=');
+
+    // 验证连接状态正确更新
+    const connectionStatus = await agoraSTTPage.getConnectionStatus();
+    expect(connectionStatus).toBe('已连接');
+
+    // 验证组件功能正常
+    await expect(agoraSTTPage.startRecordingButton).toBeVisible();
+    await expect(agoraSTTPage.clearTranscriptionsButton).toBeVisible();
+  });
+
+  test('配置常量显示验证', async ({ agoraSTTPage, page }) => {
+    // 加入频道以获取配置常量
+    await agoraSTTPage.joinChannel();
+
+    // 验证配置信息显示(如果组件显示配置信息)
+    // 这里可以检查页面是否显示了从API获取的配置常量
+
+    // 验证组件状态正常,没有错误
+    const hasError = await agoraSTTPage.hasError();
+    expect(hasError).toBe(false);
+
+    // 验证连接状态
+    const connectionStatus = await agoraSTTPage.getConnectionStatus();
+    expect(connectionStatus).toBe('已连接');
+  });
+
+  test('Token API错误处理', async ({ agoraSTTPage, page }) => {
+    // 模拟Token API失败
+    await page.route('**/api/v1/agora/token*', async (route) => {
+      await route.fulfill({
+        status: 500,
+        contentType: 'application/json',
+        body: JSON.stringify({ message: 'Token生成失败' })
+      });
+    });
+
+    // 尝试加入频道
+    await agoraSTTPage.joinChannelButton.click();
+
+    // 验证错误处理
+    await expect(agoraSTTPage.errorAlert).toBeVisible({ timeout: 5000 });
+
+    // 验证连接状态未改变
+    const connectionStatus = await agoraSTTPage.getConnectionStatus();
+    expect(connectionStatus).toBe('未连接');
+
+    // 恢复正常路由
+    await page.unroute('**/api/v1/agora/token*');
+  });
+
   test('完整流程测试', async ({ agoraSTTPage }) => {
   test('完整流程测试', async ({ agoraSTTPage }) => {
     // 完整测试语音转文字流程
     // 完整测试语音转文字流程