diff --git a/app/lib/feedback/history/feedback_view.dart b/app/lib/feedback/history/feedback_view.dart index 62e49460a..4292a5e3a 100644 --- a/app/lib/feedback/history/feedback_view.dart +++ b/app/lib/feedback/history/feedback_view.dart @@ -36,7 +36,7 @@ class FeedbackView { factory FeedbackView.fromUserFeedback(UserFeedback feedback) { return FeedbackView( - rating: '${feedback.rating}/5.0', + rating: feedback.rating == null ? null : '${feedback.rating}/5.0', likes: feedback.likes, dislikes: feedback.dislikes, heardFrom: feedback.heardFrom, diff --git a/app/lib/feedback/src/models/user_feedback.dart b/app/lib/feedback/src/models/user_feedback.dart index e0bdae9b1..645ae28ba 100644 --- a/app/lib/feedback/src/models/user_feedback.dart +++ b/app/lib/feedback/src/models/user_feedback.dart @@ -77,7 +77,7 @@ class UserFeedback { factory UserFeedback.fromJson(Map map) { return UserFeedback._( createdOn: dateTimeFromTimestampOrNull(map['createdOn']), - rating: double.tryParse(map['rating']), + rating: map['rating'] == null ? null : double.tryParse(map['rating']), likes: map['likes'] ?? '', dislikes: map['dislikes'] ?? '', missing: map['missing'] ?? '', diff --git a/app/test/feedback/feedback_view_test.dart b/app/test/feedback/feedback_view_test.dart new file mode 100644 index 000000000..71bb1e719 --- /dev/null +++ b/app/test/feedback/feedback_view_test.dart @@ -0,0 +1,63 @@ +// Copyright (c) 2022 Sharezone UG (haftungsbeschränkt) +// Licensed under the EUPL-1.2-or-later. +// +// You may obtain a copy of the Licence at: +// https://joinup.ec.europa.eu/software/page/eupl +// +// SPDX-License-Identifier: EUPL-1.2 + +import 'package:flutter_test/flutter_test.dart'; +import 'package:sharezone/feedback/history/feedback_view.dart'; +import 'package:sharezone/feedback/src/models/user_feedback.dart'; + +void main() { + group(FeedbackView, () { + test('.fromUserFeedback() empty', () { + final feedback = UserFeedback.create(); + final view = FeedbackView.fromUserFeedback(feedback); + + expect(view.rating, isNull); + expect(view.likes, ''); + expect(view.dislikes, ''); + expect(view.heardFrom, ''); + expect(view.missing, ''); + expect(view.createdOn, isNull); + }); + + test('.fromUserFeedback() with data', () { + final feedback = UserFeedback.create().copyWith( + rating: 5.0, + dislikes: 'd', + heardFrom: 'h', + likes: 'l', + missing: 'm', + ); + final view = FeedbackView.fromUserFeedback(feedback); + + expect(view.rating, '5.0/5.0'); + expect(view.likes, 'l'); + expect(view.dislikes, 'd'); + expect(view.heardFrom, 'h'); + expect(view.missing, 'm'); + expect(view.createdOn, isNull); + }); + + test('.hasX returns null even it is empty', () { + const view = FeedbackView( + createdOn: '', + rating: '', + likes: '', + dislikes: '', + heardFrom: '', + missing: '', + ); + + expect(view.hasCreatedOn, isFalse); + expect(view.hasRating, isFalse); + expect(view.hasLikes, isFalse); + expect(view.hasDislikes, isFalse); + expect(view.hasHeardFrom, isFalse); + expect(view.hasMissing, isFalse); + }); + }); +}