83 lines
4.1 KiB
Dart
83 lines
4.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:jj_mkvmaker/ui/notice.dart';
|
|
|
|
/// E4 U2 약속 시험 (모듈 하나에 한 장): lib/ui/notice.dart 맨 위 약속을 그대로 본다.
|
|
void main() {
|
|
late ScaffoldMessengerState messenger;
|
|
Future<void> open(WidgetTester tester) async {
|
|
final key = GlobalKey<ScaffoldMessengerState>();
|
|
await tester.pumpWidget(MaterialApp(scaffoldMessengerKey: key, home: const Scaffold(body: SizedBox())));
|
|
messenger = key.currentState!;
|
|
}
|
|
|
|
testWidgets('단추가 있어도 timed 는 appNoticeDuration 뒤 저절로 닫힘 (U2) · 앱 전체 한 값', (tester) async {
|
|
await open(tester);
|
|
var pressed = 0;
|
|
showNotice(messenger, text: '복사했습니다', action: ('폴더 열기', () => pressed++));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('복사했습니다'), findsOneWidget);
|
|
expect(find.byIcon(Icons.close), findsOneWidget, reason: '✕ 로 바로 닫기');
|
|
await tester.pump(appNoticeDuration - const Duration(seconds: 1));
|
|
expect(find.text('복사했습니다'), findsOneWidget, reason: '정해진 시간 전에는 남음');
|
|
await tester.pump(const Duration(seconds: 2));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('복사했습니다'), findsNothing);
|
|
expect(pressed, 0);
|
|
expect(appNoticeDuration, const Duration(seconds: 10), reason: '앱의 값 (U2) - 시험이 정하지 않으면 이것');
|
|
});
|
|
|
|
testWidgets('단추를 누르면 그 일을 하고 닫힘', (tester) async {
|
|
await open(tester);
|
|
var pressed = 0;
|
|
showNotice(messenger, text: '지웠습니다', action: ('되돌리기', () => pressed++));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('되돌리기'));
|
|
await tester.pumpAndSettle();
|
|
expect(pressed, 1);
|
|
expect(find.text('지웠습니다'), findsNothing);
|
|
});
|
|
|
|
testWidgets('untilClosed 는 오래 지나도 남고 ✕ · 부르는 쪽이 닫음', (tester) async {
|
|
await open(tester);
|
|
showNotice(messenger, life: NoticeLife.untilClosed, content: const Text('DNS 안내'), action: ('바꾸기', () {}));
|
|
await tester.pumpAndSettle();
|
|
await tester.pump(const Duration(minutes: 30));
|
|
expect(find.text('DNS 안내'), findsOneWidget);
|
|
await tester.tap(find.byIcon(Icons.close));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('DNS 안내'), findsNothing);
|
|
final bar = showNotice(messenger, life: NoticeLife.untilClosed, text: '준비 중');
|
|
await tester.pumpAndSettle();
|
|
bar!.close();
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('준비 중'), findsNothing);
|
|
});
|
|
|
|
testWidgets('clearOthers 는 앞 알림을 치우고 바로 보임 · messenger 가 없으면 null', (tester) async {
|
|
await open(tester);
|
|
showNotice(messenger, life: NoticeLife.untilClosed, text: '앞 알림');
|
|
await tester.pumpAndSettle();
|
|
showNotice(messenger, text: '되돌리기 알림', clearOthers: true, action: ('실행 취소', () {}));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('앞 알림'), findsNothing);
|
|
expect(find.text('되돌리기 알림'), findsOneWidget);
|
|
expect(showNotice(null, text: 'x'), isNull);
|
|
});
|
|
|
|
testWidgets('NoticeTiming: 감싼 화면의 timed 알림은 그 시간 뒤 닫힘 (없으면 appNoticeDuration)', (tester) async {
|
|
final key = GlobalKey<ScaffoldMessengerState>();
|
|
await tester.pumpWidget(NoticeTiming(
|
|
duration: const Duration(seconds: 30),
|
|
child: MaterialApp(scaffoldMessengerKey: key, home: const Scaffold(body: SizedBox()))));
|
|
showNotice(key.currentState, text: '오래 남음', action: ('보기', () {}));
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 500)); // 들어오는 움직임이 끝난 뒤부터 센다
|
|
await tester.pump(appNoticeDuration + const Duration(seconds: 5));
|
|
expect(find.text('오래 남음'), findsOneWidget, reason: '10초가 지나도 정한 30초 전에는 남음');
|
|
await tester.pump(const Duration(seconds: 20));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('오래 남음'), findsNothing);
|
|
});
|
|
}
|