1
- import 'dart:async' ;
2
-
3
1
import 'package:flutter/material.dart' ;
4
2
import 'package:flutter_localizations/flutter_localizations.dart' ;
5
3
import 'package:flutter_test/flutter_test.dart' ;
6
4
import 'package:mockito/mockito.dart' ;
7
- import 'package:talawa/models/organization/org_info.dart' ;
8
- import 'package:talawa/models/post/post_model.dart' ;
9
- import 'package:talawa/models/user/user_info.dart' ;
5
+ import 'package:talawa/router.dart' ;
6
+ import 'package:talawa/services/navigation_service.dart' ;
10
7
import 'package:talawa/services/post_service.dart' ;
11
8
import 'package:talawa/services/size_config.dart' ;
12
9
import 'package:talawa/utils/app_localization.dart' ;
10
+ import 'package:talawa/view_model/lang_view_model.dart' ;
13
11
import 'package:talawa/view_model/main_screen_view_model.dart' ;
14
12
import 'package:talawa/views/after_auth_screens/feed/organization_feed.dart' ;
13
+ import 'package:talawa/views/base_view.dart' ;
15
14
16
15
import '../../../helpers/test_helpers.dart' ;
17
16
import '../../../helpers/test_locator.dart' ;
@@ -48,6 +47,46 @@ Widget createOrganizationFeedScreen({
48
47
)));
49
48
}
50
49
50
+ // late OrganizationFeedViewModel _organizationFeedViewModel;
51
+
52
+ Widget createOrganizationFeedScreen2 ({
53
+ bool isPublic = true ,
54
+ bool viewOnMap = true ,
55
+ required MainScreenViewModel homeModel,
56
+ }) {
57
+ return BaseView <AppLanguage >(
58
+ onModelReady: (model) => model.initialize (),
59
+ // builder: (context, langModel, child) {
60
+ // return BaseView<OrganizationFeedViewModel>(
61
+ // onModelReady: (model) {
62
+ // model.initialise();
63
+ // _organizationFeedViewModel = model;
64
+ // },
65
+ builder: (context, model, child) {
66
+ return MaterialApp (
67
+ locale: const Locale ('en' ),
68
+ localizationsDelegates: [
69
+ const AppLocalizationsDelegate (isTest: true ),
70
+ GlobalMaterialLocalizations .delegate,
71
+ GlobalWidgetsLocalizations .delegate,
72
+ ],
73
+ home: Scaffold (
74
+ key: MainScreenViewModel .scaffoldKey,
75
+ body: OrganizationFeed (
76
+ homeModel: homeModel,
77
+ key: const Key ('test_key' ),
78
+ forTest: true ,
79
+ ),
80
+ ),
81
+ navigatorKey: locator <NavigationService >().navigatorKey,
82
+ onGenerateRoute: generateRoute,
83
+ );
84
+ },
85
+ // );
86
+ // },
87
+ );
88
+ }
89
+
51
90
void main () {
52
91
SizeConfig ().test ();
53
92
testSetupLocator ();
@@ -57,6 +96,7 @@ void main() {
57
96
registerServices ();
58
97
});
59
98
99
+ TestWidgetsFlutterBinding .ensureInitialized ();
60
100
testWidgets ('check if createOrganizationFeedScreen shows up' , (tester) async {
61
101
final model = locator <MainScreenViewModel >();
62
102
await tester.pumpWidget (createOrganizationFeedScreen (homeModel: model));
@@ -138,73 +178,79 @@ void main() {
138
178
139
179
expect (refreshed, true );
140
180
});
141
- testWidgets ('check if post shows up when model.posts.isNotEmpty is true' ,
181
+ testWidgets (
182
+ 'check if post shows up when model.posts.isNotEmpty is true and post' ,
142
183
(tester) async {
184
+ // _organizationFeedViewModel.setValueForTest();
143
185
final model = locator <MainScreenViewModel >();
144
- await tester.pumpWidget (createOrganizationFeedScreen (homeModel: model));
145
- await tester.pump ();
186
+ await tester.pumpWidget (createOrganizationFeedScreen2 (homeModel: model));
187
+ await tester.pumpAndSettle (const Duration (seconds: 1 ));
188
+ // tester.allElements.forEach((element) {
189
+ // print(element);
190
+ // });
146
191
147
- final postservice = locator < PostService > ();
192
+ // _organizationFeedViewModel.setValueForTest ();
148
193
149
- final u1 = User (
150
- id: '123' ,
151
- firstName: 'John' ,
152
- lastName: 'Doe' ,
153
-
154
- );
155
- final u2 = User (
156
- id: '123' ,
157
- firstName: 'Ayush' ,
158
- lastName: 'Chaudhary' ,
159
-
160
- );
161
- final List <User > users = [u1, u2];
162
-
163
- final LikedBy l1 = LikedBy (sId: 'test1' );
164
- final LikedBy l2 = LikedBy (sId: 'test2' );
165
- final List <LikedBy > likeby = [l1, l2];
166
-
167
- final comment1 = Comments (sId: 'comment1' );
168
- final comment2 = Comments (sId: 'comment2' );
169
- final comment3 = Comments (sId: 'comment3' );
170
- final List <Comments > comments = [comment1, comment2, comment3];
171
-
172
- final myBirthday = DateTime .utc (2004 , DateTime .june, 16 , 5 , 30 , 0 , 0 , 0 );
173
- final post = Post (
174
- creator: User (
175
- id: '123' ,
176
- firstName: 'John' ,
177
- lastName: 'Doe' ,
178
-
179
- ),
180
- sId: "sid" ,
181
- createdAt: myBirthday,
182
- description: 'test description' ,
183
- imageUrl: 'https://image.com' ,
184
- videoUrl: 'https://image.com' ,
185
- organization: OrgInfo (admins: users),
186
- likedBy: likeby,
187
- comments: comments,
188
- );
189
- final List <Post > posts = [post];
194
+ // final u1 = User(
195
+ // id: '123',
196
+ // firstName: 'John',
197
+ // lastName: 'Doe',
198
+
199
+ // );
200
+ // final u2 = User(
201
+ // id: '123',
202
+ // firstName: 'Ayush',
203
+ // lastName: 'Chaudhary',
204
+
205
+ // );
206
+ // final List<User> users = [u1, u2];
207
+ //
208
+ // final LikedBy l1 = LikedBy(sId: 'test1');
209
+ // final LikedBy l2 = LikedBy(sId: 'test2');
210
+ // final List<LikedBy> likeby = [l1, l2];
211
+ //
212
+ // final comment1 = Comments(sId: 'comment1');
213
+ // final comment2 = Comments(sId: 'comment2');
214
+ // final comment3 = Comments(sId: 'comment3');
215
+ // final List<Comments> comments = [comment1, comment2, comment3];
216
+ //
217
+ // final myBirthday = DateTime.utc(2004, DateTime.june, 16, 5, 30, 0, 0, 0);
218
+ // final post = Post(
219
+ // creator: User(
220
+ // id: '123',
221
+ // firstName: 'John',
222
+ // lastName: 'Doe',
223
+
224
+ // ),
225
+ // sId: "sid",
226
+ // createdAt: myBirthday,
227
+ // description: 'test description',
228
+ // imageUrl: 'https://image.com',
229
+ // videoUrl: 'https://image.com',
230
+ // organization: OrgInfo(admins: users),
231
+ // likedBy: likeby,
232
+ // comments: comments,
233
+ // );
234
+ // final List<Post> posts = [post];
190
235
// when(postservice.postStream).
191
- final StreamController <List <Post >> _streamController = StreamController ();
192
- final Stream <List <Post >> _stream =
193
- _streamController.stream.asBroadcastStream ();
236
+ // final StreamController<List<Post>> _streamController = StreamController();
237
+ // final Stream<List<Post>> _stream =
238
+ // _streamController.stream.asBroadcastStream();
194
239
195
- // final service = MockEventService();
196
- when (postService.postStream).thenAnswer ((invocation) {
197
- return _stream;
198
- });
199
- postservice.postStream.listen ((event) {
200
- print (11 );
201
- });
202
- _streamController.add (posts);
203
- await tester.drag (
204
- find.byType (RefreshIndicator ),
205
- const Offset (0 , 200 ),
206
- );
240
+ // final service = MockPostService();
241
+ // when(service.postStream).thenAnswer((invocation) {
242
+ // return _stream;
243
+ // });
244
+ // postservice.postStream.listen((event) {
245
+ // print(11);
246
+ // });
247
+ // getAndRegisterPostService();
248
+ // _streamController.add(posts);
249
+ // await tester.drag(
250
+ // find.byType(RefreshIndicator),
251
+ // const Offset(0, 200),
252
+ // );
207
253
208
- await tester.pumpAndSettle ();
254
+ // await tester.pumpAndSettle(Duration(milliseconds: 100) );
209
255
});
210
256
}
0 commit comments