feat: select school before connecting timetable

This commit is contained in:
Codex
2026-10-14 20:58:47 +08:00
parent ce21cdc10c
commit d83481d965
12 changed files with 297 additions and 20 deletions
+5 -5
View File
@@ -28,16 +28,16 @@ void main() {
await tester.drag(find.text('周三'), const Offset(-250, 0));
await tester.pumpAndSettle();
expect(find.text('第 2 周'), findsOneWidget);
expect(find.text('登录学校账户'), findsNothing);
expect(find.text('选择学校'), findsNothing);
await tester.drag(
find.byKey(const Key('dock-cursor')),
const Offset(185, 0),
);
await tester.pumpAndSettle();
expect(find.text('登录学校账户'), findsOneWidget);
await tester.drag(find.text('连接学校课表'), const Offset(250, 0));
expect(find.text('选择学校'), findsOneWidget);
await tester.drag(find.text('学校课表'), const Offset(250, 0));
await tester.pumpAndSettle();
expect(find.text('登录学校账户'), findsOneWidget);
expect(find.text('选择学校'), findsOneWidget);
await tester.drag(
find.byKey(const Key('dock-cursor')),
const Offset(-185, 0),
@@ -46,7 +46,7 @@ void main() {
expect(find.text('示例课表'), findsOneWidget);
await tester.tap(find.text('我的'));
await tester.pumpAndSettle();
expect(find.text('登录学校账户'), findsOneWidget);
expect(find.text('选择学校'), findsOneWidget);
c.dispose();
});
testWidgets('cancelled cursor drag keeps selected tab', (tester) async {
+1 -1
View File
@@ -24,7 +24,7 @@ void main() {
expect(find.bySemanticsLabel('个人设置'), findsOneWidget);
await tester.tap(find.bySemanticsLabel('个人设置'));
await tester.pumpAndSettle();
expect(find.text('登录学校账户'), findsOneWidget);
expect(find.text('选择学校'), findsOneWidget);
expect(find.text('课表设置'), findsOneWidget);
await tester.tap(find.bySemanticsLabel('课表'));
await tester.pumpAndSettle();
@@ -40,7 +40,7 @@ void main() {
expect(find.text('考试安排'), findsOneWidget);
await tester.tap(find.bySemanticsLabel('个人设置'));
await tester.pumpAndSettle();
expect(find.text('登录学校账户'), findsOneWidget);
expect(find.text('选择学校'), findsOneWidget);
c.dispose();
});
}
@@ -0,0 +1,142 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:timezone/data/latest.dart' as tzdata;
import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';
import 'package:hepan_everyday/app/hepan_app.dart';
import 'package:hepan_everyday/domain/school_term.dart';
import 'package:hepan_everyday/features/school/school_session.dart';
import '../support/fake_school_web.dart';
import 'navigation_test.dart' show uiController;
void main() {
setUpAll(tzdata.initializeTimeZones);
testWidgets('cancelling school selection never starts authentication', (
tester,
) async {
WebViewPlatform.instance = FakeSchoolPlatform();
final session = SchoolSession();
final controller = uiController();
await controller.initialize();
addTearDown(session.dispose);
addTearDown(controller.dispose);
await tester.pumpWidget(
HepanApp(
controller: controller,
school: session,
schoolBuilder: () => const Scaffold(body: Text('学校认证页面')),
),
);
await tester.pumpAndSettle();
await tester.tap(find.bySemanticsLabel('个人设置'));
await tester.pumpAndSettle();
await tester.tap(find.widgetWithText(FilledButton, '选择学校'));
await tester.pumpAndSettle();
expect(find.text('电子科技大学(研究生)'), findsOneWidget);
expect(session.hasOpened, isFalse);
expect(find.text('学校认证页面'), findsNothing);
await tester.tap(find.byType(BackButton));
await tester.pumpAndSettle();
expect(session.hasOpened, isFalse);
expect(find.widgetWithText(FilledButton, '选择学校'), findsOneWidget);
expect(controller.snapshot.courses, isEmpty);
});
testWidgets('selecting UESTC graduate enters its existing authentication', (
tester,
) async {
final platform = FakeSchoolPlatform();
WebViewPlatform.instance = platform;
final session = SchoolSession();
final controller = uiController();
await controller.initialize();
addTearDown(session.dispose);
addTearDown(controller.dispose);
await tester.pumpWidget(
HepanApp(
controller: controller,
school: session,
schoolBuilder: () => const Scaffold(body: Text('学校认证页面')),
),
);
await tester.pumpAndSettle();
await tester.tap(find.bySemanticsLabel('个人设置'));
await tester.pumpAndSettle();
await tester.tap(find.widgetWithText(FilledButton, '选择学校'));
await tester.pumpAndSettle();
expect(session.hasOpened, isFalse);
await tester.tap(find.text('电子科技大学(研究生)'));
await tester.pumpAndSettle();
expect(find.text('学校认证页面'), findsOneWidget);
expect(session.hasOpened, isTrue);
expect(platform.web.loads, ['https://yjsjy.uestc.edu.cn/pyxx/jzsso/login']);
Navigator.pop(tester.element(find.text('学校认证页面')));
await tester.pumpAndSettle();
expect(find.textContaining('电子科技大学(研究生)'), findsOneWidget);
});
testWidgets('first exam sync selects school before opening exam workflow', (
tester,
) async {
WebViewPlatform.instance = FakeSchoolPlatform();
final session = SchoolSession();
final controller = uiController();
await controller.initialize();
addTearDown(session.dispose);
addTearDown(controller.dispose);
await tester.pumpWidget(
HepanApp(
controller: controller,
school: session,
schoolBuilder: () => const Scaffold(body: Text('学校认证页面')),
),
);
await tester.pumpAndSettle();
await tester.tap(find.bySemanticsLabel('考试'));
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('从学校更新考试'));
await tester.pumpAndSettle();
expect(find.text('电子科技大学(研究生)'), findsOneWidget);
expect(session.hasOpened, isFalse);
await tester.tap(find.text('电子科技大学(研究生)'));
await tester.pumpAndSettle();
expect(session.requestingExams, isTrue);
expect(find.text('学校认证页面'), findsOneWidget);
});
testWidgets('connected refresh keeps the school and imported semester', (
tester,
) async {
final platform = FakeSchoolPlatform();
WebViewPlatform.instance = platform;
final session = SchoolSession();
await session.openTimetable(term: SchoolTerm(72));
session.connectionState = SchoolConnectionState.connected;
final controller = uiController();
await controller.initialize();
controller.snapshot = controller.snapshot.copyWith(
schoolTerm: SchoolTerm(72),
);
addTearDown(session.dispose);
addTearDown(controller.dispose);
await tester.pumpWidget(
HepanApp(
controller: controller,
school: session,
schoolBuilder: () => const Scaffold(body: Text('学校认证页面')),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('刷新课表'));
await tester.pumpAndSettle();
expect(find.text('学校认证页面'), findsOneWidget);
expect(find.text('电子科技大学(研究生)'), findsNothing);
expect(
platform.web.loads.last,
'https://yjsjy.uestc.edu.cn/pyxx/pygl/xskbcx/index/72',
);
expect(session.selectedTerm, SchoolTerm(72));
session.setReadingActive(false);
});
}