70 lines
3.1 KiB
Dart
70 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:jj_mkvmaker/ui/jj_field.dart';
|
|
|
|
/// W 공용 위젯 약속 (JjField): 도움 글은 칸 아래 3줄까지 (넘으면 거기서 끊김) · 오류 글은 칸 아래 · 좁은 폭 · 큰 글자에서 넘치지 않음 ·
|
|
/// 처음은 일반 글 칸 그대로 (자동 고침 · 추천 켬, 한 줄). 위젯 하나에 대해 한 번만 둔다 (설계 7-2)
|
|
void main() {
|
|
const long = 'サーバーのアドレスを入力します。例: http://100.x.x.x:7860 (--api で起動した Automatic1111 · Forge) '
|
|
'ポートまで含めて入力してください。空にするとこの項目は使いません。';
|
|
|
|
Future<void> show(WidgetTester t, Widget child, {double width = 412, double scale = 1}) async {
|
|
t.view.physicalSize = Size(width, 900);
|
|
t.view.devicePixelRatio = 1;
|
|
addTearDown(t.view.reset);
|
|
await t.pumpWidget(MaterialApp(
|
|
home: MediaQuery(
|
|
data: MediaQueryData(size: Size(width, 900), textScaler: TextScaler.linear(scale)),
|
|
child: Scaffold(body: Column(children: [child])),
|
|
),
|
|
));
|
|
}
|
|
|
|
testWidgets('처음 값: 일반 글 칸 (자동 고침 · 추천 켬 · 한 줄 · 가리지 않음)', (t) async {
|
|
await show(t, JjField(controller: TextEditingController(), label: '이름'));
|
|
final f = t.widget<TextField>(find.byType(TextField));
|
|
expect([f.autocorrect, f.enableSuggestions, f.obscureText, f.maxLines], [true, true, false, 1]);
|
|
expect(f.decoration!.helperMaxLines, 3);
|
|
});
|
|
|
|
testWidgets('도움 글이 길면 3줄까지 보이고 [helperLines] 로 늘릴 수 있음', (t) async {
|
|
for (final lines in [3, 4]) {
|
|
await show(t, JjField(controller: TextEditingController(), label: '주소', helper: long, helperLines: lines), width: 300);
|
|
final helper = find.text(long);
|
|
expect(helper, findsOneWidget);
|
|
expect(t.widget<Text>(helper).maxLines, lines);
|
|
expect(t.takeException(), isNull);
|
|
}
|
|
});
|
|
|
|
testWidgets('오류 글 · 칸 끝 단추가 보이고, 넣기 (Enter) 를 알림', (t) async {
|
|
String? submitted;
|
|
final c = TextEditingController(text: '0 9 * * *');
|
|
await show(
|
|
t,
|
|
JjField(
|
|
controller: c,
|
|
errorText: '알 수 없는 줄',
|
|
outlined: true,
|
|
minLines: 2,
|
|
maxLines: 5,
|
|
suffix: IconButton(icon: const Icon(Icons.check), onPressed: () {}),
|
|
onSubmitted: (v) => submitted = v,
|
|
));
|
|
expect(find.text('알 수 없는 줄'), findsOneWidget);
|
|
expect(find.byIcon(Icons.check), findsOneWidget);
|
|
await t.showKeyboard(find.byType(TextField));
|
|
await t.testTextInput.receiveAction(TextInputAction.done);
|
|
expect(submitted, '0 9 * * *');
|
|
});
|
|
|
|
for (final width in [300.0, 412.0]) {
|
|
for (final scale in [1.0, 2.0]) {
|
|
testWidgets('폭 $width · 배율 $scale: 긴 이름 · 도움 글도 넘치지 않음', (t) async {
|
|
await show(t, JjField(controller: TextEditingController(), label: 'Server address (host name or IP)', helper: long), width: width, scale: scale);
|
|
expect(t.takeException(), isNull);
|
|
});
|
|
}
|
|
}
|
|
}
|