Skip to content

Commit 134ba8b

Browse files
committed
[refactor] harden Files toolbar coverage
Signed-off-by: Viwat Vchirawongkwin <viwat.v@chula.ac.th>
1 parent 790384d commit 134ba8b

1 file changed

Lines changed: 100 additions & 52 deletions

File tree

‎app/test/widget/files_view_test.dart‎

Lines changed: 100 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -206,57 +206,60 @@ void main() {
206206
'compact toolbar keeps Select and GitHub direct on one action row',
207207
(WidgetTester tester) async {
208208
final semantics = tester.ensureSemantics();
209-
final RecordingConnection rec = RecordingConnection(
210-
initial: ConnState.ready,
211-
);
212-
addTearDown(rec.dispose);
213-
await rec.putFile('/alpha.py', b('print("alpha")\n'));
214-
await pumpSurface(
215-
tester,
216-
const FilesView(),
217-
connection: rec,
218-
size: const Size(252, 568),
219-
);
220-
await tester.pumpAndSettle();
221-
final AppLocalizations l10n = l10nOf(tester);
209+
try {
210+
final RecordingConnection rec = RecordingConnection(
211+
initial: ConnState.ready,
212+
);
213+
addTearDown(rec.dispose);
214+
await rec.putFile('/alpha.py', b('print("alpha")\n'));
215+
await pumpSurface(
216+
tester,
217+
const FilesView(),
218+
connection: rec,
219+
size: const Size(252, 568),
220+
);
221+
await tester.pumpAndSettle();
222+
final AppLocalizations l10n = l10nOf(tester);
222223

223-
final Finder select = find.byTooltip(l10n.filesActionSelect);
224-
final Finder github = find.byTooltip(l10n.githubImportAction);
225-
final Finder overflow = find.byKey(kFilesActionsOverflowButtonKey);
226-
expect(find.byKey(kFilesNormalActionsRowKey), findsOneWidget);
227-
expect(select, findsOneWidget);
228-
expect(github, findsOneWidget);
229-
expect(overflow, findsOneWidget);
230-
expect(find.byTooltip(l10n.filesActionRefresh), findsNothing);
231-
expect(find.byTooltip(l10n.filesEmptyCta), findsNothing);
232-
expect(find.byTooltip(l10n.filesActionNewFolder), findsNothing);
233-
expect(find.byTooltip(l10n.filesActionUpload), findsNothing);
234-
expectOneHorizontalLine(tester, <Finder>[select, github, overflow]);
235-
expect(
236-
tester.getSize(find.byKey(kFilesNormalActionsRowKey)).height,
237-
48,
238-
);
239-
expectTouchTarget(tester, select, 'compact Select');
240-
expectTouchTarget(tester, github, 'compact GitHub import');
241-
expectTouchTarget(tester, overflow, 'compact overflow');
242-
final Finder overflowButton = find.descendant(
243-
of: overflow,
244-
matching: find.byType(IconButton),
245-
);
246-
expect(overflowButton, findsOneWidget);
247-
expect(
248-
tester.getSemantics(overflowButton),
249-
isSemantics(
250-
tooltip: l10n.filesMoreActions,
251-
isButton: true,
252-
hasEnabledState: true,
253-
isEnabled: true,
254-
isFocusable: true,
255-
hasTapAction: true,
256-
),
257-
);
258-
expect(tester.takeException(), isNull);
259-
semantics.dispose();
224+
final Finder select = find.byTooltip(l10n.filesActionSelect);
225+
final Finder github = find.byTooltip(l10n.githubImportAction);
226+
final Finder overflow = find.byKey(kFilesActionsOverflowButtonKey);
227+
expect(find.byKey(kFilesNormalActionsRowKey), findsOneWidget);
228+
expect(select, findsOneWidget);
229+
expect(github, findsOneWidget);
230+
expect(overflow, findsOneWidget);
231+
expect(find.byTooltip(l10n.filesActionRefresh), findsNothing);
232+
expect(find.byTooltip(l10n.filesEmptyCta), findsNothing);
233+
expect(find.byTooltip(l10n.filesActionNewFolder), findsNothing);
234+
expect(find.byTooltip(l10n.filesActionUpload), findsNothing);
235+
expectOneHorizontalLine(tester, <Finder>[select, github, overflow]);
236+
expect(
237+
tester.getSize(find.byKey(kFilesNormalActionsRowKey)).height,
238+
48,
239+
);
240+
expectTouchTarget(tester, select, 'compact Select');
241+
expectTouchTarget(tester, github, 'compact GitHub import');
242+
expectTouchTarget(tester, overflow, 'compact overflow');
243+
final Finder overflowButton = find.descendant(
244+
of: overflow,
245+
matching: find.byType(IconButton),
246+
);
247+
expect(overflowButton, findsOneWidget);
248+
expect(
249+
tester.getSemantics(overflowButton),
250+
isSemantics(
251+
tooltip: l10n.filesMoreActions,
252+
isButton: true,
253+
hasEnabledState: true,
254+
isEnabled: true,
255+
isFocusable: true,
256+
hasTapAction: true,
257+
),
258+
);
259+
expect(tester.takeException(), isNull);
260+
} finally {
261+
semantics.dispose();
262+
}
260263
},
261264
);
262265

@@ -319,7 +322,12 @@ void main() {
319322

320323
rec.holdNextList();
321324
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
322-
await rec.listStarted.future;
325+
await tester.pump();
326+
expect(
327+
rec.listStarted.isCompleted,
328+
isTrue,
329+
reason: 'keyboard activation routes Refresh immediately',
330+
);
323331
rec.releaseList.complete();
324332
await tester.pumpAndSettle();
325333
expect(find.byKey(kFilesOverflowRefreshKey), findsNothing);
@@ -366,7 +374,8 @@ void main() {
366374

367375
rec.holdNextList();
368376
await tester.tap(find.byKey(kFilesOverflowRefreshKey));
369-
await rec.listStarted.future;
377+
await tester.pump();
378+
expect(rec.listStarted.isCompleted, isTrue);
370379
expect(find.byKey(kFilesActionsOverflowButtonKey), findsOneWidget);
371380
rec.releaseList.complete();
372381
await tester.pumpAndSettle();
@@ -439,6 +448,40 @@ void main() {
439448
expect(tester.takeException(), isNull);
440449
});
441450

451+
for (final (double width, bool compact) in <(double, bool)>[
452+
(295, true),
453+
(296, false),
454+
]) {
455+
testWidgets(
456+
'${width.toInt()} dp host ${compact ? 'uses overflow' : 'fits six direct actions'} at the exact cutoff',
457+
(WidgetTester tester) async {
458+
final RecordingConnection rec = RecordingConnection(
459+
initial: ConnState.ready,
460+
);
461+
addTearDown(rec.dispose);
462+
await rec.putFile('/alpha.py', b('a\n'));
463+
await pumpSurface(
464+
tester,
465+
const FilesView(),
466+
connection: rec,
467+
size: Size(width, 568),
468+
);
469+
await tester.pumpAndSettle();
470+
final AppLocalizations l10n = l10nOf(tester);
471+
472+
expect(
473+
find.byKey(kFilesActionsOverflowButtonKey),
474+
compact ? findsOneWidget : findsNothing,
475+
);
476+
expect(
477+
find.byTooltip(l10n.filesActionRefresh),
478+
compact ? findsNothing : findsOneWidget,
479+
);
480+
expect(tester.takeException(), isNull);
481+
},
482+
);
483+
}
484+
442485
testWidgets('compact overflow remains usable at 2x text', (
443486
WidgetTester tester,
444487
) async {
@@ -465,6 +508,11 @@ void main() {
465508
expect(find.text(l10n.filesEmptyCta), findsOneWidget);
466509
expect(find.text(l10n.filesActionNewFolder), findsOneWidget);
467510
expect(find.text(l10n.filesActionUpload), findsOneWidget);
511+
final Finder upload = find.byKey(kFilesOverflowUploadKey);
512+
await tester.ensureVisible(upload);
513+
await tester.pumpAndSettle();
514+
expect(upload.hitTestable(), findsOneWidget);
515+
expectTouchTarget(tester, upload, '2x Upload menu item');
468516
expect(tester.takeException(), isNull);
469517
});
470518

0 commit comments

Comments
 (0)