-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from cgustav/release/1.0.1
Release/1.0.1
- Loading branch information
Showing
6 changed files
with
151 additions
and
41 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
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
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
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
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
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 |
---|---|---|
@@ -1,13 +1,79 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:lite_rolling_switch/lite_rolling_switch.dart'; | ||
|
||
void main() { | ||
test('adds one to input values', () { | ||
final rollingSwitch = LiteRollingSwitch( | ||
onChanged: (bool) {}, | ||
onDoubleTap: () {}, | ||
onSwipe: () {}, | ||
onTap: () {}, | ||
testWidgets( | ||
'Button switch have the expected text and an icon on initial state', | ||
(tester) async { | ||
// Create the widget by telling the tester to build it. | ||
await tester.pumpWidget(MaterialApp( | ||
home: Center( | ||
child: LiteRollingSwitch( | ||
value: false, | ||
textOff: 'Off', | ||
iconOff: Icons.remove, | ||
onTap: () {}, | ||
onDoubleTap: () {}, | ||
onSwipe: () {}, | ||
onChanged: (value) {}), | ||
))); | ||
|
||
// Create the Finders. | ||
final textFinder = find.text('Off'); | ||
final iconFinder = find.byIcon(Icons.remove); | ||
|
||
// Use the `findsOneWidget` matcher provided by flutter_test to | ||
// verify that there is exactly one widget in the widget tree. | ||
expect(textFinder, findsOneWidget); | ||
expect(iconFinder, findsOneWidget); | ||
}); | ||
|
||
testWidgets( | ||
'Button switch change to the expected text and an icon when tapped', | ||
(tester) async { | ||
// Constants | ||
const defaultDuration = Duration(milliseconds: 600); | ||
const initialStateIcon = Icons.add; | ||
const initialStateText = 'On'; | ||
const finalStateIcon = Icons.remove; | ||
const finalStateText = 'Off'; | ||
|
||
// Create the widget by telling the tester to build it. | ||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: LiteRollingSwitch( | ||
value: true, | ||
textOn: initialStateText, | ||
iconOn: initialStateIcon, | ||
textOff: finalStateText, | ||
iconOff: finalStateIcon, | ||
animationDuration: defaultDuration, | ||
onTap: () {}, | ||
onDoubleTap: () {}, | ||
onSwipe: () {}, | ||
onChanged: (value) {})), | ||
); | ||
|
||
// Initial state Finders. | ||
final initialStateTextFinder = find.text(initialStateText); | ||
final initialStateIconFinder = find.byIcon(initialStateIcon); | ||
|
||
// Use the `findsOneWidget` matcher provided by flutter_test to | ||
// verify that there is exactly one widget in the widget tree. | ||
expect(initialStateTextFinder, findsOneWidget); | ||
expect(initialStateIconFinder, findsOneWidget); | ||
|
||
// Tap the icon and trigger a frame (animation tick). | ||
await tester.tap(initialStateIconFinder); | ||
await tester.pump(defaultDuration); | ||
|
||
// Final state Finders. | ||
final finalStateTextFinder = find.text(finalStateText); | ||
final finalStateIconFinder = find.byIcon(finalStateIcon); | ||
|
||
// Verify that our text and icon has changed as expected. | ||
expect(finalStateTextFinder, findsOneWidget); | ||
expect(finalStateIconFinder, findsOneWidget); | ||
}); | ||
} |