iop/apps/client/test/widget_test.dart
toki 1fe368ad2c refactor: portal → client 앱 리팩토링 및 제어플랫폼 와이어 클라이언트 명명 변경
- apps/portal 디렉터리를 apps/client로 리팩터링
- ControlPlaneWireClient → WireClient 명명 변경
- 관련_proto import 정렬, struct protobuf 생성 제거
- README, docker-compose, 스크립트 등 일관성 개선
2026-05-28 20:24:45 +09:00

111 lines
2.9 KiB
Dart

import 'dart:async';
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:iop_client/main.dart';
import 'package:iop_client/client_config.dart';
import 'package:iop_client/iop_wire/client_wire_client.dart';
import 'package:iop_client/gen/proto/iop/control.pb.dart';
import 'package:protobuf/protobuf.dart';
import 'package:fixnum/fixnum.dart';
class FakeWebSocket implements WebSocket {
final _controller = StreamController<dynamic>();
@override
StreamSubscription<dynamic> listen(
void Function(dynamic event)? onData, {
Function? onError,
void Function()? onDone,
bool? cancelOnError,
}) {
return _controller.stream.listen(
onData,
onError: onError,
onDone: onDone,
cancelOnError: cancelOnError,
);
}
@override
dynamic noSuchMethod(Invocation invocation) {
return null;
}
}
class FakeClientWireClient extends ClientWireClient {
final bool shouldSuccess;
final String mockMessage;
FakeClientWireClient({
this.shouldSuccess = true,
this.mockMessage = 'Welcome to Toki CP!',
}) : super(FakeWebSocket());
@override
bool get isAlive => true;
@override
Future<Res> sendRequest<
Req extends GeneratedMessage,
Res extends GeneratedMessage
>(Req data, {Duration timeout = const Duration(seconds: 30)}) async {
if (data is ClientHelloRequest) {
final response = ClientHelloResponse()
..ready = shouldSuccess
..protocol = 'iop-wire-v1'
..serverTimeUnixNano = Int64(1716584400)
..message = mockMessage;
return response as Res;
}
throw UnimplementedError();
}
}
void main() {
testWidgets('Client App basic rendering and success handshake test', (
WidgetTester tester,
) async {
final fakeClient = FakeClientWireClient(shouldSuccess: true);
await tester.pumpWidget(IopClientApp(testClient: fakeClient));
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(find.text('IOP Client'), findsOneWidget);
expect(find.text('HEALTH: OK'), findsOneWidget);
expect(
find.text(ClientConfig.controlPlaneHttpUrl, findRichText: true),
findsOneWidget,
);
expect(
find.text(ClientConfig.controlPlaneWireUrl, findRichText: true),
findsOneWidget,
);
expect(find.text('Connected'), findsOneWidget);
expect(
find.textContaining('Handshake Success: Welcome to Toki CP!'),
findsOneWidget,
);
});
testWidgets('Client App connection error state test', (
WidgetTester tester,
) async {
final fakeClient = FakeClientWireClient(
shouldSuccess: false,
mockMessage: 'Invalid Version',
);
await tester.pumpWidget(IopClientApp(testClient: fakeClient));
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(find.text('Error'), findsOneWidget);
expect(
find.textContaining('Handshake Rejected: Invalid Version'),
findsOneWidget,
);
});
}