Guest User

Untitled

a guest
Jun 24th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. import 'dart:io';
  2.  
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_test/flutter_test.dart';
  5. import 'package:thermometer/main.dart';
  6. import 'package:thermometer/thermometer_widget.dart';
  7.  
  8. void main() {
  9. Widget createDefaultThermometerWidget() {
  10. return Center(
  11. child: RepaintBoundary(child: ThermometerWidget()),
  12. );
  13. }
  14.  
  15. Widget createThermometerWidgetWithColors() {
  16. return Center(
  17. child: RepaintBoundary(
  18. child: ThermometerWidget(
  19. borderColor: Colors.red,
  20. innerColor: Colors.green,
  21. indicatorColor: Colors.red,
  22. )),
  23. );
  24. }
  25.  
  26. Widget createThermometerWidgetWithColorsAnd100Degrees() {
  27. return Center(
  28. child: RepaintBoundary(
  29. child: ThermometerWidget(
  30. borderColor: Colors.red,
  31. innerColor: Colors.green,
  32. indicatorColor: Colors.red,
  33. temperature: 100.0,
  34. )),
  35. );
  36. }
  37.  
  38. Widget createThermometerWidgetWithColorsAndZeroDegrees() {
  39. return Center(
  40. child: RepaintBoundary(
  41. child: ThermometerWidget(
  42. borderColor: Colors.red,
  43. innerColor: Colors.green,
  44. indicatorColor: Colors.red,
  45. temperature: 0.0,
  46. )),
  47. );
  48. }
  49.  
  50. testWidgets('Widget test', (WidgetTester tester) async {
  51. await tester.pumpWidget(new MyApp());
  52.  
  53. // Check if the thermometer widget is present in the app.
  54. expect(find.byType(ThermometerWidget), findsOneWidget);
  55.  
  56. // Check that the ThermometerWidget has a CustomPaint child
  57. expect(
  58. find.descendant(
  59. of: find.byType(ThermometerWidget),
  60. matching: find.byType(CustomPaint)),
  61. findsOneWidget);
  62. });
  63.  
  64. testWidgets('Default ThermometerWidget matches goldenfile test',
  65. (WidgetTester tester) async {
  66. Widget widget = createDefaultThermometerWidget();
  67. await tester.pumpWidget(widget);
  68. await expectLater(
  69. find.byType(ThermometerWidget),
  70. matchesGoldenFile('golden/defaultThermometerGoldenImage.png'),
  71. skip: !Platform.isWindows,
  72. );
  73. });
  74.  
  75. testWidgets('ThermometerWidget with color matches goldenfile test',
  76. (WidgetTester tester) async {
  77. Widget widget = createThermometerWidgetWithColors();
  78. await tester.pumpWidget(widget);
  79. await expectLater(
  80. find.byType(ThermometerWidget),
  81. matchesGoldenFile('golden/thermometerWithColorsGoldenImage.png'),
  82. skip: !Platform.isWindows,
  83. );
  84. });
  85.  
  86. testWidgets(
  87. 'ThermometerWidget with color and 100 degrees Celsius matches golden file',
  88. (WidgetTester tester) async {
  89. Widget widget = createThermometerWidgetWithColorsAnd100Degrees();
  90. await tester.pumpWidget(widget);
  91. await expectLater(
  92. find.byType(ThermometerWidget),
  93. matchesGoldenFile('golden/thermometerWithColorsAnd100DegGoldenImage.png'),
  94. skip: !Platform.isWindows,
  95. );
  96. });
  97.  
  98. testWidgets(
  99. 'ThermometerWidget with color and 0 degrees Celsius matches golden file',
  100. (WidgetTester tester) async {
  101. Widget widget = createThermometerWidgetWithColorsAndZeroDegrees();
  102. await tester.pumpWidget(widget);
  103. await expectLater(
  104. find.byType(ThermometerWidget),
  105. matchesGoldenFile(
  106. 'golden/thermometerWithColorsAndZeroDegGoldenImage.png'),
  107. skip: !Platform.isWindows,
  108. );
  109. });
  110. }
Add Comment
Please, Sign In to add comment