Files
TPSchedule/mobile/test/widgets/settings_test.dart
T

99 lines
3.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:timezone/data/latest.dart' as tzdata;
import 'package:hepan_everyday/app/hepan_app.dart';
import 'package:hepan_everyday/app/app_controller.dart';
import 'package:hepan_everyday/features/profile/settings_page.dart';
import 'package:hepan_everyday/services/calendar_service.dart';
import '../support/fakes.dart';
import 'navigation_test.dart' show uiController;
void main() {
setUpAll(tzdata.initializeTimeZones);
testWidgets('calendar provider failure is explained and keeps switch off', (
tester,
) async {
final controller = AppController(
MemoryStore(),
FakeNotifications(),
UnavailableCalendar(),
DateTime.now,
);
await controller.initialize();
await tester.pumpWidget(
MaterialApp(home: SettingsPage(controller: controller)),
);
await tester.pumpAndSettle();
await tester.scrollUntilVisible(
find.text('导入手机日历'),
250,
scrollable: find.byType(Scrollable).first,
);
await tester.ensureVisible(find.text('导入手机日历'));
await tester.pumpAndSettle();
await tester.tap(find.text('导入手机日历'));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
expect(find.text('日历暂时不可用,请检查权限后重试'), findsOneWidget);
expect(controller.snapshot.settings.calendarEnabled, isFalse);
controller.dispose();
});
testWidgets(
'invalid semester weeks are rejected without changing saved data',
(tester) async {
final controller = uiController();
await controller.initialize();
await tester.pumpWidget(HepanApp(controller: controller));
await tester.pumpAndSettle();
expect(find.bySemanticsLabel('我的'), findsOneWidget);
await tester.tap(find.bySemanticsLabel('我的'));
await tester.pumpAndSettle();
await tester.ensureVisible(find.text('课表设置'));
await tester.pumpAndSettle();
await tester.tap(find.text('课表设置'));
await tester.pumpAndSettle();
await tester.scrollUntilVisible(
find.byKey(const Key('semester-weeks')),
300,
scrollable: find.byType(Scrollable).last,
);
await tester.enterText(find.byKey(const Key('semester-weeks')), '31');
await tester.ensureVisible(find.text('保存学期设置'));
await tester.tap(find.text('保存学期设置'));
await tester.pumpAndSettle();
expect(find.text('周数应为 1–30'), findsOneWidget);
expect(controller.snapshot.settings.semester, isNull);
controller.dispose();
},
);
testWidgets('two hundred percent font demo has no overflow', (tester) async {
tester.view.physicalSize = const Size(360, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
tester.platformDispatcher.textScaleFactorTestValue = 2;
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
final controller = uiController();
await controller.initialize();
await controller.showDemo();
await tester.pumpWidget(HepanApp(controller: controller));
await tester.pumpAndSettle();
await tester.scrollUntilVisible(
find.text('示例课表'),
250,
scrollable: find.byType(Scrollable).first,
);
expect(find.text('示例课表'), findsOneWidget);
expect(tester.takeException(), isNull);
controller.dispose();
});
}
class UnavailableCalendar extends FakeCalendar {
@override
Future<List<DeviceCalendar>> listWritableCalendars() async =>
throw StateError('unavailable');
}