fix: 登录按钮对认不出的输入给出提示,不再静默无反应

- SGWCMAID 前缀改成按粘贴原文判断:令牌取的是内容的后 64 位,粘贴内容一旦超过
  64 位,前缀就被截掉了,原先对截取结果做 startsWith 会直接 return,
  点按钮看着能点却一声不响
- 补 test/login_page_test.dart 覆盖两条输入路径:不认识的令牌给提示,
  连接信息把按钮切成「恢复会话」
This commit is contained in:
Cookiues committed 2026-09-29 13:30:06 +08:00
1 parent 5d16984e4e
commit e74bb792bd
3 files changed
+80 -32

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:ichino/config/strings.dart';
import 'package:ichino/main.dart';
import 'package:ichino/models/session_share.dart';
/// 登录页的输入既可能是 QR 令牌,也可能是主页导出的「连接信息」,
/// 两条路都要有可见反馈,不能出现点了没反应。
void main() {
testWidgets('粘贴不认识的令牌时点登录会给出提示', (tester) async {
await tester.pumpWidget(const MyApp());
await tester.pump();
// 72 位:截取的后 64 位里没有 SGWCMAID 前缀
await tester.enterText(find.byType(TextField), 'ABCDEF' * 12);
await tester.pump();
await tester.tap(find.text(AppStrings.login));
await tester.pump();
expect(find.text(AppStrings.qrTokenUnrecognized), findsOneWidget);
});
testWidgets('粘贴连接信息时按钮切成「恢复会话」', (tester) async {
await tester.pumpWidget(const MyApp());
await tester.pump();
const share = SessionShare(
userId: 7,
token: 'SGWCMAIDtoken',
cookie: 'JSESSIONID=x',
);
await tester.enterText(find.byType(TextField), share.encode());
await tester.pump();
expect(find.text(AppStrings.sessionShareDetected), findsOneWidget);
expect(find.text(AppStrings.restoreSession), findsOneWidget);
expect(find.text(AppStrings.login), findsNothing);
});
}