74 lines
2.7 KiB
Dart
74 lines
2.7 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:ads_manager/ui/app_widgets.dart' show AdsCupertinoApp;
|
|
|
|
import 'package:cupertino_ui/cupertino_ui.dart' show CupertinoTextField;
|
|
|
|
import 'package:material_ui/material_ui.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:ads_manager/data/manager_repository.dart';
|
|
import 'package:ads_manager/ui/manager_model.dart';
|
|
import 'package:ads_manager/ui/manager_view.dart';
|
|
|
|
void main() {
|
|
test('API URL preserves deployment prefix and rejects insecure schemes', () {
|
|
final s = Settings()..server = 'wss://example.com/ads/';
|
|
expect(
|
|
s.uri('v1/devices').toString(),
|
|
'https://example.com/ads/v1/devices',
|
|
);
|
|
s.server = 'ws://example.com';
|
|
expect(() => s.uri('v1/devices'), throwsFormatException);
|
|
});
|
|
test(
|
|
'agent credentials are rejected; client secret is not persisted',
|
|
() async {
|
|
final dir = await Directory.systemTemp.createTemp('ads-flutter-test');
|
|
try {
|
|
final file = File('${dir.path}/client.env');
|
|
final repo = ManagerRepository((_) {});
|
|
repo.settings.credential = file.path;
|
|
await file.writeAsString('ADS_AGENT_TOKEN=${'a' * 32}');
|
|
await expectLater(repo.importCredential(), throwsFormatException);
|
|
await file.writeAsString('ADS_CLIENT_TOKEN=${'b' * 32}');
|
|
await repo.importCredential();
|
|
expect(repo.token, 'b' * 32);
|
|
expect(repo.settings.toJson().toString(), isNot(contains('b' * 32)));
|
|
} finally {
|
|
await dir.delete(recursive: true);
|
|
}
|
|
},
|
|
);
|
|
for (final width in [920.0, 1280.0]) {
|
|
testWidgets('device status, search and navigation at $width px', (
|
|
tester,
|
|
) async {
|
|
tester.view.physicalSize = Size(width, 820);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
final m = ManagerModel();
|
|
m.devices = [
|
|
const Device('test-phone', false),
|
|
const Device('busy-phone', true),
|
|
];
|
|
await tester.pumpWidget(
|
|
AdsCupertinoApp(
|
|
home: ManagerView(model: m, onQuit: () async {}),
|
|
),
|
|
);
|
|
expect(find.text('test-phone'), findsOneWidget);
|
|
expect(find.text('其他客户端占用'), findsOneWidget);
|
|
await tester.enterText(find.byType(CupertinoTextField), 'test');
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('busy-phone'), findsNothing);
|
|
await tester.tap(find.text('连接配置'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('保存配置'), findsOneWidget);
|
|
expect(tester.takeException(), isNull);
|
|
await tester.pumpWidget(const SizedBox());
|
|
m.dispose();
|
|
});
|
|
}
|
|
}
|