176 lines
6.1 KiB
Dart
176 lines
6.1 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:payloads_host/payloads_host.dart';
|
|
import 'package:bridge_core/bridge_core.dart';
|
|
|
|
void main() {
|
|
group('SecretAdminCommandPayload', () {
|
|
test('should create admin command payload', () {
|
|
final payload = SecretAdminCommandPayload(
|
|
command: 'restart_app',
|
|
parameters: {'force': true},
|
|
adminToken: 'secret123',
|
|
);
|
|
|
|
expect(payload.command, equals('restart_app'));
|
|
expect(payload.parameters, equals({'force': true}));
|
|
expect(payload.adminToken, equals('secret123'));
|
|
expect(payload.type, equals('secret_admin_command'));
|
|
});
|
|
|
|
test('should serialize and deserialize correctly', () {
|
|
final original = SecretAdminCommandPayload(
|
|
command: 'restart_app',
|
|
parameters: {'force': true},
|
|
adminToken: 'secret123',
|
|
);
|
|
final json = original.toJson();
|
|
final deserialized = SecretAdminCommandPayload.fromJson(json);
|
|
|
|
expect(deserialized.command, equals(original.command));
|
|
expect(deserialized.parameters, equals(original.parameters));
|
|
expect(deserialized.adminToken, equals(original.adminToken));
|
|
});
|
|
});
|
|
|
|
group('AdminCommandResponsePayload', () {
|
|
test('should create admin command response', () {
|
|
final payload = AdminCommandResponsePayload(
|
|
success: true,
|
|
result: 'App restarted successfully',
|
|
data: {'restartTime': '2024-01-01T00:00:00Z'},
|
|
);
|
|
|
|
expect(payload.success, isTrue);
|
|
expect(payload.result, equals('App restarted successfully'));
|
|
expect(payload.data, equals({'restartTime': '2024-01-01T00:00:00Z'}));
|
|
expect(payload.type, equals('admin_command_response'));
|
|
});
|
|
|
|
test('should serialize and deserialize correctly', () {
|
|
final original = AdminCommandResponsePayload(
|
|
success: true,
|
|
result: 'Success',
|
|
error: null,
|
|
data: {'key': 'value'},
|
|
);
|
|
final json = original.toJson();
|
|
final deserialized = AdminCommandResponsePayload.fromJson(json);
|
|
|
|
expect(deserialized.success, equals(original.success));
|
|
expect(deserialized.result, equals(original.result));
|
|
expect(deserialized.error, equals(original.error));
|
|
expect(deserialized.data, equals(original.data));
|
|
});
|
|
});
|
|
|
|
group('ShowNativeDialogPayload', () {
|
|
test('should create native dialog payload', () {
|
|
final buttons = [
|
|
DialogButton(id: 'ok', text: 'OK'),
|
|
DialogButton(id: 'cancel', text: 'Cancel', style: ButtonStyle.cancel),
|
|
];
|
|
|
|
final payload = ShowNativeDialogPayload(
|
|
title: 'Confirm Action',
|
|
message: 'Are you sure?',
|
|
buttons: buttons,
|
|
dialogType: DialogType.confirm,
|
|
);
|
|
|
|
expect(payload.title, equals('Confirm Action'));
|
|
expect(payload.message, equals('Are you sure?'));
|
|
expect(payload.buttons.length, equals(2));
|
|
expect(payload.dialogType, equals(DialogType.confirm));
|
|
expect(payload.type, equals('show_native_dialog'));
|
|
});
|
|
|
|
test('should serialize and deserialize correctly', () {
|
|
final buttons = [
|
|
DialogButton(id: 'ok', text: 'OK'),
|
|
DialogButton(id: 'cancel', text: 'Cancel', style: ButtonStyle.cancel),
|
|
];
|
|
|
|
final original = ShowNativeDialogPayload(
|
|
title: 'Test',
|
|
message: 'Test message',
|
|
buttons: buttons,
|
|
dialogType: DialogType.alert,
|
|
);
|
|
final json = original.toJson();
|
|
final deserialized = ShowNativeDialogPayload.fromJson(json);
|
|
|
|
expect(deserialized.title, equals(original.title));
|
|
expect(deserialized.message, equals(original.message));
|
|
expect(deserialized.buttons.length, equals(original.buttons.length));
|
|
expect(deserialized.dialogType, equals(original.dialogType));
|
|
});
|
|
});
|
|
|
|
group('NativeDialogResponsePayload', () {
|
|
test('should create native dialog response', () {
|
|
final payload = NativeDialogResponsePayload(
|
|
selectedButtonId: 'ok',
|
|
cancelled: false,
|
|
userInput: {'text': 'user input'},
|
|
);
|
|
|
|
expect(payload.selectedButtonId, equals('ok'));
|
|
expect(payload.cancelled, isFalse);
|
|
expect(payload.userInput, equals({'text': 'user input'}));
|
|
expect(payload.type, equals('native_dialog_response'));
|
|
});
|
|
|
|
test('should serialize and deserialize correctly', () {
|
|
final original = NativeDialogResponsePayload(
|
|
selectedButtonId: 'ok',
|
|
cancelled: false,
|
|
userInput: {'text': 'user input'},
|
|
);
|
|
final json = original.toJson();
|
|
final deserialized = NativeDialogResponsePayload.fromJson(json);
|
|
|
|
expect(deserialized.selectedButtonId, equals(original.selectedButtonId));
|
|
expect(deserialized.cancelled, equals(original.cancelled));
|
|
expect(deserialized.userInput, equals(original.userInput));
|
|
});
|
|
});
|
|
|
|
group('DialogButton', () {
|
|
test('should create dialog button', () {
|
|
final button = DialogButton(
|
|
id: 'ok',
|
|
text: 'OK',
|
|
style: ButtonStyle.default_,
|
|
);
|
|
|
|
expect(button.id, equals('ok'));
|
|
expect(button.text, equals('OK'));
|
|
expect(button.style, equals(ButtonStyle.default_));
|
|
});
|
|
|
|
test('should serialize and deserialize correctly', () {
|
|
final original = DialogButton(
|
|
id: 'cancel',
|
|
text: 'Cancel',
|
|
style: ButtonStyle.cancel,
|
|
);
|
|
final json = original.toJson();
|
|
final deserialized = DialogButton.fromJson(json);
|
|
|
|
expect(deserialized.id, equals(original.id));
|
|
expect(deserialized.text, equals(original.text));
|
|
expect(deserialized.style, equals(original.style));
|
|
});
|
|
});
|
|
|
|
group('Payload Registration', () {
|
|
test('should register all host payloads', () {
|
|
registerHostPayloads();
|
|
|
|
expect(PayloadRegistry.isRegistered('secret_admin_command'), isTrue);
|
|
expect(PayloadRegistry.isRegistered('admin_command_response'), isTrue);
|
|
expect(PayloadRegistry.isRegistered('show_native_dialog'), isTrue);
|
|
expect(PayloadRegistry.isRegistered('native_dialog_response'), isTrue);
|
|
});
|
|
});
|
|
}
|