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

Fix loading feedback when rating is null #1380

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/lib/feedback/history/feedback_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/lib/feedback/src/models/user_feedback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class UserFeedback {
factory UserFeedback.fromJson(Map<String, dynamic> 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'] ?? '',
Expand Down
63 changes: 63 additions & 0 deletions app/test/feedback/feedback_view_test.dart
Original file line number Diff line number Diff line change
@@ -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);
});
});
}
Loading