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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
import 'package:flutter_test/flutter_test.dart';
import 'package:quicklog/services/shared_text_handler.dart';
void main() {
group('prepareSharedTextLoad', () {
test('rejects whitespace-only input', () {
final d = prepareSharedTextLoad(' \n\t', false);
expect(d.proceed, isFalse);
});
test('returns prefill mode when autoLog is false', () {
final d = prepareSharedTextLoad('hello', false);
expect(d.proceed, isTrue);
expect(d.mode, SharedTextLoadMode.prefill);
expect(d.text, 'hello');
});
test('returns autoLog mode when autoLog is true', () {
final d = prepareSharedTextLoad('hello', true);
expect(d.proceed, isTrue);
expect(d.mode, SharedTextLoadMode.autoLog);
});
test('does not truncate long input', () {
final big = 'x' * 10000;
final d = prepareSharedTextLoad(big, true);
expect(d.text.length, 10000);
});
});
group('handleSharedTextLoad', () {
late _Probe p;
setUp(() => p = _Probe());
test('autoLog success: logs, shows info, resets, clears cache', () async {
await handleSharedTextLoad(
text: 'note',
autoLog: true,
dir: '/tmp',
prefill: p.prefill,
focus: p.focus,
resetInput: p.resetInput,
clearCache: p.clearCache,
logFn: (_, _) async => p.logged = true,
showInfo: p.showInfo,
showError: p.showError,
);
expect(p.logged, true);
expect(p.info, ['Logged']);
expect(p.didReset, true);
expect(p.cleared, true);
expect(p.errors, isEmpty);
});
test('autoLog failure: shows error, keeps cache, does not reset', () async {
await handleSharedTextLoad(
text: 'note',
autoLog: true,
dir: '/tmp',
prefill: p.prefill,
focus: p.focus,
resetInput: p.resetInput,
clearCache: p.clearCache,
logFn: (_, _) async => throw Exception('boom'),
showInfo: p.showInfo,
showError: p.showError,
);
expect(p.errors.length, 1);
expect(p.cleared, false);
expect(p.didReset, false);
});
test('empty text: clears cache and skips everything else', () async {
await handleSharedTextLoad(
text: ' ',
autoLog: true,
dir: '/tmp',
prefill: p.prefill,
focus: p.focus,
resetInput: p.resetInput,
clearCache: p.clearCache,
logFn: (_, _) async {
p.logged = true;
},
showInfo: p.showInfo,
showError: p.showError,
);
expect(p.logged, false);
expect(p.cleared, true);
expect(p.didReset, false);
expect(p.prefilled, isNull);
});
test('prefill mode: prefills + focuses + clears cache, no log', () async {
await handleSharedTextLoad(
text: 'note',
autoLog: false,
dir: '/tmp',
prefill: p.prefill,
focus: p.focus,
resetInput: p.resetInput,
clearCache: p.clearCache,
logFn: (_, _) async => p.logged = true,
showInfo: p.showInfo,
showError: p.showError,
);
expect(p.prefilled, 'note');
expect(p.focused, true);
expect(p.cleared, true);
expect(p.logged, false);
});
});
}
class _Probe {
String? prefilled;
bool focused = false;
bool didReset = false;
bool cleared = false;
bool logged = false;
final List<String> info = [];
final List<Object> errors = [];
void prefill(String s) {
prefilled = s;
}
void focus() {
focused = true;
}
void resetInput() {
didReset = true;
}
Future<void> clearCache() async {
cleared = true;
}
void showInfo(String title, String msg) {
info.add(title);
}
void showError(Object e) {
errors.add(e);
}
}
|