feat: select school before connecting timetable
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
const appVersion = '0.6.1';
|
||||
const appBuildNumber = 16;
|
||||
const appVersion = '0.6.2';
|
||||
const appBuildNumber = 17;
|
||||
|
||||
@@ -14,6 +14,7 @@ import '../features/exams/exams_page.dart';
|
||||
import '../features/timetable/timetable_page.dart';
|
||||
import '../features/profile/profile_page.dart';
|
||||
import '../features/school/school_session.dart';
|
||||
import '../features/school/school_selection_page.dart';
|
||||
|
||||
class HepanApp extends StatelessWidget {
|
||||
const HepanApp({
|
||||
@@ -66,6 +67,16 @@ class _Shell extends StatefulWidget {
|
||||
|
||||
class _ShellState extends State<_Shell> with WidgetsBindingObserver {
|
||||
int _tab = 0;
|
||||
bool _openingSchool = false;
|
||||
SupportedSchool? _selectedSchool;
|
||||
// Earlier imports all belong to UESTC graduate; reuse their existing term
|
||||
// and session without requiring students to choose again on every refresh.
|
||||
SupportedSchool? get _knownSchool =>
|
||||
_selectedSchool ??
|
||||
(widget.controller.snapshot.schoolTerm != null ||
|
||||
widget.school?.canLogout == true
|
||||
? SupportedSchool.uestcGraduate
|
||||
: null);
|
||||
void _selectTab(int index) {
|
||||
if (index == _tab) return;
|
||||
setState(() => _tab = index);
|
||||
@@ -121,7 +132,41 @@ class _ShellState extends State<_Shell> with WidgetsBindingObserver {
|
||||
}
|
||||
}
|
||||
|
||||
void _school({bool exams = false, bool chooseTerm = false}) {
|
||||
Future<void> _school({
|
||||
bool exams = false,
|
||||
bool chooseTerm = false,
|
||||
bool selectSchool = false,
|
||||
}) async {
|
||||
if (_openingSchool) return;
|
||||
_openingSchool = true;
|
||||
try {
|
||||
var selected = _knownSchool;
|
||||
if (selectSchool || selected == null) {
|
||||
selected = await Navigator.push<SupportedSchool>(
|
||||
context,
|
||||
MaterialPageRoute<SupportedSchool>(
|
||||
builder: (_) => SchoolSelectionPage(selected: _knownSchool),
|
||||
),
|
||||
);
|
||||
if (!mounted || selected == null) return;
|
||||
setState(() => _selectedSchool = selected);
|
||||
}
|
||||
if (!mounted) return;
|
||||
// The only current connector is the existing UESTC graduate workflow.
|
||||
// A new catalog option must provide its own connector here.
|
||||
switch (selected) {
|
||||
case SupportedSchool.uestcGraduate:
|
||||
await _openSchool(exams: exams, chooseTerm: chooseTerm);
|
||||
}
|
||||
} finally {
|
||||
_openingSchool = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openSchool({
|
||||
bool exams = false,
|
||||
bool chooseTerm = false,
|
||||
}) async {
|
||||
if (widget.schoolBuilder != null) {
|
||||
final term = widget.controller.snapshot.schoolTerm;
|
||||
if (exams) {
|
||||
@@ -135,12 +180,12 @@ class _ShellState extends State<_Shell> with WidgetsBindingObserver {
|
||||
chooseTerm: chooseTerm || term == null,
|
||||
);
|
||||
}
|
||||
Navigator.push(
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute<void>(builder: (_) => widget.schoolBuilder!()),
|
||||
);
|
||||
} else {
|
||||
showDialog<void>(
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('学校认证'),
|
||||
@@ -275,7 +320,8 @@ class _ShellState extends State<_Shell> with WidgetsBindingObserver {
|
||||
ProfilePage(
|
||||
controller: widget.controller,
|
||||
feedbackSender: widget.feedbackSender,
|
||||
onLogin: _school,
|
||||
onLogin: () => _school(selectSchool: true),
|
||||
schoolName: _knownSchool?.label,
|
||||
onUpdateTerm: () => _school(chooseTerm: true),
|
||||
authStatus: widget.school?.statusLabel ?? '未登录',
|
||||
logoutLabel: widget.school?.logoutFailed == true
|
||||
|
||||
@@ -118,7 +118,7 @@ class ExamsPage extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'连接研究生系统,或导入学校考试页面的 HTML。',
|
||||
'选择学校连接教务系统,或导入学校考试页面的 HTML。',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 13, height: 1.8),
|
||||
),
|
||||
|
||||
@@ -18,6 +18,7 @@ class ProfilePage extends StatelessWidget {
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.onLogin,
|
||||
this.schoolName,
|
||||
this.authStatus = '未登录',
|
||||
this.onLogout,
|
||||
this.logoutLabel = '退出学校登录',
|
||||
@@ -26,6 +27,7 @@ class ProfilePage extends StatelessWidget {
|
||||
});
|
||||
final AppController controller;
|
||||
final VoidCallback onLogin;
|
||||
final String? schoolName;
|
||||
final VoidCallback? onLogout;
|
||||
final VoidCallback? onUpdateTerm;
|
||||
final String authStatus, logoutLabel;
|
||||
@@ -98,12 +100,12 @@ class ProfilePage extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'连接学校课表',
|
||||
'学校课表',
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w700),
|
||||
),
|
||||
const SizedBox(height: 7),
|
||||
Text(
|
||||
'电子科技大学 · 研究生\n$authStatus',
|
||||
'${schoolName ?? '选择学校后连接教务系统'}\n$authStatus',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
height: 1.8,
|
||||
@@ -115,7 +117,7 @@ class ProfilePage extends StatelessWidget {
|
||||
width: double.infinity,
|
||||
child: FilledButton(
|
||||
onPressed: onLogin,
|
||||
child: Text(onLogout == null ? '登录学校账户' : '打开学校课表'),
|
||||
child: const Text('选择学校'),
|
||||
),
|
||||
),
|
||||
if (onLogout != null)
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../app/app_theme.dart';
|
||||
|
||||
/// Only list schools whose login and import workflow is available.
|
||||
enum SupportedSchool {
|
||||
uestcGraduate('电子科技大学(研究生)', '研究生课表与考试安排');
|
||||
|
||||
const SupportedSchool(this.label, this.description);
|
||||
final String label, description;
|
||||
}
|
||||
|
||||
class SchoolSelectionPage extends StatelessWidget {
|
||||
const SchoolSelectionPage({super.key, this.selected});
|
||||
|
||||
final SupportedSchool? selected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
appBar: AppBar(title: const Text('选择学校')),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.fromLTRB(22, 16, 22, 24),
|
||||
children: [
|
||||
Text(
|
||||
'选择你的学校,登录后导入课表和考试。',
|
||||
style: TextStyle(fontSize: 13, color: ink.withValues(alpha: 0.6)),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
for (final school in SupportedSchool.values) ...[
|
||||
SurfaceCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
leading: const Icon(Icons.school_rounded, color: river),
|
||||
title: Text(
|
||||
school.label,
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
subtitle: Text(school.description),
|
||||
trailing: Icon(
|
||||
school == selected
|
||||
? Icons.check_circle_rounded
|
||||
: Icons.chevron_right_rounded,
|
||||
color: river,
|
||||
),
|
||||
onTap: () => Navigator.pop(context, school),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
name: hepan_everyday
|
||||
description: TPSchedule 学生课表
|
||||
publish_to: none
|
||||
version: 0.6.1+16
|
||||
version: 0.6.2+17
|
||||
environment:
|
||||
sdk: ^3.13.5
|
||||
dependencies:
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user