JJ_MKVMaker/test/notice_band_contract_test.dart

54 lines
2.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:jj_mkvmaker/ui/notice_band.dart';
/// W 공용 위젯 약속 (NoticeBand): 폭 · 글자 배율 · 언어 조합에서 넘치지 않고 (제목 · 설명은 줄을 바꿈), 단추는 넘치면 다음 줄로.
/// 위젯 하나에 대해 한 번만 둔다 (설계 7-2) - 화면마다 띠 넘침 시험을 더하지 않는다
void main() {
const texts = {
'ko': ('이 폴더를 읽을 수 없습니다', '저장소 권한이 없거나 다른 앱이 쓰는 중입니다. 허용 화면에서 JJ_MKVMaker 를 켜고 돌아오세요.', ['권한 허용 화면 열기', '허용했으면 다시 확인', '닫기']),
'en': ('Cannot read this folder', 'There is no storage permission or another app is using it. Turn on JJ_MKVMaker in the settings screen and come back.',
['Open permission screen', 'Check again', 'Close']),
'ja': ('このフォルダーを読み込めません', 'ストレージの権限がないか、別のアプリが使用中です。許可画面で JJ_MKVMaker をオンにして戻ってください。', ['許可画面を開く', '許可したら再確認', '閉じる']),
};
for (final width in [300.0, 412.0, 960.0]) {
for (final scale in [1.0, 1.3, 2.0]) {
for (final MapEntry(key: lang, value: (title, body, buttons)) in texts.entries) {
testWidgets('$lang · 폭 $width · 배율 $scale: 넘치지 않음 · 단추 모두 보임', (t) async {
t.view.physicalSize = Size(width, 1200);
t.view.devicePixelRatio = 1;
addTearDown(t.view.reset);
await t.pumpWidget(MaterialApp(
home: MediaQuery(
data: MediaQueryData(size: Size(width, 1200), textScaler: TextScaler.linear(scale)),
child: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: NoticeBand(
icon: Icons.lock_outline,
title: title,
body: body,
actions: [for (final b in buttons) TextButton(onPressed: () {}, child: Text(b))],
),
),
),
),
));
expect(t.takeException(), isNull, reason: '넘침 없음');
for (final b in buttons) {
final r = t.getRect(find.text(b));
expect(r.right <= width && r.left >= 0, isTrue, reason: '단추 "$b" 가 띠 안에');
}
final band = t.getRect(find.byType(NoticeBand));
expect(band.width, lessThanOrEqualTo(width));
if (width == 300 && scale == 2.0) {
final ys = {for (final b in buttons) t.getRect(find.text(b)).top};
expect(ys.length, greaterThan(1), reason: '좁고 크면 단추가 다음 줄로');
}
});
}
}
}
}