JJ_MKVMaker/test/settings_sections_contract_...

83 lines
4.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:jj_mkvmaker/app/app_controller.dart';
import 'package:jj_mkvmaker/platform/windows/desktop_storage_service.dart';
import 'package:jj_mkvmaker/platform/windows/process_media_tool.dart';
import 'package:jj_mkvmaker/services/platform_services.dart';
import 'package:jj_mkvmaker/ui/settings/app_sections.dart';
import 'package:jj_mkvmaker/ui/settings/browser_section.dart';
import 'package:jj_mkvmaker/ui/settings/files_section.dart';
import 'package:jj_mkvmaker/ui/settings/general_sections.dart';
import 'package:jj_mkvmaker/ui/settings/media_sections.dart';
import 'package:jj_mkvmaker/ui/settings/settings_tiles.dart';
import 'package:jj_mkvmaker/ui/settings/transfer_sections.dart';
/// 설정 B 약속 시험: lib/ui/settings/ 의 분야 · 공용 줄 (실제 화면 · 실제 설정 - 저장소 없음)
void main() {
AppController app() => AppController(PlatformServices(mediaTool: ProcessMediaTool('x', 'y'), storage: DesktopStorageService()));
Future<void> show(WidgetTester t, Widget w) async {
t.view.physicalSize = const Size(1200, 4000);
t.view.devicePixelRatio = 1;
addTearDown(t.view.reset);
await t.pumpWidget(MaterialApp(home: Scaffold(body: SingleChildScrollView(child: w))));
await t.pump();
}
final sections = <String, Widget Function(AppController c, bool desk)>{
'general': (c, d) => GeneralSettingsSection(c: c, desk: d),
'display': (c, d) => DisplaySettingsSection(c: c, desk: d),
'mkv': (c, d) => MkvSettingsSection(c: c, desk: d),
'subtitle': (c, d) => SubtitleSettingsSection(c: c, desk: d),
'play': (c, d) => PlaySettingsSection(c: c, desk: d),
'browser': (c, d) => BrowserSettingsSection(c: c, desk: d),
'files': (c, d) => FilesSettingsSection(c: c, desk: d),
'rsync': (c, d) => RsyncSettingsSection(c: c, desk: d),
'download': (c, d) => DownloadSettingsSection(c: c, desk: d),
'run': (c, d) => RunSettingsSection(c: c, desk: d),
'cleanup': (c, d) => CleanupSettingsSection(c: c, desk: d),
'about': (c, d) => AboutSettingsSection(c: c, desk: d),
};
for (final e in sections.entries) {
testWidgets('분야 ${e.key}: PC · Android 갈래 모두 그려짐 (줄이 하나 이상)', (t) async {
for (final desk in [true, false]) {
await show(t, e.value(app(), desk));
expect(find.byType(ListTile).evaluate().length + find.byType(SwitchListTile).evaluate().length + find.byType(Text).evaluate().length,
greaterThan(0));
}
});
}
testWidgets('일반: 스위치를 바꾸면 바로 설정에 (업데이트로 바뀐 기본값 알림)', (t) async {
final c = app();
final before = c.settings.migrationNotice;
await show(t, GeneralSettingsSection(c: c, desk: true));
await t.tap(find.widgetWithText(SwitchListTile, '업데이트로 바뀐 기본값 알림'));
await t.pump();
expect(c.settings.migrationNotice, !before);
});
testWidgets('공용 줄: 개수 고르기 · 글 넣는 줄 저장 · 폴더 줄 [기본값] 은 고른 것이 있을 때만', (t) async {
int? count;
final saved = <String>[];
var reset = 0;
await show(
t,
Column(children: [
CountSelector(value: 1, onChanged: (n) => count = n),
settingsTextTile('이름', '', '설명', saved.add),
settingsFolderTile(title: '폴더 A', value: null, defaultText: '처음 값', onPick: () {}, onReset: () => reset++),
settingsFolderTile(title: '폴더 B', value: r'D:\x', defaultText: '처음 값', onPick: () {}, onReset: () => reset++),
]));
await t.tap(find.text(CountSelector.label(1)));
await t.pumpAndSettle();
await t.tap(find.text(CountSelector.label(5)).last);
await t.pumpAndSettle();
await t.enterText(find.byType(TextFormField), 'abc');
expect([count, saved.last], [5, 'abc']);
expect(find.text('기본값'), findsOneWidget, reason: '고른 것이 있는 폴더 줄만');
await t.tap(find.text('기본값'));
expect(reset, 1);
});
}