Files
pipelines/app/test/features/chat/domain/chat_commands_test.dart
T

94 lines
3.1 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/domain/chat_commands.dart';
void main() {
test('records the web command list verbatim and in order', () {
expect(chatCommands.map((command) => command.name), [
'new',
'close',
'rename',
'stop',
'help',
]);
expect(chatCommands.map((command) => command.usage), [
'/new',
'/close',
'/rename <title>',
'/stop',
'/help',
]);
expect(chatCommands.map((command) => command.summary), [
'Start a fresh session in this directory',
'Finish this session for every client, keeping its history',
'Rename this session',
'Stop the turn that is running',
'List every command',
]);
expect(
chatCommands.where((command) => command.takesArgument).map((c) => c.name),
['rename'],
);
});
test('a bare slash offers every recorded command', () {
expect(chatCommandSuggestions('/'), chatCommands);
expect(chatCommandSuggestions(' /'), chatCommands);
});
test('the name prefix filters case-insensitively', () {
expect(chatCommandSuggestions('/n').map((command) => command.name), [
'new',
]);
expect(chatCommandSuggestions('/re').map((command) => command.name), [
'rename',
]);
expect(chatCommandSuggestions('/CL').map((command) => command.name), [
'close',
]);
expect(chatCommandSuggestions('/s').map((command) => command.name), [
'stop',
]);
});
test('an argument, plain text or an unknown word offers nothing', () {
expect(chatCommandSuggestions('/close '), isEmpty);
expect(chatCommandSuggestions('/rename My chat'), isEmpty);
expect(chatCommandSuggestions('/zzz'), isEmpty);
expect(chatCommandSuggestions('hello'), isEmpty);
expect(chatCommandSuggestions(''), isEmpty);
});
test('the query is only the single slash word', () {
expect(chatCommandQuery('/Help'), 'help');
expect(chatCommandQuery(' /He'), 'he');
expect(chatCommandQuery('/help '), isNull);
expect(chatCommandQuery('help'), isNull);
});
test('the slash word carries any argument and is null without a slash', () {
expect(chatCommandWord('/close'), '/close');
expect(chatCommandWord(' /close now'), '/close');
expect(chatCommandWord('/rename My chat'), '/rename');
expect(chatCommandWord('plain'), isNull);
expect(chatCommandWord('/'), '/');
expect(chatCommandNamed('/CLOSE'), chatCommands[1]);
expect(chatCommandNamed('/close'), chatCommands[1]);
expect(chatCommandNamed('/rename My chat'), chatCommands[2]);
expect(chatCommandNamed('/zzz'), isNull);
expect(chatCommandNamed('/close now'), chatCommands[1]);
expect(chatCommandNamed('plain'), isNull);
});
test('the parsed reports keep the web client words', () {
expect(
chatUnknownCommandReport('/nope'),
'“/nope” is not a command, so nothing was sent to the agent. '
'Send it as a message, or cancel.',
);
expect(
chatCommandUnavailableReport('/close'),
'“/close” is not available yet, so nothing was sent to the agent.',
);
});
}