Skip to content

Commit

Permalink
test: refactored the unnecessary usage of NewsFeedEntity class when t…
Browse files Browse the repository at this point in the history
…esting ArticlesEntity class
  • Loading branch information
BasakK6 committed Sep 29, 2023
1 parent 025191a commit afe80ce
Showing 1 changed file with 23 additions and 43 deletions.
66 changes: 23 additions & 43 deletions test/features/news_feed/domain/entities/news_feed_entity_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,83 +5,63 @@ void main() {
group("timeAgo tests", () {
test("should return null when publishedAt is null", () {
//arrange
const testNewsFeedEntity = NewsFeedEntity(
articles: [
ArticlesEntity(
//publishedAt: "2023-09-24T05:35:00Z",
)
],
const testArticlesEntity = ArticlesEntity(
//publishedAt: "2023-09-24T05:35:00Z",
);
//act
final result = testNewsFeedEntity.articles?[0].timeAgo;
final result = testArticlesEntity.timeAgo;
//assert
expect(result, "Unknown");
});

test("should return Just now for very recent time", () {
//arrange
final testNewsFeedEntity = NewsFeedEntity(
articles: [
ArticlesEntity(
publishedAt: DateTime.now()
.subtract(const Duration(seconds: 5))
.toIso8601String(),
)
],
final testArticlesEntity = ArticlesEntity(
publishedAt: DateTime.now()
.subtract(const Duration(seconds: 5))
.toIso8601String(),
);
//act
final result = testNewsFeedEntity.articles?[0].timeAgo;
final result = testArticlesEntity.timeAgo;
//assert
expect(result, equals('Just now'));
});

test("should return time difference in minutes", () {
//arrange
final testNewsFeedEntity = NewsFeedEntity(
articles: [
ArticlesEntity(
publishedAt: DateTime.now()
.subtract(const Duration(minutes: 30))
.toIso8601String(),
)
],
final testArticlesEntity = ArticlesEntity(
publishedAt: DateTime.now()
.subtract(const Duration(minutes: 30))
.toIso8601String(),
);
//act
final result = testNewsFeedEntity.articles?[0].timeAgo;
final result = testArticlesEntity.timeAgo;
//assert
expect(result, equals('30 Minutes ago'));
});

test("returns time difference in hours", () {
//arrange
final testNewsFeedEntity = NewsFeedEntity(
articles: [
ArticlesEntity(
publishedAt: DateTime.now()
.subtract(const Duration(hours: 3))
.toIso8601String(),
)
],
final testArticlesEntity = ArticlesEntity(
publishedAt: DateTime.now()
.subtract(const Duration(hours: 3))
.toIso8601String(),
);
//act
final result = testNewsFeedEntity.articles?[0].timeAgo;
final result = testArticlesEntity.timeAgo;
//assert
expect(result, equals('3 Hours ago'));
});

test("should return time difference in days", () {
//arrange
final testNewsFeedEntity = NewsFeedEntity(
articles: [
ArticlesEntity(
publishedAt: DateTime.now()
.subtract(const Duration(days: 3))
.toIso8601String(),
)
],
final testArticlesEntity = ArticlesEntity(
publishedAt: DateTime.now()
.subtract(const Duration(days: 3))
.toIso8601String(),
);
//act
final result = testNewsFeedEntity.articles?[0].timeAgo;
final result = testArticlesEntity.timeAgo;
//assert
expect(result, equals('3 Days ago'));
});
Expand Down

0 comments on commit afe80ce

Please sign in to comment.