snapshot of https://github.com/flutter/samples.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Main Branch CI / Test Flutter beta on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter stable on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter beta on macos-latest (push) Has been cancelled
Main Branch CI / Test Flutter stable on macos-latest (push) Has been cancelled
Some checks failed
Main Branch CI / Test Flutter beta on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter stable on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter beta on macos-latest (push) Has been cancelled
Main Branch CI / Test Flutter stable on macos-latest (push) Has been cancelled
This commit is contained in:
162
material_3_demo/test/color_screen_test.dart
Normal file
162
material_3_demo/test/color_screen_test.dart
Normal file
@@ -0,0 +1,162 @@
|
||||
// Copyright 2021 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_3_demo/main.dart';
|
||||
import 'package:material_3_demo/src/color_box.dart';
|
||||
import 'package:material_3_demo/src/color_palettes_screen.dart';
|
||||
import 'package:material_3_demo/src/scheme.dart';
|
||||
|
||||
import 'component_screen_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'Color palettes screen shows correctly when color icon is clicked '
|
||||
'on NavigationBar',
|
||||
(tester) async {
|
||||
widgetSetup(tester, 449);
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
await tester.pumpWidget(const App());
|
||||
|
||||
expect(find.text('Light ColorScheme'), findsNothing);
|
||||
expect(find.text('Dark ColorScheme'), findsNothing);
|
||||
expect(find.byType(NavigationBar), findsOneWidget);
|
||||
Finder colorIconOnBar = find.descendant(
|
||||
of: find.byType(NavigationBar),
|
||||
matching: find.widgetWithIcon(
|
||||
NavigationDestination,
|
||||
Icons.format_paint_outlined,
|
||||
),
|
||||
);
|
||||
expect(colorIconOnBar, findsOneWidget);
|
||||
await tester.tap(colorIconOnBar);
|
||||
await tester.pumpAndSettle(const Duration(microseconds: 500));
|
||||
expect(colorIconOnBar, findsNothing);
|
||||
|
||||
Finder selectedColorIconOnBar = find.descendant(
|
||||
of: find.byType(NavigationBar),
|
||||
matching: find.widgetWithIcon(
|
||||
NavigationDestination,
|
||||
Icons.format_paint,
|
||||
),
|
||||
);
|
||||
expect(selectedColorIconOnBar, findsOneWidget);
|
||||
expect(find.text('Light ColorScheme'), findsOneWidget);
|
||||
expect(find.text('Dark ColorScheme'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'Color palettes screen shows correctly when color icon is clicked '
|
||||
'on NavigationRail',
|
||||
(tester) async {
|
||||
widgetSetup(
|
||||
tester,
|
||||
1200,
|
||||
); // NavigationRail shows only when width is > 1000.
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
await tester.pumpWidget(const App());
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Light ColorScheme'), findsNothing);
|
||||
expect(find.text('Dark ColorScheme'), findsNothing);
|
||||
Finder colorIconOnRail = find.descendant(
|
||||
of: find.byType(NavigationRail),
|
||||
matching: find.byIcon(Icons.format_paint_outlined),
|
||||
);
|
||||
expect(colorIconOnRail, findsOneWidget);
|
||||
await tester.tap(colorIconOnRail);
|
||||
await tester.pumpAndSettle(const Duration(microseconds: 500));
|
||||
expect(colorIconOnRail, findsNothing);
|
||||
Finder selectedColorIconOnRail = find.descendant(
|
||||
of: find.byType(NavigationRail),
|
||||
matching: find.byIcon(Icons.format_paint),
|
||||
);
|
||||
expect(selectedColorIconOnRail, findsOneWidget);
|
||||
expect(find.text('Light ColorScheme'), findsOneWidget);
|
||||
expect(find.text('Dark ColorScheme'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('Color screen shows correct content', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(body: Row(children: [ColorPalettesScreen()])),
|
||||
),
|
||||
);
|
||||
expect(find.text('Light ColorScheme'), findsOneWidget);
|
||||
expect(find.text('Dark ColorScheme'), findsOneWidget);
|
||||
expect(
|
||||
find.byType(SchemePreview, skipOffstage: false),
|
||||
findsNWidgets(2),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'ColorBox displays correct info and copies hex color on button tap',
|
||||
(tester) async {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMessageHandler('flutter/platform', (_) async {
|
||||
// To intercept method calls to 'Clipboard.setData'
|
||||
return const JSONMethodCodec().encodeSuccessEnvelope(null);
|
||||
});
|
||||
const hexColor = 0xFF3d3d8d;
|
||||
const testColor = Color(hexColor);
|
||||
const onTestColor = Colors.white;
|
||||
const testLabel = 'Test Label';
|
||||
const testTone = '50';
|
||||
|
||||
final gesture = await tester.createGesture(
|
||||
kind: PointerDeviceKind.mouse,
|
||||
);
|
||||
|
||||
// Wrap in MaterialApp + Scaffold so we can show SnackBars
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ColorBox(
|
||||
label: testLabel,
|
||||
tone: testTone,
|
||||
color: testColor,
|
||||
onColor: onTestColor,
|
||||
height: 100,
|
||||
width: 100,
|
||||
displayPaletteInfo: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text(testLabel), findsOneWidget);
|
||||
expect(find.text(testTone), findsOneWidget);
|
||||
|
||||
// The copy icon should NOT be there initially (only appears on hover).
|
||||
expect(find.byIcon(Icons.copy), findsNothing);
|
||||
|
||||
await gesture.addPointer(location: Offset.zero);
|
||||
addTearDown(gesture.removePointer);
|
||||
await tester.pump();
|
||||
await gesture.moveTo(tester.getCenter(find.byType(ColorBox)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byIcon(Icons.copy), findsOneWidget);
|
||||
|
||||
// Tap the copy icon, which copies the hex to clipboard and shows a SnackBar.
|
||||
await tester.tap(find.byIcon(Icons.copy));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SnackBar), findsOneWidget);
|
||||
|
||||
expect(
|
||||
find.text(
|
||||
'Copied #${hexColor.toRadixString(16).substring(2)} to clipboard',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
275
material_3_demo/test/component_screen_test.dart
Normal file
275
material_3_demo/test/component_screen_test.dart
Normal file
@@ -0,0 +1,275 @@
|
||||
// Copyright 2021 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// ignore_for_file: avoid_types_on_closure_parameters
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_3_demo/main.dart';
|
||||
import 'package:material_3_demo/src/component_screen.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Default main page shows all M3 components', (tester) async {
|
||||
widgetSetup(tester, 800, windowHeight: 7500);
|
||||
await tester.pumpWidget(const App());
|
||||
|
||||
// Elements on the app bar
|
||||
expect(find.text('Material 3'), findsOneWidget);
|
||||
expect(
|
||||
find.widgetWithIcon(AppBar, Icons.dark_mode_outlined),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.widgetWithIcon(AppBar, Icons.filter_2), findsOneWidget);
|
||||
expect(
|
||||
find.widgetWithIcon(AppBar, Icons.palette_outlined),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// Elements on the component screen
|
||||
// Common buttons
|
||||
expect(
|
||||
find.widgetWithText(ElevatedButton, 'Elevated'),
|
||||
findsNWidgets(2),
|
||||
);
|
||||
expect(find.widgetWithText(FilledButton, 'Filled'), findsNWidgets(2));
|
||||
expect(
|
||||
find.widgetWithText(FilledButton, 'Filled tonal'),
|
||||
findsNWidgets(2),
|
||||
);
|
||||
expect(
|
||||
find.widgetWithText(OutlinedButton, 'Outlined'),
|
||||
findsNWidgets(2),
|
||||
);
|
||||
expect(find.widgetWithText(TextButton, 'Text'), findsNWidgets(2));
|
||||
expect(find.widgetWithText(Buttons, 'Icon'), findsNWidgets(5));
|
||||
|
||||
// FABs
|
||||
expect(
|
||||
find.byType(FloatingActionButton),
|
||||
findsNWidgets(6),
|
||||
); // 2 more show up in the bottom app bar. 1 more in the navigation rail
|
||||
expect(
|
||||
find.widgetWithText(FloatingActionButton, 'Create'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// Icon buttons
|
||||
expect(
|
||||
find.widgetWithIcon(IconButton, Icons.settings_outlined),
|
||||
findsNWidgets(8),
|
||||
);
|
||||
|
||||
// Segmented buttons
|
||||
expect(find.byType(SegmentedButton<Calendar>), findsOneWidget);
|
||||
expect(find.byType(SegmentedButton<Sizes>), findsOneWidget);
|
||||
|
||||
// Badges
|
||||
expect(find.byType(Badge), findsNWidgets(4));
|
||||
|
||||
// Progress indicators
|
||||
Finder circularProgressIndicator = find.byType(
|
||||
CircularProgressIndicator,
|
||||
);
|
||||
expect(circularProgressIndicator, findsOneWidget);
|
||||
Finder linearProgressIndicator = find.byType(LinearProgressIndicator);
|
||||
expect(linearProgressIndicator, findsOneWidget);
|
||||
|
||||
// Snackbar
|
||||
expect(
|
||||
find.widgetWithText(TextButton, 'Show snackbar'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// Bottom sheet
|
||||
expect(
|
||||
find.widgetWithText(TextButton, 'Show modal bottom sheet'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.widgetWithText(TextButton, 'Show bottom sheet'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// Cards
|
||||
expect(find.widgetWithText(Cards, 'Elevated'), findsOneWidget);
|
||||
expect(find.widgetWithText(Cards, 'Filled'), findsOneWidget);
|
||||
expect(find.widgetWithText(Cards, 'Outlined'), findsOneWidget);
|
||||
|
||||
// Carousels
|
||||
expect(find.byType(CarouselView), findsNWidgets(2));
|
||||
|
||||
// Dialogs
|
||||
expect(find.widgetWithText(TextButton, 'Show dialog'), findsOneWidget);
|
||||
expect(
|
||||
find.widgetWithText(TextButton, 'Show full-screen dialog'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// Dividers
|
||||
expect(find.byKey(const Key('divider')), findsOneWidget);
|
||||
|
||||
// Bottom app bar
|
||||
expect(find.byType(BottomAppBar), findsOneWidget);
|
||||
|
||||
// Navigation bar
|
||||
// Third one is off screen in the scaffold
|
||||
expect(find.byType(NavigationBar), findsNWidgets(3));
|
||||
|
||||
// Navigation drawer
|
||||
expect(find.byType(Drawer), findsOneWidget);
|
||||
expect(
|
||||
find.widgetWithText(TextButton, 'Show modal navigation drawer'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// Navigation rail
|
||||
// Second one is off screen in the scaffold
|
||||
expect(find.byType(NavigationRail), findsNWidgets(2));
|
||||
|
||||
// Tabs
|
||||
expect(find.byType(TabBar), findsOneWidget);
|
||||
|
||||
// Search
|
||||
expect(find.byType(SearchBar), findsOneWidget);
|
||||
|
||||
// Top app bars
|
||||
expect(find.byType(AppBar), findsNWidgets(6));
|
||||
|
||||
// Checkboxes
|
||||
Finder checkboxExample = find.byType(CheckboxListTile);
|
||||
expect(checkboxExample, findsNWidgets(4));
|
||||
|
||||
// Chips
|
||||
expect(
|
||||
find.byType(ActionChip),
|
||||
findsNWidgets(4),
|
||||
); // includes Assist and Suggestion chip.
|
||||
expect(find.byType(FilterChip), findsNWidgets(2));
|
||||
expect(find.byType(InputChip), findsNWidgets(2));
|
||||
|
||||
// Date and time pickers
|
||||
expect(
|
||||
find.widgetWithText(DatePicker, 'Show date picker'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.widgetWithText(TimePicker, 'Show time picker'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// Menus
|
||||
expect(find.byType(MenuAnchor), findsNWidgets(5));
|
||||
expect(find.byType(DropdownMenu<ColorLabel>), findsOneWidget);
|
||||
expect(find.byType(DropdownMenu<IconLabel>), findsOneWidget);
|
||||
|
||||
// Radios
|
||||
Finder radioExample = find.byType(RadioListTile<Options>);
|
||||
expect(radioExample, findsNWidgets(3));
|
||||
|
||||
// Sliders
|
||||
expect(find.byType(Slider), findsNWidgets(2));
|
||||
|
||||
// Switches
|
||||
expect(find.byType(Switch), findsNWidgets(4));
|
||||
|
||||
// TextFields
|
||||
expect(find.widgetWithText(TextField, 'Disabled'), findsNWidgets(2));
|
||||
expect(find.widgetWithText(TextField, 'Filled'), findsNWidgets(2));
|
||||
expect(find.widgetWithText(TextField, 'Outlined'), findsNWidgets(2));
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'NavigationRail doesn\'t show when width value is small than 1000 '
|
||||
'(in Portrait mode or narrow screen)',
|
||||
(tester) async {
|
||||
widgetSetup(tester, 999, windowHeight: 7000);
|
||||
await tester.pumpWidget(const App());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// When screen width is less than 1000, NavigationBar will show. At the same
|
||||
// time, the NavigationBar example still show up in the navigation group.
|
||||
expect(
|
||||
find.byType(NavigationBars),
|
||||
findsNWidgets(3),
|
||||
); // The real navBar, badges example and navBar example
|
||||
expect(
|
||||
find.widgetWithText(NavigationBar, 'Components'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.widgetWithText(NavigationBar, 'Color'), findsOneWidget);
|
||||
expect(
|
||||
find.widgetWithText(NavigationBar, 'Typography'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.widgetWithText(NavigationBar, 'Elevation'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
expect(
|
||||
find.widgetWithText(NavigationBar, 'Explore'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.widgetWithText(NavigationBar, 'Pets'), findsOneWidget);
|
||||
expect(
|
||||
find.widgetWithText(NavigationBar, 'Account'),
|
||||
findsOneWidget,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'NavigationRail shows when width value is greater than or equal '
|
||||
'to 1000 (in Landscape mode or wider screen)',
|
||||
(tester) async {
|
||||
widgetSetup(tester, 1001, windowHeight: 3000);
|
||||
await tester.pumpWidget(const App());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// When screen width is greater than or equal to 1000, NavigationRail will show.
|
||||
// At the same time, the NavigationBar will NOT show.
|
||||
expect(find.byType(NavigationRail), findsNWidgets(2));
|
||||
expect(find.byType(Tooltip, skipOffstage: false), findsWidgets);
|
||||
expect(
|
||||
find.widgetWithText(NavigationRail, 'Components'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.widgetWithText(NavigationRail, 'Color'), findsOneWidget);
|
||||
expect(
|
||||
find.widgetWithText(NavigationRail, 'Typography'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.widgetWithText(NavigationRail, 'Elevation'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
expect(
|
||||
find.widgetWithText(NavigationBar, 'Explore'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.widgetWithText(NavigationBar, 'Pets'), findsOneWidget);
|
||||
expect(
|
||||
find.widgetWithText(NavigationBar, 'Account'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// the Navigation bar should be out of screen.
|
||||
final RenderBox box = tester.renderObject(
|
||||
find.widgetWithText(NavigationBar, 'Components'),
|
||||
);
|
||||
expect(box.localToGlobal(Offset.zero), const Offset(0.0, 3080.0));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void widgetSetup(
|
||||
WidgetTester tester,
|
||||
double windowWidth, {
|
||||
double? windowHeight,
|
||||
}) {
|
||||
final height = windowHeight ?? 846;
|
||||
tester.view.devicePixelRatio = 2;
|
||||
final dpi = tester.view.devicePixelRatio;
|
||||
tester.view.physicalSize = Size(windowWidth * dpi, height * dpi);
|
||||
}
|
||||
92
material_3_demo/test/elevation_screen_test.dart
Normal file
92
material_3_demo/test/elevation_screen_test.dart
Normal file
@@ -0,0 +1,92 @@
|
||||
// Copyright 2021 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// ignore_for_file: avoid_types_on_closure_parameters
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_3_demo/main.dart';
|
||||
import 'package:material_3_demo/src/elevation_screen.dart';
|
||||
|
||||
import 'component_screen_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'Surface Tones screen shows correctly when the corresponding icon is '
|
||||
'selected on NavigationBar',
|
||||
(tester) async {
|
||||
widgetSetup(tester, 449);
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
await tester.pumpWidget(const App());
|
||||
|
||||
expect(find.text('Surface Tint Color Only'), findsNothing);
|
||||
expect(find.byType(NavigationBar), findsOneWidget);
|
||||
Finder tintIconOnBar = find.descendant(
|
||||
of: find.byType(NavigationBar),
|
||||
matching: find.widgetWithIcon(
|
||||
NavigationDestination,
|
||||
Icons.invert_colors_on_outlined,
|
||||
),
|
||||
);
|
||||
expect(tintIconOnBar, findsOneWidget);
|
||||
await tester.tap(tintIconOnBar);
|
||||
await tester.pumpAndSettle(const Duration(microseconds: 500));
|
||||
expect(tintIconOnBar, findsNothing);
|
||||
Finder selectedTintIconOnBar = find.descendant(
|
||||
of: find.byType(NavigationBar),
|
||||
matching: find.widgetWithIcon(
|
||||
NavigationDestination,
|
||||
Icons.opacity,
|
||||
),
|
||||
);
|
||||
expect(selectedTintIconOnBar, findsOneWidget);
|
||||
expect(find.text('Surface Tint Color Only'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'Surface Tones screen shows correctly when the corresponding icon is '
|
||||
'selected on NavigationRail',
|
||||
(tester) async {
|
||||
widgetSetup(
|
||||
tester,
|
||||
1200,
|
||||
); // NavigationRail shows only when width is > 1000.
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
await tester.pumpWidget(const App());
|
||||
expect(find.text('Surface Tint Color Only'), findsNothing);
|
||||
Finder tintIconOnRail = find.descendant(
|
||||
of: find.byType(NavigationRail),
|
||||
matching: find.byIcon(Icons.invert_colors_on_outlined),
|
||||
);
|
||||
expect(tintIconOnRail, findsOneWidget);
|
||||
await tester.tap(tintIconOnRail);
|
||||
await tester.pumpAndSettle(const Duration(microseconds: 500));
|
||||
expect(tintIconOnRail, findsNothing);
|
||||
Finder selectedTintIconOnRail = find.descendant(
|
||||
of: find.byType(NavigationRail),
|
||||
matching: find.byIcon(Icons.opacity),
|
||||
);
|
||||
expect(selectedTintIconOnRail, findsOneWidget);
|
||||
expect(find.text('Surface Tint Color Only'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('Surface Tones screen shows correct content', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(body: Row(children: [ElevationScreen()])),
|
||||
),
|
||||
);
|
||||
expect(find.text('Surface Tint Color Only'), findsOneWidget);
|
||||
expect(
|
||||
find.text('Surface Tint Color and Shadow Color'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Shadow Color Only'), findsOneWidget);
|
||||
expect(find.byType(ElevationGrid), findsNWidgets(3));
|
||||
expect(find.byType(ElevationCard), findsNWidgets(18));
|
||||
});
|
||||
}
|
||||
94
material_3_demo/test/typography_screen_test.dart
Normal file
94
material_3_demo/test/typography_screen_test.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright 2021 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// ignore_for_file: avoid_types_on_closure_parameters
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_3_demo/main.dart';
|
||||
import 'package:material_3_demo/src/typography_screen.dart';
|
||||
|
||||
import 'component_screen_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'Typography screen shows correctly when the corresponding icon is '
|
||||
'selected on NavigationBar',
|
||||
(tester) async {
|
||||
widgetSetup(tester, 449);
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
await tester.pumpWidget(const App());
|
||||
|
||||
expect(find.text('Display Large'), findsNothing);
|
||||
expect(find.byType(NavigationBar), findsOneWidget);
|
||||
Finder textIconOnBar = find.descendant(
|
||||
of: find.byType(NavigationBar),
|
||||
matching: find.byIcon(Icons.text_snippet_outlined),
|
||||
);
|
||||
expect(textIconOnBar, findsOneWidget);
|
||||
await tester.tap(textIconOnBar);
|
||||
await tester.pumpAndSettle(const Duration(microseconds: 500));
|
||||
expect(textIconOnBar, findsNothing);
|
||||
Finder selectedTextIconOnBar = find.descendant(
|
||||
of: find.byType(NavigationBar),
|
||||
matching: find.byIcon(Icons.text_snippet),
|
||||
);
|
||||
expect(selectedTextIconOnBar, findsOneWidget);
|
||||
expect(find.text('Display Large'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'Typography screen shows correctly when the corresponding icon is '
|
||||
'selected on NavigationRail',
|
||||
(tester) async {
|
||||
widgetSetup(
|
||||
tester,
|
||||
1200,
|
||||
); // NavigationRail shows only when width is > 1000.
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
await tester.pumpWidget(const App());
|
||||
expect(find.text('Display Large'), findsNothing);
|
||||
Finder textIconOnRail = find.descendant(
|
||||
of: find.byType(NavigationRail),
|
||||
matching: find.byIcon(Icons.text_snippet_outlined),
|
||||
);
|
||||
expect(textIconOnRail, findsOneWidget);
|
||||
await tester.tap(textIconOnRail);
|
||||
await tester.pumpAndSettle(const Duration(microseconds: 500));
|
||||
expect(textIconOnRail, findsNothing);
|
||||
Finder selectedTextIconOnRail = find.descendant(
|
||||
of: find.byType(NavigationRail),
|
||||
matching: find.byIcon(Icons.text_snippet),
|
||||
);
|
||||
expect(selectedTextIconOnRail, findsOneWidget);
|
||||
expect(find.text('Display Large'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('Typography screen shows correct content', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(body: Row(children: [TypographyScreen()])),
|
||||
),
|
||||
);
|
||||
expect(find.text('Display Large'), findsOneWidget);
|
||||
expect(find.text('Display Medium'), findsOneWidget);
|
||||
expect(find.text('Display Small'), findsOneWidget);
|
||||
expect(find.text('Headline Large'), findsOneWidget);
|
||||
expect(find.text('Headline Medium'), findsOneWidget);
|
||||
expect(find.text('Headline Small'), findsOneWidget);
|
||||
expect(find.text('Title Large'), findsOneWidget);
|
||||
expect(find.text('Title Medium'), findsOneWidget);
|
||||
expect(find.text('Title Small'), findsOneWidget);
|
||||
await tester.scrollUntilVisible(find.text('Body Small'), 500.0);
|
||||
expect(find.text('Label Large'), findsOneWidget);
|
||||
expect(find.text('Label Medium'), findsOneWidget);
|
||||
expect(find.text('Label Small'), findsOneWidget);
|
||||
expect(find.text('Body Large'), findsOneWidget);
|
||||
expect(find.text('Body Medium'), findsOneWidget);
|
||||
expect(find.text('Body Small'), findsOneWidget);
|
||||
|
||||
expect(find.byType(TextStyleExample), findsNWidgets(15));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user