74 lines
2.6 KiB
Dart
74 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:fancake/core/theme/app_theme.dart';
|
|
import 'package:fancake/core/ui/app_dialog.dart';
|
|
|
|
/// 공통 확인 창 — Figma `2066:17799` · `554:24669`: 취소(테두리)·실행(분홍 채움)이
|
|
/// 한 줄에 반씩. 실기기(v0.5.0+7)에서 실행 버튼이 전체 폭 테마 때문에 아래로 밀리고
|
|
/// 취소가 오른쪽 위 글자 버튼으로 남던 배치를 막는다.
|
|
void main() {
|
|
Future<List<Object?>> open(
|
|
WidgetTester tester,
|
|
Future<Object?> Function(BuildContext) show,
|
|
) async {
|
|
final results = <Object?>[];
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: buildAppTheme(),
|
|
home: Builder(
|
|
builder: (context) => TextButton(
|
|
onPressed: () async => results.add(await show(context)),
|
|
child: const Text('open'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.tap(find.text('open'));
|
|
await tester.pumpAndSettle();
|
|
return results;
|
|
}
|
|
|
|
testWidgets('취소 · 실행이 같은 줄에 왼쪽 · 오른쪽 같은 폭으로 놓인다', (tester) async {
|
|
final results = await open(
|
|
tester,
|
|
(c) => showConfirmDialog(c, '기본 행성을 변경할까요?'),
|
|
);
|
|
final cancel = find.widgetWithText(OutlinedButton, '취소');
|
|
final change = find.widgetWithText(FilledButton, '변경');
|
|
expect(cancel, findsOneWidget);
|
|
expect(change, findsOneWidget);
|
|
|
|
final a = tester.getRect(cancel);
|
|
final b = tester.getRect(change);
|
|
expect(a.top, b.top);
|
|
expect(a.height, 48);
|
|
expect(a.width, b.width);
|
|
expect(a.right, lessThan(b.left));
|
|
// 버튼 줄은 문구 아래.
|
|
expect(tester.getRect(find.text('기본 행성을 변경할까요?')).bottom,
|
|
lessThan(a.top));
|
|
|
|
await tester.tap(change);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('open'));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(cancel);
|
|
await tester.pumpAndSettle();
|
|
expect(results, [true, false]);
|
|
});
|
|
|
|
testWidgets('단일 알림은 확인 하나가 카드 폭을 채운다', (tester) async {
|
|
await open(tester, (c) => showAlertDialog(c, '저장했어요'));
|
|
expect(find.byType(OutlinedButton), findsNothing);
|
|
final ok = tester.getRect(find.widgetWithText(FilledButton, '확인'));
|
|
final card = tester.getRect(
|
|
find.descendant(of: find.byType(AppDialog), matching: find.byType(Material)).first,
|
|
);
|
|
expect(ok.width, card.width - 32);
|
|
await tester.tap(find.text('확인'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(AppDialog), findsNothing);
|
|
});
|
|
}
|