Skip to content

Commit

Permalink
Test of CustomScrollViewExampleApp (flutter#152431)
Browse files Browse the repository at this point in the history
CustomScrollViewExampleApp 
Part of flutter#130459

The test is checking: 
- if all crucial Widgets are initially visible
- if IconButton click will expand existing SliverList
- if IconButton click and mouse scroll will reveal additional SliverList
  • Loading branch information
miechoo authored Aug 23, 2024
1 parent aa934ac commit b6c14d7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
1 change: 0 additions & 1 deletion dev/bots/check_code_samples.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,5 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/widgets/restoration/restoration_mixin.0_test.dart',
'examples/api/test/widgets/actions/focusable_action_detector.0_test.dart',
'examples/api/test/widgets/focus_scope/focus_scope.0_test.dart',
'examples/api/test/widgets/scroll_view/custom_scroll_view.1_test.dart',
'examples/api/test/gestures/pointer_signal_resolver/pointer_signal_resolver.0_test.dart',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/scroll_view/custom_scroll_view.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';

void main() {
testWidgets('What should be visible in the initial state.', (WidgetTester tester) async {
await tester.pumpWidget(const example.CustomScrollViewExampleApp());

expect(find.descendant(
of: find.byType(IconButton),
matching: find.byIcon(Icons.add),
), findsOne);
expect(find.byType(SliverList), findsOne);

// Initial state should present only "Item: 0" on the SliverList.
expect(find.widgetWithText(SliverList, 'Item: 0'), findsOne);
expect(find.widgetWithText(SliverList, 'Item: -1'), findsNothing);
expect(find.widgetWithText(SliverList, 'Item: 1'), findsNothing);
});

testWidgets('Items are added correctly', (WidgetTester tester) async {
await tester.pumpWidget(const example.CustomScrollViewExampleApp());

await tester.tap(find.byType(IconButton));
await tester.pump();

// 'Item: -1' is invisible before scrolling.
expect(find.widgetWithText(SliverList, 'Item: -1'), findsNothing);
expect(find.widgetWithText(SliverList, 'Item: 1'), findsOne);

// Scroll the updated screen.
await tester.drag(find.byType(CustomScrollView), const Offset(0.0, 50.0));
await tester.pump();

// An additional SliverList appears.
expect(find.byType(SliverList), findsExactly(2));

// All items are visible.
expect(find.widgetWithText(SliverList, 'Item: -1'), findsOne);
expect(find.widgetWithText(SliverList, 'Item: 0'), findsOne);
expect(find.widgetWithText(SliverList, 'Item: 1'), findsOne);
});
}

0 comments on commit b6c14d7

Please sign in to comment.