mirror of
https://github.com/Melorise/TamaASR.git
synced 2026-11-07 14:39:32 +00:00
fix: 适配新版千问录音状态并升级至 1.0.3
AI-assisted-by: Codex AI-model: gpt-5.6-sol AI-reasoning-effort: medium Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { qianwenAdapter } from '../src/backends/qianwen';
|
||||
import { shouldClickMicrophoneOnStop } from '../src/preload/speech-session-state';
|
||||
|
||||
function microphone(className: string, attributes: Record<string, string | undefined> = {}): HTMLElement {
|
||||
return {
|
||||
classList: { contains: (token: string) => className.split(/\s+/).includes(token) },
|
||||
getAttribute: (name: string) => name === 'class' ? className : attributes[name] ?? null,
|
||||
querySelector: () => null,
|
||||
textContent: ''
|
||||
} as unknown as HTMLElement;
|
||||
}
|
||||
|
||||
test('千问新版录音样式允许点击停止,恢复空闲样式后不再判为录音', () => {
|
||||
let control = microphone('cursor-pointer hover:bg-tag');
|
||||
const adapter = { ...qianwenAdapter, findMicrophone: () => control };
|
||||
const document = {} as Document;
|
||||
assert.equal(adapter.isRecording(document), false);
|
||||
|
||||
control = microphone('pointer-events-auto cursor-pointer bg-tag');
|
||||
assert.equal(adapter.isRecording(document), true);
|
||||
assert.equal(shouldClickMicrophoneOnStop(adapter.isRecording(document), false), true);
|
||||
assert.equal(shouldClickMicrophoneOnStop(adapter.isRecording(document), true), false);
|
||||
|
||||
control = microphone('cursor-pointer hover:bg-tag');
|
||||
assert.equal(adapter.isRecording(document), false);
|
||||
});
|
||||
|
||||
test('千问旧版 aria 和停止文案保持兼容', () => {
|
||||
for (const attributes of [{ 'aria-pressed': 'true' }, { 'aria-label': '停止语音' }]) {
|
||||
const adapter = { ...qianwenAdapter, findMicrophone: () => microphone('', attributes) };
|
||||
assert.equal(adapter.isRecording({} as Document), true);
|
||||
}
|
||||
const adapter = { ...qianwenAdapter, findMicrophone: () => null };
|
||||
assert.equal(adapter.isRecording({} as Document), false);
|
||||
});
|
||||
Reference in New Issue
Block a user