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 open(WidgetTester tester) async { final key = GlobalKey(); await tester.pumpWidget(MaterialApp(scaffoldMessengerKey: key, home: const Scaffold(body: SizedBox()))); messenger = key.currentState!; } testWidgets('단추가 있어도 timed 는 noticeDuration 뒤 저절로 닫힘 (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(noticeDuration - 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(noticeDuration, const Duration(seconds: 10)); }); 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); }); }