feat(apps): add router auth protection
This commit is contained in:
@@ -1,10 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:social_app/main.dart';
|
||||
import 'package:social_app/features/auth/presentation/bloc/auth_bloc.dart';
|
||||
import 'package:social_app/features/auth/presentation/bloc/auth_state.dart';
|
||||
|
||||
class MockAuthBloc extends Mock implements AuthBloc {}
|
||||
|
||||
class FakeAuthState extends Fake implements AuthState {}
|
||||
|
||||
void main() {
|
||||
setUpAll(() {
|
||||
registerFallbackValue(FakeAuthState());
|
||||
});
|
||||
|
||||
testWidgets('Login screen loads correctly', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const LinksyApp());
|
||||
final mockAuthBloc = MockAuthBloc();
|
||||
when(() => mockAuthBloc.state).thenReturn(AuthInitial());
|
||||
when(
|
||||
() => mockAuthBloc.stream,
|
||||
).thenAnswer((_) => Stream.value(AuthInitial()));
|
||||
|
||||
await tester.pumpWidget(LinksyApp(authBloc: mockAuthBloc));
|
||||
expect(find.text('linksy'), findsOneWidget);
|
||||
expect(find.text('继续'), findsOneWidget);
|
||||
expect(find.text('还没有账号?去注册'), findsOneWidget);
|
||||
@@ -13,7 +30,13 @@ void main() {
|
||||
testWidgets('Main content is vertically centered above footer', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
await tester.pumpWidget(const LinksyApp());
|
||||
final mockAuthBloc = MockAuthBloc();
|
||||
when(() => mockAuthBloc.state).thenReturn(AuthInitial());
|
||||
when(
|
||||
() => mockAuthBloc.stream,
|
||||
).thenAnswer((_) => Stream.value(AuthInitial()));
|
||||
|
||||
await tester.pumpWidget(LinksyApp(authBloc: mockAuthBloc));
|
||||
|
||||
final safeAreaRect = tester.getRect(find.byType(SafeArea));
|
||||
final mainRect = tester.getRect(
|
||||
|
||||
Reference in New Issue
Block a user