|
| 1 | +import 'dart:io'; |
| 2 | + |
| 3 | +import 'package:flutter/material.dart'; |
| 4 | +import 'package:flutter_test_goldens/flutter_test_goldens.dart'; |
| 5 | +import 'package:flutter_test_goldens/golden_bricks.dart'; |
| 6 | + |
| 7 | +void main() { |
| 8 | + testGoldenScene('reports multiple failures', (tester) async { |
| 9 | + await Gallery( |
| 10 | + tester, |
| 11 | + directory: Directory("./goldens"), |
| 12 | + fileName: "multiple_failures", |
| 13 | + sceneDescription: "Multiple Failures", |
| 14 | + layout: SceneLayout.column, |
| 15 | + ) |
| 16 | + .itemFromWidget( |
| 17 | + id: '1', |
| 18 | + description: 'Red Rectangle', |
| 19 | + // Use _buildGoldenRectangle to build the original golden rectangle. |
| 20 | + widget: _buildMismatchRectangle(), |
| 21 | + ) |
| 22 | + .itemFromWidget( |
| 23 | + id: '2', |
| 24 | + description: 'A text', |
| 25 | + // Use _buildGoldenText to build the original golden text. |
| 26 | + widget: _buildMismatchText(), |
| 27 | + ) |
| 28 | + // The following item is present in the golden file. |
| 29 | + // .itemFromWidget( |
| 30 | + // id: '3', |
| 31 | + // description: 'Another Red Rectangle', |
| 32 | + // widget: _buildGoldenRectangle(), |
| 33 | + // ) |
| 34 | + // |
| 35 | + // The following item is not present in the golden file. |
| 36 | + .itemFromWidget( |
| 37 | + id: '4', |
| 38 | + description: 'An unexpected Rectangle', |
| 39 | + widget: _buildGoldenRectangle(), |
| 40 | + ) |
| 41 | + .renderOrCompareGolden(); |
| 42 | + }); |
| 43 | +} |
| 44 | + |
| 45 | +/// The widget used to build the original golden rectangle. |
| 46 | +Widget _buildGoldenRectangle() { |
| 47 | + return Container( |
| 48 | + width: 150, |
| 49 | + height: 100, |
| 50 | + color: Colors.red, |
| 51 | + ); |
| 52 | +} |
| 53 | + |
| 54 | +/// The widget used to build the mismatch rectangle. |
| 55 | +/// |
| 56 | +/// It has the same same size as the golden rectangle but a different color. |
| 57 | +Widget _buildMismatchRectangle() { |
| 58 | + return Container( |
| 59 | + width: 150, |
| 60 | + height: 100, |
| 61 | + color: Colors.green, |
| 62 | + ); |
| 63 | +} |
| 64 | + |
| 65 | +/// The widget used to build the original golden text. |
| 66 | +// ignore: unused_element |
| 67 | +Widget _buildGoldenText() { |
| 68 | + return Text( |
| 69 | + 'A text widget', |
| 70 | + style: TextStyle( |
| 71 | + fontFamily: goldenBricks, |
| 72 | + ), |
| 73 | + ); |
| 74 | +} |
| 75 | + |
| 76 | +/// The widget used to build the mismatch golden text. |
| 77 | +/// |
| 78 | +/// It has the same text but all uppercase. |
| 79 | +Widget _buildMismatchText() { |
| 80 | + return Text( |
| 81 | + 'A TEXT WIDGET', |
| 82 | + style: TextStyle( |
| 83 | + fontFamily: goldenBricks, |
| 84 | + ), |
| 85 | + ); |
| 86 | +} |
0 commit comments