Skip to content

Commit

Permalink
write tests for auth logo tile
Browse files Browse the repository at this point in the history
  • Loading branch information
youngbryanyu committed Feb 22, 2024
1 parent 91db62f commit 08b5473
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions frontend/lib/components/auth/auth_logo_tile.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:flutter/material.dart';

/* Logo tile for 3rd party logos like Google and Apple sign in logos */
class LogoTile extends StatelessWidget {
class AuthLogoTile extends StatelessWidget {
final String imagePath;
final Function()? onTap;

const LogoTile({
const AuthLogoTile({
super.key,
required this.imagePath,
required this.onTap,
Expand Down
1 change: 1 addition & 0 deletions frontend/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ flutter:
# To add assets to your application, add an assets section, like this:
assets:
- lib/assets/images/
- test/assets/images/

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
Expand Down
Binary file added frontend/test/assets/images/google-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions frontend/test/components/auth/auth_logo_tile_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:frontend/components/auth/auth_logo_tile.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();

group('LogoTile Tests', () {
testWidgets('Displays an image from the provided imagePath',
(WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: AuthLogoTile(
imagePath: 'test/assets/images/google-logo.png',
onTap: () {},
),
),
));

expect(find.byType(Image), findsOneWidget);
});

testWidgets('Responds to tap events', (WidgetTester tester) async {
bool tapped = false;

await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: AuthLogoTile(
imagePath: 'test/assets/images/google-logo.png',
onTap: () {
tapped = true;
},
),
),
));

await tester.tap(find.byType(AuthLogoTile));
await tester.pump();

expect(tapped, true);
});
});
}

0 comments on commit 08b5473

Please sign in to comment.