Skip to content

Commit

Permalink
test: add test cases for handling of reblogs
Browse files Browse the repository at this point in the history
  • Loading branch information
aitorres committed Dec 30, 2024
1 parent 51ed4b7 commit cf5209a
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 20 deletions.
129 changes: 109 additions & 20 deletions test/data_test/status_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,65 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:feathr/data/status.dart';

void main() {
const Map<String, dynamic> testStatusNoReblog = {
"id": "11223344",
"content": "<p>I am a toot!</p>",
"favourited": true,
"bookmarked": false,
"reblogged": true,
"account": {
"id": "this is an id",
"username": "username123",
"acct": "username123",
"display_name": "user display name",
"locked": false,
"bot": true,
"avatar": "avatar-url",
"header": "header-url",
},
"reblog": null,
};

const Map<String, dynamic> testStatusWithReblog = {
"id": "11223344",
"content": "<p>I am a toot!</p>",
"favourited": true,
"bookmarked": false,
"reblogged": true,
"account": {
"id": "this is an id",
"username": "username123",
"acct": "username123",
"display_name": "user display name",
"locked": false,
"bot": true,
"avatar": "avatar-url",
"header": "header-url",
},
"reblog": {
"id": "55667788",
"content": "<p>I am an internal toot!</p>",
"favourited": false,
"bookmarked": true,
"reblogged": false,
"account": {
"id": "this is another id",
"username": "username456",
"acct": "username456",
"display_name": "user456 display name",
"locked": false,
"bot": true,
"avatar": "avatar-url-2",
"header": "header-url-2",
},
},
};

testWidgets(
'Status is created properly from Json',
'Status is created properly from Json (not a reblog)',
(WidgetTester tester) async {
Map<String, dynamic> data = {
"id": "11223344",
"content": "<p>I am a toot!</p>",
"favourited": true,
"bookmarked": false,
"reblogged": true,
"account": {
"id": "this is an id",
"username": "username123",
"acct": "username123",
"display_name": "user display name",
"locked": false,
"bot": true,
"avatar": "avatar-url",
"header": "header-url",
},
};

final status = Status.fromJson(data);
final status = Status.fromJson(testStatusNoReblog);

expect(status.id, equals("11223344"));
expect(status.content, equals("<p>I am a toot!</p>"));
expect(status.favorited, isTrue);
Expand All @@ -40,4 +77,56 @@ void main() {
expect(status.reblog, isNull);
},
);

testWidgets(
'Status is created properly from Json (is a reblog)',
(WidgetTester tester) async {
final status = Status.fromJson(testStatusWithReblog);
expect(status.id, equals("11223344"));
expect(status.content, equals("<p>I am a toot!</p>"));
expect(status.favorited, isTrue);
expect(status.bookmarked, isFalse);
expect(status.reblogged, isTrue);
expect(status.account.id, equals("this is an id"));
expect(status.account.username, equals("username123"));
expect(status.account.displayName, equals("user display name"));
expect(status.account.isLocked, isFalse);
expect(status.account.isBot, isTrue);
expect(status.account.avatarUrl, equals("avatar-url"));
expect(status.account.headerUrl, equals("header-url"));
expect(status.reblog, isNotNull);

final reblog = status.reblog!;
expect(reblog.id, equals("55667788"));
expect(reblog.content, equals("<p>I am an internal toot!</p>"));
expect(reblog.favorited, isFalse);
expect(reblog.bookmarked, isTrue);
expect(reblog.reblogged, isFalse);
expect(reblog.account.id, equals("this is another id"));
expect(reblog.account.username, equals("username456"));
expect(reblog.account.displayName, equals("user456 display name"));
expect(reblog.account.isLocked, isFalse);
expect(reblog.account.isBot, isTrue);
expect(reblog.account.avatarUrl, equals("avatar-url-2"));
expect(reblog.account.headerUrl, equals("header-url-2"));
},
);

testWidgets(
'Status.getContent returns the expected content (internal if reblog)',
(WidgetTester tester) async {
final status_1 = Status.fromJson(testStatusNoReblog);
expect(status_1.content, equals("<p>I am a toot!</p>"));
expect(status_1.reblog, isNull);
expect(status_1.getContent(), equals("<p>I am a toot!</p>"));

final status_2 = Status.fromJson(testStatusWithReblog);
expect(status_2.content, equals("<p>I am a toot!</p>"));
expect(status_2.reblog, isNotNull);
expect(status_2.reblog!.content, equals("<p>I am an internal toot!</p>"));
expect(status_2.reblog!.account.acct, equals("username456"));
expect(status_2.getContent(),
equals("Reblogged from username456: <p>I am an internal toot!</p>"));
},
);
}
13 changes: 13 additions & 0 deletions test/screens_test/about_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:feathr/screens/about.dart';
import 'package:package_info_plus/package_info_plus.dart';

void main() {
testWidgets('About screen is rendered properly', (WidgetTester tester) async {
// Mocking the package info
PackageInfo.setMockInitialValues(
appName: 'feathr',
packageName: 'space.feathr.app',
version: '1.2.3',
buildNumber: '1',
buildSignature: 'testbuild',
);

await tester.pumpWidget(const MaterialApp(home: About()));

expect(find.byType(About), findsOneWidget);
Expand All @@ -16,5 +26,8 @@ void main() {
find.textContaining('GNU Affero General Public License'),
findsOneWidget,
);

await tester.pumpAndSettle(const Duration(milliseconds: 200));
expect(find.text('Version 1.2.3 (build: 1)'), findsOneWidget);
});
}

0 comments on commit cf5209a

Please sign in to comment.