Skip to content

Commit

Permalink
fix(booking): call textualDateTime method on toString (#170)
Browse files Browse the repository at this point in the history
* fix(booking): call `textualDateTime` method on `toString`

Addresses an issue introduced in #168

* fix(booking): ensure to always display the year textually

* test(single_booking): add test cases for `toString` method
  • Loading branch information
albertms10 committed Jan 7, 2023
1 parent da786cc commit 35a4ae2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/src/model/booking/booking.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ abstract class Booking extends DateRangeItem {
}

@override
String toString() =>
[if (isLocked) 'πŸ”’', description, textualDateTime].join(' ');
String toString() => [
if (isLocked) 'πŸ”’',
description,
// A reference DateTime with year 0 will always show the year textually.
textualDateTime(referenceDateTime: DateTime(0)),
].join(' ');

@override
bool operator ==(Object other) =>
Expand Down
24 changes: 24 additions & 0 deletions test/model/booking/single_booking_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,29 @@ void main() {
},
);
});

group('.toString()', () {
test('should return a string representation of a SingleBooking', () {
final booking = SingleBooking(
startDate: DateTime(2022, 12, 4, 9),
endDate: DateTime(2022, 12, 4, 10, 30),
description: 'Booked slot',
);
expect(booking.toString(), 'Booked slot December 4, 2022 09:00–10:30');
});

test(
'should return a string representation of a locked SingleBooking',
() {
final booking = SingleBooking(
startDate: DateTime(2023, 1, 12, 21, 15),
endDate: DateTime(2023, 1, 12, 22),
description: 'Slot',
isLocked: true,
);
expect(booking.toString(), 'πŸ”’ Slot January 12, 2023 21:15–22:00');
},
);
});
});
}

0 comments on commit 35a4ae2

Please sign in to comment.