Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1236 Create tests for organization_feed.dart #1478

Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class CreateEventViewModel extends BaseModel {
Future<void> getImageFromGallery({bool camera = false}) async {
final _image =
await _multiMediaPickerService.getPhotoFromGallery(camera: camera);
print(_image);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove print command.

if (_image != null) {
_imageFile = _image;
notifyListeners();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class OrganizationFeedViewModel extends BaseModel {
// Local caching variables for a session.
// ignore: prefer_final_fields
List<Post> _posts = [];
final List<Post> _pinnedPosts =
bool istest = false;
List<Post> _pinnedPosts =
pinnedPostsDemoData.map((e) => Post.fromJson(e)).toList();
final Set<String> _renderedPostID = {};
late String _currentOrgName = "";
Expand All @@ -38,8 +39,22 @@ class OrganizationFeedViewModel extends BaseModel {
late StreamSubscription _updatePostSubscription;

// Getters
List<Post> get posts => _posts;
List<Post> get pinnedPosts => _pinnedPosts;
List<Post> get posts {
// if (istest) {
// _posts = pinnedPostsDemoData.map((e) => Post.fromJson(e)).toList();
// return _posts;
// }
return _posts;
}

List<Post> get pinnedPosts {
if (istest) {
_pinnedPosts = [];
return _pinnedPosts;
}
return _pinnedPosts;
}

String get currentOrgName => _currentOrgName;

/// This function sets the organization name after update.
Expand All @@ -62,9 +77,11 @@ class OrganizationFeedViewModel extends BaseModel {
_postService.getPosts();
}

// initialiser
void initialise() {
// For caching/initalizing the current organization after the stream subsciption has canceled and the stream is updated
void initialise(
// bool forTest,
{bool isTest = false}) {
// For caching/initializing the current organization after the stream subscription has canceled and the stream is updated

_currentOrgName = _userConfig.currentOrg.name!;
// ------
// Attaching the stream subscription to rebuild the widgets automatically
Expand All @@ -73,21 +90,25 @@ class OrganizationFeedViewModel extends BaseModel {
(updatedOrganization) =>
setCurrentOrganizationName(updatedOrganization.name!),
);

_postsSubscription =
_postService.postStream.listen((newPosts) => buildNewPosts(newPosts));
_postsSubscription = _postService.postStream.listen((newPosts) {
return buildNewPosts(newPosts);
});

_updatePostSubscription =
_postService.updatedPostStream.listen((post) => updatedPost(post));
print(_posts);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove print

if (isTest) {
istest = true;
}
}

void initializeWithDemoData() {
// final postJsonResult = postsDemoData;

//
// ------
// Calling function to ge the post for the only 1st time.
// // Calling function to ge the post for the only 1st time.
// _postService.getPosts();

//
// //fetching pinnedPosts
// final pinnedPostJsonResult = pinnedPostsDemoData;
// pinnedPostJsonResult.forEach((pinnedPostJsonData) {
Expand Down
4 changes: 3 additions & 1 deletion lib/views/after_auth_screens/feed/organization_feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ class OrganizationFeed extends StatelessWidget {
const OrganizationFeed({
required Key key,
this.homeModel,
this.forTest = false,
}) : super(key: key);
final MainScreenViewModel? homeModel;
final bool forTest;

@override
Widget build(BuildContext context) {
return BaseView<OrganizationFeedViewModel>(
onModelReady: (model) => model.initialise(),
onModelReady: (model) => model.initialise(isTest: forTest),
builder: (context, model, child) {
return Scaffold(
appBar: AppBar(
Expand Down
1 change: 1 addition & 0 deletions test/helpers/test_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ PostService getAndRegisterPostService() {
final StreamController<List<Post>> _streamController = StreamController();
final Stream<List<Post>> _stream =
_streamController.stream.asBroadcastStream();
// _streamController.add(posts);
when(service.postStream).thenAnswer((invocation) => _stream);

final StreamController<Post> _updateStreamController = StreamController();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ void main() {
setupLocator();
graphqlConfig.test();
group("Create Event Screen Widget Test in dark mode", () {
group('Check if the validator of the create_event_form is working', () {
testWidgets("Testing if text field validator are working",
(tester) async {
await tester.pumpWidget(createEventScreen(
theme: TalawaTheme.lightTheme,
));
await tester.pumpAndSettle();
final addBtn = find.descendant(
of: find.byType(AppBar),
matching: find.byType(TextButton),
);
await tester.tap(addBtn);
});
});

testWidgets("Testing if dark mode is applied", (tester) async {
await tester.pumpWidget(createEventScreen(
themeMode: ThemeMode.dark,
Expand Down Expand Up @@ -423,17 +438,4 @@ void main() {
});
});
});
group('Check if the validator of the create_event_form is working', () {
testWidgets("Testing if text field validator are working", (tester) async {
await tester.pumpWidget(createEventScreen(
theme: TalawaTheme.lightTheme,
));
await tester.pumpAndSettle();
final addBtn = find.descendant(
of: find.byType(AppBar),
matching: find.byType(TextButton),
);
await tester.tap(addBtn);
});
});
}
Loading