forked from flutter/packages
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write Tests for API Examples of
cupertino_text_field.0
, `data_table…
….0`, `icon_button.2` & `ink_well.0` (#139258) Write Tests for API Examples of `cupertino_text_field.0`, `data_table.0`, `icon_button.2` & `ink_well.0` Note: test for `cupertino_text_field.0` was already there but it was named `cupertino_text_field.0.dart`. I renamed it to `cupertino_text_field.0_test.dart`. Part of #130459
- Loading branch information
1 parent
8871097
commit c10787b
Showing
5 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
35 changes: 35 additions & 0 deletions
35
examples/api/test/material/data_table/data_table.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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/material/data_table/data_table.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('DataTable Smoke Test', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const example.DataTableExampleApp(), | ||
); | ||
expect(find.widgetWithText(AppBar, 'DataTable Sample'), findsOneWidget); | ||
expect(find.byType(DataTable), findsOneWidget); | ||
final DataTable dataTable = tester.widget<DataTable>(find.byType(DataTable)); | ||
expect(dataTable.columns.length, 3); | ||
expect(dataTable.rows.length, 3); | ||
for (int i = 0; i < dataTable.rows.length; i++) { | ||
expect(dataTable.rows[i].cells.length, 3); | ||
} | ||
expect(find.text('Name'), findsOneWidget); | ||
expect(find.text('Age'), findsOneWidget); | ||
expect(find.text('Role'), findsOneWidget); | ||
expect(find.text('Sarah'), findsOneWidget); | ||
expect(find.text('19'), findsOneWidget); | ||
expect(find.text('Student'), findsOneWidget); | ||
expect(find.text('Janine'), findsOneWidget); | ||
expect(find.text('43'), findsOneWidget); | ||
expect(find.text('Professor'), findsOneWidget); | ||
expect(find.text('William'), findsOneWidget); | ||
expect(find.text('27'), findsOneWidget); | ||
expect(find.text('Associate Professor'), findsOneWidget); | ||
}); | ||
} |
23 changes: 23 additions & 0 deletions
23
examples/api/test/material/icon_button/icon_button.2_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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/material/icon_button/icon_button.2.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('IconButton Types', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const example.IconButtonApp(), | ||
); | ||
expect(find.widgetWithIcon(IconButton, Icons.filter_drama), findsNWidgets(8)); | ||
final Finder iconButtons = find.widgetWithIcon(IconButton, Icons.filter_drama); | ||
for (int i = 0; i <= 3; i++) { | ||
expect(tester.widget<IconButton>(iconButtons.at(i)).onPressed is VoidCallback, isTrue); | ||
} | ||
for (int i = 4; i <= 7; i++) { | ||
expect(tester.widget<IconButton>(iconButtons.at(i)).onPressed, isNull); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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/material/ink_well/ink_well.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Clicking on InkWell changes the Size of 50x50 AnimatedContainer to 100x100 and vice versa', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const example.InkWellExampleApp(), | ||
); | ||
expect(find.widgetWithText(AppBar, 'InkWell Sample'), findsOneWidget); | ||
final Finder inkWell = find.byType(InkWell); | ||
final InkWell inkWellWidget = tester.widget<InkWell>(inkWell); | ||
final Finder animatedContainer = find.byType(AnimatedContainer); | ||
AnimatedContainer animatedContainerWidget = tester.widget<AnimatedContainer>(animatedContainer); | ||
expect(inkWell, findsOneWidget); | ||
expect(inkWellWidget.onTap.runtimeType, VoidCallback); | ||
expect(animatedContainerWidget.constraints?.minWidth, 50); | ||
expect(animatedContainerWidget.constraints?.minHeight, 50); | ||
await tester.tap(inkWell); | ||
await tester.pumpAndSettle(); | ||
animatedContainerWidget = tester.widget<AnimatedContainer>(animatedContainer); | ||
expect(animatedContainerWidget.constraints?.minWidth, 100); | ||
expect(animatedContainerWidget.constraints?.minHeight, 100); | ||
await tester.tap(inkWell); | ||
await tester.pumpAndSettle(); | ||
animatedContainerWidget = tester.widget<AnimatedContainer>(animatedContainer); | ||
expect(animatedContainerWidget.constraints?.minWidth, 50); | ||
expect(animatedContainerWidget.constraints?.minHeight, 50); | ||
}); | ||
} |