|
| 1 | +import 'package:alchemist/alchemist.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:flutter_test/flutter_test.dart'; |
| 4 | +import 'package:stream_chat_flutter/stream_chat_flutter.dart'; |
| 5 | + |
| 6 | +import '../src/golden_client_stubs.dart'; |
| 7 | +import '../src/golden_theme.dart'; |
| 8 | +import '../src/mocks.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + TestWidgetsFlutterBinding.ensureInitialized(); |
| 12 | + |
| 13 | + goldenTest( |
| 14 | + 'channel preview tile', |
| 15 | + fileName: 'channel_preview', |
| 16 | + constraints: const BoxConstraints.tightFor(width: 375, height: 80), |
| 17 | + builder: () { |
| 18 | + final client = MockClient(); |
| 19 | + final channel = fakeChannel( |
| 20 | + client: client, |
| 21 | + id: 'general', |
| 22 | + name: 'General', |
| 23 | + messages: [ |
| 24 | + Message( |
| 25 | + id: 'msg-1', |
| 26 | + text: 'Hey everyone! 👋', |
| 27 | + user: User(id: 'user-2', name: 'Bob'), |
| 28 | + createdAt: DateTime(2024, 6, 1, 10, 30), |
| 29 | + ), |
| 30 | + ], |
| 31 | + ); |
| 32 | + |
| 33 | + return MaterialApp( |
| 34 | + theme: docsScreenshotsTheme(), |
| 35 | + debugShowCheckedModeBanner: false, |
| 36 | + home: StreamChat( |
| 37 | + client: client, |
| 38 | + connectivityStream: Stream.value([ConnectivityResult.mobile]), |
| 39 | + child: Scaffold( |
| 40 | + body: StreamChannelListItem(channel: channel), |
| 41 | + ), |
| 42 | + ), |
| 43 | + ); |
| 44 | + }, |
| 45 | + ); |
| 46 | + |
| 47 | + goldenTest( |
| 48 | + 'channel list view', |
| 49 | + fileName: 'channel_list_view', |
| 50 | + constraints: const BoxConstraints.tightFor(width: 375, height: 400), |
| 51 | + builder: () { |
| 52 | + final client = MockClient(); |
| 53 | + |
| 54 | + final channels = [ |
| 55 | + fakeChannel( |
| 56 | + client: client, |
| 57 | + id: 'general', |
| 58 | + name: 'General', |
| 59 | + messages: [ |
| 60 | + Message( |
| 61 | + id: 'msg-1', |
| 62 | + text: 'Hey, how is everyone doing?', |
| 63 | + user: User(id: 'user-2', name: 'Bob'), |
| 64 | + createdAt: DateTime(2024, 6, 1, 10, 30), |
| 65 | + ), |
| 66 | + ], |
| 67 | + unreadCount: 2, |
| 68 | + ), |
| 69 | + fakeChannel( |
| 70 | + client: client, |
| 71 | + id: 'design', |
| 72 | + name: 'Design', |
| 73 | + messages: [ |
| 74 | + Message( |
| 75 | + id: 'msg-2', |
| 76 | + text: 'New mockups are ready!', |
| 77 | + user: User(id: 'user-3', name: 'Carol'), |
| 78 | + createdAt: DateTime(2024, 6, 1, 9, 15), |
| 79 | + ), |
| 80 | + ], |
| 81 | + ), |
| 82 | + fakeChannel( |
| 83 | + client: client, |
| 84 | + id: 'random', |
| 85 | + name: 'Random', |
| 86 | + messages: [ |
| 87 | + Message( |
| 88 | + id: 'msg-3', |
| 89 | + text: 'Anyone up for lunch?', |
| 90 | + user: User(id: 'user-4', name: 'Dave'), |
| 91 | + createdAt: DateTime(2024, 5, 31, 12, 0), |
| 92 | + ), |
| 93 | + ], |
| 94 | + ), |
| 95 | + fakeChannel( |
| 96 | + client: client, |
| 97 | + id: 'engineering', |
| 98 | + name: 'Engineering', |
| 99 | + messages: [ |
| 100 | + Message( |
| 101 | + id: 'msg-4', |
| 102 | + text: 'PR #42 is ready for review', |
| 103 | + user: User(id: 'user-5', name: 'Eve'), |
| 104 | + createdAt: DateTime(2024, 5, 30, 15, 45), |
| 105 | + ), |
| 106 | + ], |
| 107 | + ), |
| 108 | + ]; |
| 109 | + |
| 110 | + final controller = StreamChannelListController.fromValue( |
| 111 | + PagedValue(items: channels), |
| 112 | + client: client, |
| 113 | + ); |
| 114 | + |
| 115 | + stubQueryChannelsForGoldens(client, channels); |
| 116 | + |
| 117 | + return MaterialApp( |
| 118 | + theme: docsScreenshotsTheme(), |
| 119 | + debugShowCheckedModeBanner: false, |
| 120 | + home: StreamChat( |
| 121 | + client: client, |
| 122 | + connectivityStream: Stream.value([ConnectivityResult.mobile]), |
| 123 | + child: Scaffold( |
| 124 | + body: StreamChannelListView( |
| 125 | + controller: controller, |
| 126 | + shrinkWrap: true, |
| 127 | + ), |
| 128 | + ), |
| 129 | + ), |
| 130 | + ); |
| 131 | + }, |
| 132 | + ); |
| 133 | + |
| 134 | + goldenTest( |
| 135 | + 'swipe channel to reveal actions', |
| 136 | + fileName: 'swipe_channel', |
| 137 | + constraints: const BoxConstraints.tightFor(width: 375, height: 80), |
| 138 | + builder: () { |
| 139 | + final client = MockClient(); |
| 140 | + final channel = fakeChannel( |
| 141 | + client: client, |
| 142 | + id: 'general', |
| 143 | + name: 'General', |
| 144 | + messages: [ |
| 145 | + Message( |
| 146 | + id: 'msg-1', |
| 147 | + text: 'Hey, how is everyone doing?', |
| 148 | + user: User(id: 'user-2', name: 'Bob'), |
| 149 | + createdAt: DateTime(2024, 6, 1, 10, 30), |
| 150 | + ), |
| 151 | + ], |
| 152 | + ); |
| 153 | + |
| 154 | + return MaterialApp( |
| 155 | + theme: docsScreenshotsTheme(), |
| 156 | + debugShowCheckedModeBanner: false, |
| 157 | + home: StreamChat( |
| 158 | + client: client, |
| 159 | + connectivityStream: Stream.value([ConnectivityResult.mobile]), |
| 160 | + child: Scaffold( |
| 161 | + body: Swipeable( |
| 162 | + key: const ValueKey('swipeable-channel'), |
| 163 | + backgroundBuilder: (context, details) => Container( |
| 164 | + color: Colors.red, |
| 165 | + alignment: Alignment.centerRight, |
| 166 | + padding: const EdgeInsets.symmetric(horizontal: 20), |
| 167 | + child: const Icon(Icons.delete, color: Colors.white), |
| 168 | + ), |
| 169 | + child: StreamChannelListItem(channel: channel), |
| 170 | + ), |
| 171 | + ), |
| 172 | + ), |
| 173 | + ); |
| 174 | + }, |
| 175 | + ); |
| 176 | +} |
0 commit comments