Skip to content

Commit

Permalink
test(neon_rich_text): Separate all tests into multiple files
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Dec 7, 2024
1 parent 2afcde8 commit 0a3aa4c
Show file tree
Hide file tree
Showing 15 changed files with 739 additions and 634 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:neon_framework/models.dart';
import 'package:neon_framework/testing.dart';
import 'package:neon_rich_text/neon_rich_text.dart';
import 'package:nextcloud/core.dart' as core;
import 'package:provider/provider.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';

void main() {
late MockUrlLauncher urlLauncher;
late Account account;

setUpAll(() {
FakeNeonStorage.setup();

registerFallbackValue(const LaunchOptions());

urlLauncher = MockUrlLauncher();
// ignore: discarded_futures
when(() => urlLauncher.launchUrl(any(), any())).thenAnswer((_) async => true);

UrlLauncherPlatform.instance = urlLauncher;
});

setUp(() {
account = MockAccount();
});

testWidgets('Deck card', (tester) async {
await tester.pumpWidgetWithAccessibility(
TestApp(
providers: [
Provider<Account>.value(value: account),
],
child: NeonRichObjectDeckCard(
parameter: core.RichObjectParameter(
(b) => b
..type = core.RichObjectParameter_Type.deckCard
..id = ''
..name = 'name'
..boardname = 'boardname'
..stackname = 'stackname'
..link = '/link',
),
),
),
);
expect(find.text('name'), findsOne);
expect(find.text('boardname: stackname'), findsOne);
await expectLater(
find.byType(NeonRichObjectDeckCard),
matchesGoldenFile('goldens/rich_text_object_deck_card.png'),
);

await tester.tap(find.byType(NeonRichObjectDeckCard));
verify(() => urlLauncher.launchUrl('https://cloud.example.com:8443/link', any())).called(1);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:neon_framework/models.dart';
import 'package:neon_framework/testing.dart';
import 'package:neon_framework/widgets.dart';
import 'package:neon_rich_text/neon_rich_text.dart';
import 'package:nextcloud/core.dart' as core;
import 'package:provider/provider.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';

void main() {
late MockUrlLauncher urlLauncher;
late Account account;

setUpAll(() {
FakeNeonStorage.setup();

registerFallbackValue(const LaunchOptions());

urlLauncher = MockUrlLauncher();
// ignore: discarded_futures
when(() => urlLauncher.launchUrl(any(), any())).thenAnswer((_) async => true);

UrlLauncherPlatform.instance = urlLauncher;
});

setUp(() {
account = MockAccount();
});

group('Fallback', () {
testWidgets('Opens link', (tester) async {
await tester.pumpWidgetWithAccessibility(
TestApp(
providers: [
Provider<Account>.value(value: account),
],
child: NeonRichObjectFallback(
parameter: core.RichObjectParameter(
(b) => b
..type = core.RichObjectParameter_Type.calendarEvent
..id = ''
..name = 'name'
..link = '/link',
),
textStyle: null,
),
),
);

await tester.tap(find.byType(NeonRichObjectFallback));
verify(() => urlLauncher.launchUrl('https://cloud.example.com:8443/link', any())).called(1);
});

testWidgets('Without icon', (tester) async {
await tester.pumpWidgetWithAccessibility(
TestApp(
child: NeonRichObjectFallback(
parameter: core.RichObjectParameter(
(b) => b
..type = core.RichObjectParameter_Type.addressbook
..id = ''
..name = 'name',
),
textStyle: null,
),
),
);
expect(find.byType(NeonUriImage), findsNothing);
expect(find.text('name'), findsOne);
await expectLater(
find.byType(NeonRichObjectFallback),
matchesGoldenFile('goldens/rich_text_object_fallback_without_icon.png'),
);
});

testWidgets('With icon', (tester) async {
await tester.pumpWidgetWithAccessibility(
TestApp(
providers: [
Provider<Account>.value(value: account),
],
child: NeonRichObjectFallback(
parameter: core.RichObjectParameter(
(b) => b
..type = core.RichObjectParameter_Type.addressbook
..id = ''
..name = 'name'
..iconUrl = '',
),
textStyle: null,
),
),
);
expect(find.byType(NeonUriImage), findsOne);
expect(find.text('name'), findsOne);
await expectLater(
find.byType(NeonRichObjectFallback),
matchesGoldenFile('goldens/rich_text_object_fallback_with_icon.png'),
);
});
});
}
Loading

0 comments on commit 0a3aa4c

Please sign in to comment.