forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_message_test.dart
More file actions
55 lines (43 loc) · 1.91 KB
/
Copy patherror_message_test.dart
File metadata and controls
55 lines (43 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:omi/utils/error_message.dart';
void main() {
test('lifts the detail out of an API error body', () {
final error = Exception(
'Failed to rebuild knowledge graph: {"detail":"Canonical knowledge graph state is derived from '
'canonical memories and cannot be deleted or rebuilt directly."}',
);
expect(
readableError(error),
'Canonical knowledge graph state is derived from canonical memories and cannot be deleted or rebuilt directly.',
);
});
test('reads a PlatformException message instead of its dump', () {
final error = PlatformException(
code: 'Unexpected security result code',
message: 'The specified item already exists in the keychain.',
details: -25299,
);
expect(readableError(error), 'The specified item already exists in the keychain.');
});
test('falls back to the platform code when the message is empty', () {
final error = PlatformException(code: 'channel-error', message: ' ');
expect(readableError(error), 'channel-error');
});
test('strips the exception prefix from a plain message', () {
expect(readableError(Exception('Device is not connected')), 'Device is not connected');
expect(readableError(const FormatException('Unexpected end of input')), 'Unexpected end of input');
});
test('keeps a body it cannot parse rather than inventing one', () {
expect(readableError('offline'), 'offline');
expect(readableError(Exception('Failed to save: {not json}')), 'Failed to save: {not json}');
});
test('truncates a long body to one snackbar line', () {
final result = readableError(Exception('x' * 400));
expect(result.length, 160);
expect(result.endsWith('…'), isTrue);
});
test('renders a null error as empty rather than the word null', () {
expect(readableError(null), isEmpty);
});
}