37 lines
1.4 KiB
Dart
37 lines
1.4 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
|||
|
|
import 'package:flutter_test/flutter_test.dart';
|
|||
|
|
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
|||
|
|
|
|||
|
|
void main() {
|
|||
|
|
testWidgets(
|
|||
|
|
'旧提示的自动消失定时器不能误杀后弹出的新提示',
|
|||
|
|
(tester) async {
|
|||
|
|
await tester.pumpWidget(
|
|||
|
|
const MaterialApp(home: Scaffold(body: Text('page'))),
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
// 第一条:显示 2 秒
|
|||
|
|
CapsuleToast.show('A-第一条', duration: const Duration(seconds: 2));
|
|||
|
|
await tester.pumpAndSettle(); // postFrame 插入 + Overlay 重建
|
|||
|
|
expect(find.text('A-第一条'), findsOne);
|
|||
|
|
|
|||
|
|
// 1 秒后第二条插入(模拟用户连点触发的新 toast)
|
|||
|
|
await tester.pump(const Duration(seconds: 1));
|
|||
|
|
CapsuleToast.show('B-第二条', duration: const Duration(seconds: 2));
|
|||
|
|
await tester.pumpAndSettle();
|
|||
|
|
expect(find.text('B-第二条'), findsOne);
|
|||
|
|
expect(find.text('A-第一条'), findsNothing);
|
|||
|
|
|
|||
|
|
// 到点:第一条的 2 秒定时器到期,第二条只应已显示 1 秒,不能被移除
|
|||
|
|
await tester.pump(const Duration(seconds: 1));
|
|||
|
|
await tester.pumpAndSettle();
|
|||
|
|
expect(find.text('B-第二条'), findsOne);
|
|||
|
|
|
|||
|
|
// 第二条自己的 2 秒到点后才消失
|
|||
|
|
await tester.pump(const Duration(milliseconds: 1100));
|
|||
|
|
await tester.pumpAndSettle();
|
|||
|
|
expect(find.text('B-第二条'), findsNothing);
|
|||
|
|
},
|
|||
|
|
);
|
|||
|
|
}
|