전역 구조 리팩터링 및 테스트 확장

This commit is contained in:
JiWoong Sul
2025-09-29 01:51:47 +09:00
parent c00c0c9ab2
commit fef7108479
70 changed files with 7709 additions and 3185 deletions

View File

@@ -0,0 +1,175 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import 'package:superport_v2/core/config/environment.dart';
import 'package:superport_v2/core/constants/app_sections.dart';
import 'package:superport_v2/features/login/presentation/pages/login_page.dart';
import 'package:superport_v2/core/theme/superport_shad_theme.dart';
import 'package:superport_v2/core/permissions/permission_manager.dart';
GoRouter _createTestRouter() {
return GoRouter(
initialLocation: loginRoutePath,
routes: [
GoRoute(
path: loginRoutePath,
builder: (context, state) => const LoginPage(),
),
GoRoute(
path: dashboardRoutePath,
builder: (context, state) => const _TestDashboardPage(),
),
GoRoute(
path: '/inventory/inbound',
builder: (context, state) => const _PlaceholderPage(title: '입고 화면'),
),
GoRoute(
path: '/inventory/outbound',
builder: (context, state) => const _PlaceholderPage(title: '출고 화면'),
),
GoRoute(
path: '/inventory/rental',
builder: (context, state) => const _PlaceholderPage(title: '대여 화면'),
),
],
);
}
class _TestApp extends StatelessWidget {
const _TestApp({required this.router});
final GoRouter router;
@override
Widget build(BuildContext context) {
return PermissionScope(
manager: PermissionManager(),
child: ShadApp.router(
routerConfig: router,
debugShowCheckedModeBanner: false,
theme: SuperportShadTheme.light(),
darkTheme: SuperportShadTheme.dark(),
),
);
}
}
class _TestDashboardPage extends StatelessWidget {
const _TestDashboardPage();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('테스트 대시보드'),
actions: [
IconButton(
tooltip: '로그아웃',
icon: const Icon(Icons.logout),
onPressed: () => context.go(loginRoutePath),
),
],
),
body: Padding(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextButton(
onPressed: () => context.go('/inventory/inbound'),
child: const Text('입고로 이동'),
),
TextButton(
onPressed: () => context.go('/inventory/outbound'),
child: const Text('출고로 이동'),
),
TextButton(
onPressed: () => context.go('/inventory/rental'),
child: const Text('대여로 이동'),
),
],
),
),
);
}
}
class _PlaceholderPage extends StatelessWidget {
const _PlaceholderPage({required this.title});
final String title;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(title)),
body: Center(
child: TextButton(
onPressed: () => context.go(dashboardRoutePath),
child: const Text('대시보드로 돌아가기'),
),
),
);
}
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUpAll(() async {
await Environment.initialize();
});
Finder editableTextAt(int index) => find.byType(EditableText).at(index);
testWidgets('사용자가 로그인 후 주요 화면을 탐색할 수 있다', (tester) async {
final view = tester.view;
view.physicalSize = const Size(1080, 720);
view.devicePixelRatio = 1.0;
addTearDown(() {
view.resetPhysicalSize();
view.resetDevicePixelRatio();
});
final router = _createTestRouter();
await tester.pumpWidget(_TestApp(router: router));
await tester.pumpAndSettle();
expect(find.text('Superport v2 로그인'), findsOneWidget);
await tester.enterText(editableTextAt(0), 'tester');
await tester.enterText(editableTextAt(1), 'password123');
await tester.tap(find.widgetWithText(ShadButton, '로그인'));
await tester.pump(const Duration(milliseconds: 650));
await tester.pumpAndSettle();
expect(find.text('테스트 대시보드'), findsOneWidget);
await tester.tap(find.widgetWithText(TextButton, '입고로 이동'));
await tester.pumpAndSettle();
expect(find.text('입고 화면'), findsOneWidget);
await tester.tap(find.widgetWithText(TextButton, '대시보드로 돌아가기'));
await tester.pumpAndSettle();
expect(find.text('테스트 대시보드'), findsOneWidget);
await tester.tap(find.widgetWithText(TextButton, '출고로 이동'));
await tester.pumpAndSettle();
expect(find.text('출고 화면'), findsOneWidget);
await tester.tap(find.widgetWithText(TextButton, '대시보드로 돌아가기'));
await tester.pumpAndSettle();
await tester.tap(find.widgetWithText(TextButton, '대여로 이동'));
await tester.pumpAndSettle();
expect(find.text('대여 화면'), findsOneWidget);
await tester.tap(find.widgetWithText(TextButton, '대시보드로 돌아가기'));
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('로그아웃'));
await tester.pumpAndSettle();
expect(find.text('Superport v2 로그인'), findsOneWidget);
});
}