frindlymap/test/widget_test.dart

98 lines
4.7 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:friendly_map/modules/app/app.dart';
import 'package:friendly_map/modules/transport/transport.dart';
import 'package:friendly_map/modules/ui/src/screens/person_screen.dart';
import 'package:friendly_map/modules/ui/ui.dart';
import 'support/app_device.dart';
/// 키·저장소를 어떻게 여는지는 화면이 모른다. 시험에서는 메모리 기기로 대신한다.
class FakeBootstrap implements Bootstrap {
FakeBootstrap({this.keys = false, this.app});
bool keys;
final FriendlyApp? app;
@override
Future<bool> hasKeys() async => keys;
@override
Future<String> createKeys() async {
keys = true;
return 'one two three four five six seven eight nine ten eleven twelve';
}
@override
Future<bool> restoreKeys(String phrase) async => false;
@override
Future<List<String>> splitRecovery(int n, int k) async => [for (var i = 1; i <= n; i++) 'fmr1.$k.0000.$i:00'];
@override
Future<FriendlyApp> openApp() async => app!;
@override
Future<String?> recoveryPhrase() async => null;
}
void main() {
testWidgets('키가 없으면 처음 화면이 보인다', (tester) async {
await tester.pumpWidget(FriendlyMapApp(bootstrap: FakeBootstrap()));
await tester.pumpAndSettle();
expect(find.text('새로 시작하기'), findsOneWidget);
});
testWidgets('내 정보가 있으면 홈과 아래 메뉴가 보이고 칸을 옮길 수 있다', (tester) async {
final device = await tester.runAsync(() => AppDevice.create(MemoryHub(), '010-1111-2222', '+821011112222', '이미영', start: false));
await tester.pumpWidget(FriendlyMapApp(bootstrap: FakeBootstrap(keys: true, app: device!.app)));
await tester.pumpAndSettle();
expect(find.byType(NavigationBar), findsOneWidget);
await tester.tap(find.descendant(of: find.byType(NavigationBar), matching: find.text('명함')));
await tester.pumpAndSettle();
expect(find.text('내 명함'), findsWidgets);
});
testWidgets('설정에서 그룹 관리를 열면 처음 그룹 네 개가 보이고, 새 그룹을 더하고, 학교 안에 하위 그룹이 보인다', (tester) async {
final device = await tester.runAsync(() => AppDevice.create(MemoryHub(), '010-1111-2222', '+821011112222', '이미영', start: false));
await tester.pumpWidget(FriendlyMapApp(bootstrap: FakeBootstrap(keys: true, app: device!.app)));
await tester.pumpAndSettle();
await tester.tap(find.descendant(of: find.byType(NavigationBar), matching: find.text('내 정보')));
await tester.pumpAndSettle();
await tester.tap(find.text('저장·보안'));
await tester.pumpAndSettle();
await tester.scrollUntilVisible(find.text('그룹 관리'), 200, scrollable: find.byType(Scrollable).last);
await tester.tap(find.text('그룹 관리'));
await tester.pumpAndSettle();
for (final n in ['가족', '학교', '회사', '그룹·여행']) {
expect(find.text(n), findsOneWidget);
}
await tester.tap(find.byTooltip('새 그룹'));
await tester.pumpAndSettle();
await tester.enterText(find.byType(TextField), '등산 모임');
await tester.tap(find.text('확인'));
await tester.runAsync(() => Future<void>.delayed(const Duration(milliseconds: 50)));
await tester.pumpAndSettle();
expect(find.text('등산 모임'), findsOneWidget);
await tester.tap(find.text('학교'));
await tester.pumpAndSettle();
expect(find.text('고등학교'), findsOneWidget);
expect(find.text('대학원'), findsOneWidget);
});
testWidgets('사람 화면의 관계 정하기로 학교 › 고등학교에 넣으면 들어간 그룹이 보인다', (tester) async {
final device = await tester.runAsync(() => AppDevice.create(MemoryHub(), '010-1111-2222', '+821011112222', '이미영', start: false));
final app = device!.app;
final friend = await tester.runAsync(() => app.friends.add('+821033334444', '김민수'));
await tester.pumpWidget(FriendlyMapApp(bootstrap: FakeBootstrap(keys: true, app: app)));
await tester.pumpAndSettle();
tester.state<NavigatorState>(find.byType(Navigator).first).push(MaterialPageRoute<void>(builder: (_) => PersonScreen(personId: friend!.id)));
await tester.pumpAndSettle();
expect(find.textContaining('관계 정하기 —'), findsOneWidget);
await tester.tap(find.byTooltip('관계 정하기'));
await tester.pumpAndSettle();
await tester.tap(find.textContaining('학교 동문'));
await tester.pumpAndSettle();
await tester.tap(find.text('고등학교'));
await tester.runAsync(() => Future<void>.delayed(const Duration(milliseconds: 50)));
await tester.pumpAndSettle();
expect(find.text('학교 › 고등학교'), findsOneWidget);
});
}