|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
5 | 5 | import 'package:flutter/material.dart';
|
| 6 | +import 'package:flutter_markdown/flutter_markdown.dart'; |
6 | 7 | import 'package:flutter_test/flutter_test.dart';
|
| 8 | +import 'package:network_image_mock/network_image_mock.dart'; |
7 | 9 | import 'package:travel_app/src/catalog/itinerary_day.dart';
|
8 | 10 |
|
9 | 11 | void main() {
|
10 |
| - testWidgets('ItineraryDay golden test', (WidgetTester tester) async { |
11 |
| - await tester.pumpWidget( |
12 |
| - MaterialApp( |
13 |
| - home: Scaffold( |
14 |
| - body: Builder( |
15 |
| - builder: (context) { |
16 |
| - return Center( |
17 |
| - child: itineraryDay.widgetBuilder( |
18 |
| - data: { |
19 |
| - 'title': 'Day 1', |
20 |
| - 'subtitle': 'Arrival in Tokyo', |
21 |
| - 'description': 'A day of exploring the city.', |
22 |
| - 'imageChildId': 'tokyo_image', |
23 |
| - 'children': <String>[], |
24 |
| - }, |
25 |
| - id: 'test', |
26 |
| - buildChild: (_) => const Placeholder(), |
27 |
| - dispatchEvent: (_) {}, |
28 |
| - context: context, |
29 |
| - values: {}, |
30 |
| - ), |
31 |
| - ); |
32 |
| - }, |
| 12 | + group('ItineraryDay', () { |
| 13 | + testWidgets('renders correctly', (WidgetTester tester) async { |
| 14 | + await tester.pumpWidget( |
| 15 | + MaterialApp( |
| 16 | + home: Scaffold( |
| 17 | + body: Builder( |
| 18 | + builder: (context) { |
| 19 | + return Center( |
| 20 | + child: itineraryDay.widgetBuilder( |
| 21 | + data: { |
| 22 | + 'title': 'Day 1', |
| 23 | + 'subtitle': 'Arrival in Tokyo', |
| 24 | + 'description': 'A day of exploring the city.', |
| 25 | + 'imageChildId': 'tokyo_image', |
| 26 | + 'children': <String>[], |
| 27 | + }, |
| 28 | + id: 'test', |
| 29 | + buildChild: (_) => const Placeholder(), |
| 30 | + dispatchEvent: (_) {}, |
| 31 | + context: context, |
| 32 | + values: {}, |
| 33 | + ), |
| 34 | + ); |
| 35 | + }, |
| 36 | + ), |
33 | 37 | ),
|
34 | 38 | ),
|
35 |
| - ), |
36 |
| - ); |
| 39 | + ); |
37 | 40 |
|
38 |
| - expect(find.text('Day 1'), findsOneWidget); |
39 |
| - expect(find.text('Arrival in Tokyo'), findsOneWidget); |
40 |
| - expect(find.text('A day of exploring the city.'), findsOneWidget); |
| 41 | + expect(find.text('Day 1'), findsOneWidget); |
| 42 | + expect(find.text('Arrival in Tokyo'), findsOneWidget); |
| 43 | + expect(find.text('A day of exploring the city.'), findsOneWidget); |
| 44 | + }); |
| 45 | + |
| 46 | + testWidgets('renders correctly with markdown', (WidgetTester tester) async { |
| 47 | + await mockNetworkImagesFor(() async { |
| 48 | + const testTitle = 'Test Title'; |
| 49 | + const testSubtitle = 'Test Subtitle'; |
| 50 | + const testDescription = 'Test **Description**'; |
| 51 | + |
| 52 | + await tester.pumpWidget( |
| 53 | + MaterialApp( |
| 54 | + home: Scaffold( |
| 55 | + body: Builder( |
| 56 | + builder: (context) { |
| 57 | + return itineraryDay.widgetBuilder( |
| 58 | + data: { |
| 59 | + 'title': testTitle, |
| 60 | + 'subtitle': testSubtitle, |
| 61 | + 'description': testDescription, |
| 62 | + 'imageChildId': 'image_child_id', |
| 63 | + 'children': <String>[], |
| 64 | + }, |
| 65 | + id: 'test_id', |
| 66 | + buildChild: (id) { |
| 67 | + if (id == 'image_child_id') { |
| 68 | + return Image.network( |
| 69 | + 'https://example.com/thumbnail.jpg', |
| 70 | + ); |
| 71 | + } |
| 72 | + return const SizedBox.shrink(); |
| 73 | + }, |
| 74 | + dispatchEvent: (event) {}, |
| 75 | + context: context, |
| 76 | + values: {}, |
| 77 | + ); |
| 78 | + }, |
| 79 | + ), |
| 80 | + ), |
| 81 | + ), |
| 82 | + ); |
| 83 | + |
| 84 | + expect(find.text(testTitle), findsOneWidget); |
| 85 | + expect(find.text(testSubtitle), findsOneWidget); |
| 86 | + expect( |
| 87 | + find.descendant( |
| 88 | + of: find.byType(MarkdownBody), |
| 89 | + matching: find.byType(RichText), |
| 90 | + ), |
| 91 | + findsOneWidget, |
| 92 | + ); |
| 93 | + expect(find.byType(Image), findsOneWidget); |
| 94 | + }); |
| 95 | + }); |
41 | 96 | });
|
42 | 97 | }
|
0 commit comments