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

Migrating qr_code_scanner to mobile_scanner in talawa mobile #2717

Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
migration complete
- successfully migrated to mobile_scanner
- app building on android 14(api 34)
- updated old tests
MukalDadhwal committed Jan 24, 2025
commit cfd7f5d781d99e0570e0081a580982f411548251
16 changes: 12 additions & 4 deletions lib/splash_screen.dart
Original file line number Diff line number Diff line change
@@ -12,12 +12,18 @@ import 'package:talawa/utils/app_localization.dart';

/// This widget return the SplashScreen. Splash Screen is the first screen that we see when we run our application. It is also known as Launch Screen.
class SplashScreen extends StatefulWidget {
const SplashScreen({required Key key, this.mainScreenIndex = 0})
: super(key: key);
const SplashScreen({
required Key key,
this.mainScreenIndex = 0,
this.isTesting = false,
}) : super(key: key);

/// This is required if url requires us to push different Screen to Home Screen.
final int mainScreenIndex;

/// for testing purpose.
final bool isTesting;

@override
_SplashScreenState createState() => _SplashScreenState();
}
@@ -206,6 +212,8 @@ class _SplashScreenState extends State<SplashScreen> {
/// **returns**:
/// None
void _handleUserLogIn(bool userLoggedIn) {
print(widget.isTesting);
if (widget.isTesting) return;
Future.delayed(const Duration(milliseconds: 750)).then((value) async {
final pushReplacementScreen = navigationService.pushReplacementScreen;
if (!userLoggedIn) {
@@ -239,9 +247,9 @@ class _SplashScreenState extends State<SplashScreen> {
}

@override
void dispose() {
_sub.cancel();
Future<void> dispose() async {
super.dispose();
await _sub.cancel();
}

@override
368 changes: 188 additions & 180 deletions pubspec.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ dependencies:
graphql_flutter: ^5.1.2
hive: ^2.2.3
http: ^1.2.2
image_cropper: 8.0.0
image_cropper: 8.0.2
image_picker: ^1.1.2
intl: ^0.19.0
json_annotation: ^4.7.0
340 changes: 163 additions & 177 deletions test/widget_tests/pre_auth_screens/splash_screen_test.dart
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@

// ignore_for_file: unused_import

import 'dart:async';

import 'package:app_links/app_links.dart';
import 'package:fake_async/fake_async.dart';
import 'package:flutter/material.dart';
@@ -46,6 +48,7 @@ Widget _createSplashScreen({
darkTheme: darkTheme,
home: const SplashScreen(
key: Key('SplashScreen'),
isTesting: true,
),
navigatorKey: navigationService.navigatorKey,
onGenerateRoute: router.generateRoute,
@@ -65,7 +68,7 @@ Widget createSplashScreenDark({ThemeMode themeMode = ThemeMode.dark}) =>
darkTheme: TalawaTheme.darkTheme,
);

Future<void> main() async {
void main() {
// Disable stack trace demangling for non-standard environments (e.g., CI)
// This ensures consistent stack traces across different environments and
// makes test failures more debuggable in CI pipelines
@@ -78,10 +81,14 @@ Future<void> main() async {
late MockAppLinks mockAppLinks;
late MockUserConfig mockUserConfig;

// late StreamController<Uri> uriStreamController;

setUp(() {
mockAppLinks = MockAppLinks();
mockUserConfig = MockUserConfig();

// uriStreamController = StreamController<Uri>();

// Unregister and re-register AppLinks for each test
if (locator.isRegistered<AppLinks>()) {
locator.unregister<AppLinks>();
@@ -119,192 +126,174 @@ Future<void> main() async {

group('Splash Screen Widget Test in light mode', () {
testWidgets("Testing if Splash Screen shows up", (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(createSplashScreenLight());
await tester.pumpAndSettle();
final screenScaffoldWidget =
find.byKey(const Key('SplashScreenScaffold'));
expect(screenScaffoldWidget, findsOneWidget);
expect(
(tester.firstWidget(find.byKey(const Key('Root'))) as MaterialApp)
.theme!
.scaffoldBackgroundColor,
TalawaTheme.lightTheme.scaffoldBackgroundColor,
);
});
await tester.pumpWidget(createSplashScreenLight());

await tester.pumpAndSettle();
final screenScaffoldWidget =
find.byKey(const Key("SplashScreenScaffold"));

expect(screenScaffoldWidget, findsOneWidget);
expect(
(tester.firstWidget(find.byKey(const Key('Root'))) as MaterialApp)
.theme!
.scaffoldBackgroundColor,
TalawaTheme.lightTheme.scaffoldBackgroundColor,
);
});
testWidgets("Testing if app logo shows up", (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(createSplashScreenLight());
await tester.pumpAndSettle();
final logoWidget = find.byKey(const Key('LogoPainter'));
expect(logoWidget, findsOneWidget);
expect(
(tester.firstWidget(logoWidget) as CustomPaint).size,
Size(
SizeConfig.screenWidth! * 0.6,
SizeConfig.screenWidth! * 0.6,
),
);
});
await tester.pumpWidget(createSplashScreenLight());
await tester.pumpAndSettle();
final logoWidget = find.byKey(const Key('LogoPainter'));

expect(logoWidget, findsOneWidget);
expect(
(tester.firstWidget(logoWidget) as CustomPaint).size,
Size(
SizeConfig.screenWidth! * 0.6,
SizeConfig.screenWidth! * 0.6,
),
);
});
testWidgets("Testing if app name shows up", (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(createSplashScreenLight());
await tester.pumpAndSettle();
final findAppNameWidget = find.text('TALAWA');
expect(findAppNameWidget, findsOneWidget);
expect(
(tester.firstWidget(findAppNameWidget) as Text).style!.color,
TalawaTheme.lightTheme.textTheme.headlineMedium!.color,
);
expect(
(tester.firstWidget(findAppNameWidget) as Text).style!.fontFamily,
TalawaTheme.lightTheme.textTheme.headlineMedium!.fontFamily,
);
expect(
(tester.firstWidget(findAppNameWidget) as Text).style!.fontSize,
TalawaTheme.lightTheme.textTheme.headlineMedium!.fontSize,
);
});
await tester.pumpWidget(createSplashScreenLight());
await tester.pumpAndSettle();
final findAppNameWidget = find.text('TALAWA');

expect(findAppNameWidget, findsOneWidget);
expect(
(tester.firstWidget(findAppNameWidget) as Text).style!.color,
TalawaTheme.lightTheme.textTheme.headlineMedium!.color,
);
expect(
(tester.firstWidget(findAppNameWidget) as Text).style!.fontFamily,
TalawaTheme.lightTheme.textTheme.headlineMedium!.fontFamily,
);
expect(
(tester.firstWidget(findAppNameWidget) as Text).style!.fontSize,
TalawaTheme.lightTheme.textTheme.headlineMedium!.fontSize,
);
});
testWidgets("Testing if provider text shows up", (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(createSplashScreenLight());
await tester.pumpAndSettle();
final findProviderTextWidget = find.text('from');
expect(findProviderTextWidget, findsOneWidget);
expect(
(tester.firstWidget(findProviderTextWidget) as Text).style!.color,
TalawaTheme.lightTheme.textTheme.bodySmall!.color,
);
expect(
(tester.firstWidget(findProviderTextWidget) as Text)
.style!
.fontFamily,
TalawaTheme.lightTheme.textTheme.bodySmall!.fontFamily,
);
expect(
(tester.firstWidget(findProviderTextWidget) as Text).style!.fontSize,
TalawaTheme.lightTheme.textTheme.bodySmall!.fontSize,
);
});
await tester.pumpWidget(createSplashScreenLight());
await tester.pumpAndSettle();
final findProviderTextWidget = find.text('from');

expect(findProviderTextWidget, findsOneWidget);
expect(
(tester.firstWidget(findProviderTextWidget) as Text).style!.color,
TalawaTheme.lightTheme.textTheme.bodySmall!.color,
);
expect(
(tester.firstWidget(findProviderTextWidget) as Text).style!.fontFamily,
TalawaTheme.lightTheme.textTheme.bodySmall!.fontFamily,
);
expect(
(tester.firstWidget(findProviderTextWidget) as Text).style!.fontSize,
TalawaTheme.lightTheme.textTheme.bodySmall!.fontSize,
);
});
testWidgets("Testing if provider name shows up", (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(createSplashScreenLight());
await tester.pumpAndSettle();
final findProviderNameWidget = find.text('PALISADOES');
expect(findProviderNameWidget, findsOneWidget);
expect(
(tester.firstWidget(findProviderNameWidget) as Text).style!.color,
TalawaTheme.lightTheme.textTheme.titleSmall!.color,
);
expect(
(tester.firstWidget(findProviderNameWidget) as Text)
.style!
.fontFamily,
TalawaTheme.lightTheme.textTheme.titleSmall!.fontFamily,
);
});
await tester.pumpWidget(createSplashScreenLight());
await tester.pumpAndSettle();
final findProviderNameWidget = find.text('PALISADOES');

expectLater(findProviderNameWidget, findsOneWidget);
expect(
(tester.firstWidget(findProviderNameWidget) as Text).style!.color,
TalawaTheme.lightTheme.textTheme.titleSmall!.color,
);
expect(
(tester.firstWidget(findProviderNameWidget) as Text).style!.fontFamily,
TalawaTheme.lightTheme.textTheme.titleSmall!.fontFamily,
);
});
});
group('Splash Screen Widget Test in dark mode', () {
testWidgets("Testing if Splash Screen shows up", (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(createSplashScreenDark());
await tester.pumpAndSettle();
final screenScaffoldWidget =
find.byKey(const Key('SplashScreenScaffold'));
expect(screenScaffoldWidget, findsOneWidget);
expect(
(tester.firstWidget(find.byKey(const Key('Root'))) as MaterialApp)
.darkTheme!
.scaffoldBackgroundColor,
TalawaTheme.darkTheme.scaffoldBackgroundColor,
);
});
await tester.pumpWidget(createSplashScreenDark());
await tester.pumpAndSettle();
final screenScaffoldWidget =
find.byKey(const Key('SplashScreenScaffold'));

expect(screenScaffoldWidget, findsOneWidget);
expect(
(tester.firstWidget(find.byKey(const Key('Root'))) as MaterialApp)
.darkTheme!
.scaffoldBackgroundColor,
TalawaTheme.darkTheme.scaffoldBackgroundColor,
);
});
testWidgets("Testing if app logo shows up", (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(createSplashScreenDark());
await tester.pumpAndSettle();
final logoWidget = find.byKey(const Key('LogoPainter'));
expect(logoWidget, findsOneWidget);
expect(
(tester.firstWidget(logoWidget) as CustomPaint).size,
Size(
SizeConfig.screenWidth! * 0.6,
SizeConfig.screenWidth! * 0.6,
),
);
});
await tester.pumpWidget(createSplashScreenDark());
await tester.pumpAndSettle();
final logoWidget = find.byKey(const Key('LogoPainter'));

expect(logoWidget, findsOneWidget);
expect(
(tester.firstWidget(logoWidget) as CustomPaint).size,
Size(
SizeConfig.screenWidth! * 0.6,
SizeConfig.screenWidth! * 0.6,
),
);
});
testWidgets("Testing if app name shows up", (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(createSplashScreenDark());
await tester.pumpAndSettle();
final findAppNameWidget = find.text('TALAWA');
expect(findAppNameWidget, findsOneWidget);
expect(
(tester.firstWidget(findAppNameWidget) as Text).style!.color,
TalawaTheme.darkTheme.textTheme.headlineMedium!.color,
);
expect(
(tester.firstWidget(findAppNameWidget) as Text).style!.fontFamily,
TalawaTheme.darkTheme.textTheme.headlineMedium!.fontFamily,
);
expect(
(tester.firstWidget(findAppNameWidget) as Text).style!.fontSize,
TalawaTheme.darkTheme.textTheme.headlineMedium!.fontSize,
);
});
await tester.pumpWidget(createSplashScreenDark());
await tester.pumpAndSettle();
final findAppNameWidget = find.text('TALAWA');

expect(findAppNameWidget, findsOneWidget);
expect(
(tester.firstWidget(findAppNameWidget) as Text).style!.color,
TalawaTheme.darkTheme.textTheme.headlineMedium!.color,
);
expect(
(tester.firstWidget(findAppNameWidget) as Text).style!.fontFamily,
TalawaTheme.darkTheme.textTheme.headlineMedium!.fontFamily,
);
expect(
(tester.firstWidget(findAppNameWidget) as Text).style!.fontSize,
TalawaTheme.darkTheme.textTheme.headlineMedium!.fontSize,
);
});
testWidgets("Testing if provider text shows up", (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(createSplashScreenDark());
await tester.pumpAndSettle();
final findProviderTextWidget = find.text('from');
expect(findProviderTextWidget, findsOneWidget);
expect(
(tester.firstWidget(findProviderTextWidget) as Text).style!.color,
TalawaTheme.darkTheme.textTheme.bodySmall!.color,
);
expect(
(tester.firstWidget(findProviderTextWidget) as Text)
.style!
.fontFamily,
TalawaTheme.darkTheme.textTheme.bodySmall!.fontFamily,
);
expect(
(tester.firstWidget(findProviderTextWidget) as Text).style!.fontSize,
TalawaTheme.darkTheme.textTheme.bodySmall!.fontSize,
);
});
await tester.pumpWidget(createSplashScreenDark());
await tester.pumpAndSettle();
final findProviderTextWidget = find.text('from');

expect(findProviderTextWidget, findsOneWidget);
expect(
(tester.firstWidget(findProviderTextWidget) as Text).style!.color,
TalawaTheme.darkTheme.textTheme.bodySmall!.color,
);
expect(
(tester.firstWidget(findProviderTextWidget) as Text).style!.fontFamily,
TalawaTheme.darkTheme.textTheme.bodySmall!.fontFamily,
);
expect(
(tester.firstWidget(findProviderTextWidget) as Text).style!.fontSize,
TalawaTheme.darkTheme.textTheme.bodySmall!.fontSize,
);
});
testWidgets("Testing if provider name shows up", (tester) async {
await tester.runAsync(() async {
await tester.pumpWidget(createSplashScreenDark());
await tester.pumpAndSettle();
final findProviderNameWidget = find.text('PALISADOES');
expect(findProviderNameWidget, findsOneWidget);
expect(
(tester.firstWidget(findProviderNameWidget) as Text).style!.color,
TalawaTheme.darkTheme.textTheme.titleSmall!.color,
);
expect(
(tester.firstWidget(findProviderNameWidget) as Text)
.style!
.fontFamily,
TalawaTheme.darkTheme.textTheme.titleSmall!.fontFamily,
);
await tester.pumpWidget(createSplashScreenDark());
await tester.pumpAndSettle();
final findProviderNameWidget = find.text('PALISADOES');

expect(findProviderNameWidget, findsOneWidget);
expect(
(tester.firstWidget(findProviderNameWidget) as Text).style!.color,
TalawaTheme.darkTheme.textTheme.titleSmall!.color,
);
expect(
(tester.firstWidget(findProviderNameWidget) as Text).style!.fontFamily,
TalawaTheme.darkTheme.textTheme.titleSmall!.fontFamily,
);
});
});
});

group("URI Link Handling Tests", () {
testWidgets("should handle initial URI successfully", (tester) async {
await tester.runAsync(() async {
// Arrange
final uri = Uri.parse('talawa://example.com');
when(mockAppLinks.getInitialLink()).thenAnswer((_) async => uri);
@@ -317,10 +306,9 @@ Future<void> main() async {
// Assert
verify(mockAppLinks.getInitialLink()).called(1);
expect(find.byKey(const Key('SplashScreenScaffold')), findsOneWidget);
});
});
testWidgets('should handle URI stream updates', (tester) async {
await tester.runAsync(() async {
// await tester.runAsync(() async {
// Arrange
final uri = Uri.parse('talawa://example.com');
when(mockAppLinks.uriLinkStream).thenAnswer((_) => Stream.value(uri));
@@ -332,44 +320,42 @@ Future<void> main() async {

// Assert
verify(mockAppLinks.uriLinkStream).called(1);
});
// });
});
testWidgets("should handle PlatformException when getting initial URI",
(tester) async {
await tester.runAsync(() async {
// await tester.runAsync(() async {
// Arrange
when(mockAppLinks.getInitialLink())
.thenThrow(PlatformException(code: 'TEST_ERROR'));
when(mockAppLinks.uriLinkStream)
.thenAnswer((_) => const Stream.empty());
when(mockAppLinks.uriLinkStream).thenAnswer((_) => const Stream.empty());

// Act
await tester.pumpWidget(createSplashScreenLight());
await tester.pumpAndSettle();

// Assert
verify(mockAppLinks.getInitialLink()).called(1);
});
// });
});
testWidgets("should handle FormatException when getting initial URI",
(tester) async {
await tester.runAsync(() async {
// await tester.runAsync(() async {
// Arrange
when(mockAppLinks.getInitialLink())
.thenThrow(const FormatException('Invalid URI format'));
when(mockAppLinks.uriLinkStream)
.thenAnswer((_) => const Stream.empty());
when(mockAppLinks.uriLinkStream).thenAnswer((_) => const Stream.empty());

// Act
await tester.pumpWidget(createSplashScreenLight());
await tester.pumpAndSettle();

// Assert
verify(mockAppLinks.getInitialLink()).called(1);
});
// });
});
testWidgets('should handle URI stream errors', (tester) async {
await tester.runAsync(() async {
// await tester.runAsync(() async {
// Arrange
when(mockAppLinks.uriLinkStream)
.thenAnswer((_) => Stream.error('Test error'));
@@ -381,11 +367,11 @@ Future<void> main() async {

// Assert
verify(mockAppLinks.uriLinkStream).called(1);
});
// });
});
testWidgets('should cleanup stream subscription on dispose',
(tester) async {
await tester.runAsync(() async {
// await tester.runAsync(() async {
// Arrange
when(mockUserConfig.loggedIn).thenReturn(true);
when(mockAppLinks.uriLinkStream)
@@ -396,7 +382,7 @@ Future<void> main() async {
await tester.pumpWidget(Container()); // Force dispose

// No explicit assert needed - test will fail if subscription isn't properly canceled
});
// });
});
});
}
You are viewing a condensed version of this merge commit. You can view the full changes here.