mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-08-07 07:45:54 +00:00
132 lines
3.2 KiB
TypeScript
132 lines
3.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
getComposerPlaceholderKey,
|
|
getComposerPlaceholderState,
|
|
shouldBlockComposerSubmit,
|
|
shouldDisableComposerInput,
|
|
} from './composerInputState';
|
|
|
|
describe('composer input state', () => {
|
|
it('keeps the composer editable while the SSE connection is disconnected', () => {
|
|
expect(
|
|
shouldDisableComposerInput({
|
|
catchingUp: false,
|
|
pendingApproval: false,
|
|
isPreparingPrompt: false,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
getComposerPlaceholderKey({
|
|
catchingUp: false,
|
|
isPreparingPrompt: false,
|
|
isStreaming: false,
|
|
}),
|
|
).toBe('editor.placeholder');
|
|
expect(
|
|
getComposerPlaceholderKey({
|
|
catchingUp: false,
|
|
isPreparingPrompt: false,
|
|
isStreaming: false,
|
|
}),
|
|
).toBe('editor.placeholder');
|
|
});
|
|
|
|
it('keeps loading state only for catch-up or prompt preparation', () => {
|
|
expect(
|
|
shouldDisableComposerInput({
|
|
catchingUp: true,
|
|
pendingApproval: false,
|
|
isPreparingPrompt: false,
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
getComposerPlaceholderKey({
|
|
catchingUp: true,
|
|
isPreparingPrompt: false,
|
|
isStreaming: false,
|
|
}),
|
|
).toBe('common.loading');
|
|
|
|
expect(
|
|
shouldDisableComposerInput({
|
|
catchingUp: false,
|
|
pendingApproval: false,
|
|
isPreparingPrompt: true,
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
getComposerPlaceholderKey({
|
|
catchingUp: false,
|
|
isPreparingPrompt: true,
|
|
isStreaming: false,
|
|
}),
|
|
).toBe('editor.processing');
|
|
});
|
|
|
|
it('shows processing placeholder while streaming', () => {
|
|
expect(
|
|
getComposerPlaceholderKey({
|
|
catchingUp: false,
|
|
isPreparingPrompt: false,
|
|
isStreaming: true,
|
|
}),
|
|
).toBe('editor.processing');
|
|
});
|
|
|
|
it('exposes the semantic placeholder state independently of i18n keys', () => {
|
|
expect(
|
|
getComposerPlaceholderState({
|
|
catchingUp: false,
|
|
isPreparingPrompt: false,
|
|
isStreaming: false,
|
|
}),
|
|
).toBe('idle');
|
|
expect(
|
|
getComposerPlaceholderState({
|
|
catchingUp: true,
|
|
isPreparingPrompt: true,
|
|
isStreaming: true,
|
|
}),
|
|
).toBe('loading');
|
|
expect(
|
|
getComposerPlaceholderState({
|
|
catchingUp: false,
|
|
isPreparingPrompt: true,
|
|
isStreaming: true,
|
|
}),
|
|
).toBe('processing');
|
|
});
|
|
|
|
it('still disables editing for pending approvals', () => {
|
|
expect(
|
|
shouldDisableComposerInput({
|
|
catchingUp: false,
|
|
pendingApproval: true,
|
|
isPreparingPrompt: false,
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it('blocks submit only after the connection reaches a failed state', () => {
|
|
expect(
|
|
shouldBlockComposerSubmit({
|
|
connectionStatus: 'disconnected',
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
shouldBlockComposerSubmit({
|
|
connectionStatus: 'error',
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
shouldBlockComposerSubmit({
|
|
connectionStatus: 'connecting',
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
shouldBlockComposerSubmit({
|
|
connectionStatus: 'connected',
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
});
|