|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | + |
| 3 | +import 'package:e2e/common.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + test('Serialize and deserialize Failure', () { |
| 7 | + Failure fail = Failure('what a name', 'no detail'); |
| 8 | + Failure restored = Failure.fromJsonString(fail.toString()); |
| 9 | + expect(restored.methodName, fail.methodName); |
| 10 | + expect(restored.details, fail.details); |
| 11 | + }); |
| 12 | + |
| 13 | + test('Serialize and deserialize Response', () { |
| 14 | + Response response, restored; |
| 15 | + String jsonString; |
| 16 | + |
| 17 | + response = Response.allTestsPassed(); |
| 18 | + jsonString = response.toJson(); |
| 19 | + expect(jsonString, '{"result":"true","failureDetails":[]}'); |
| 20 | + restored = Response.fromJson(jsonString); |
| 21 | + expect(restored.allTestsPassed, response.allTestsPassed); |
| 22 | + expect(restored.data, null); |
| 23 | + expect(restored.formattedFailureDetails, ''); |
| 24 | + |
| 25 | + final Failure fail = Failure('what a name', 'no detail'); |
| 26 | + final Failure fail2 = Failure('what a name2', 'no detail2'); |
| 27 | + response = Response.someTestsFailed([fail, fail2]); |
| 28 | + jsonString = response.toJson(); |
| 29 | + restored = Response.fromJson(jsonString); |
| 30 | + expect(restored.allTestsPassed, response.allTestsPassed); |
| 31 | + expect(restored.data, null); |
| 32 | + expect(restored.formattedFailureDetails, response.formattedFailureDetails); |
| 33 | + |
| 34 | + Map<String, dynamic> data = <String, dynamic>{'aaa': 'bbb'}; |
| 35 | + response = Response.allTestsPassed(data: data); |
| 36 | + jsonString = response.toJson(); |
| 37 | + restored = Response.fromJson(jsonString); |
| 38 | + expect(restored.data.keys, ['aaa']); |
| 39 | + expect(restored.data.values, ['bbb']); |
| 40 | + |
| 41 | + response = Response.someTestsFailed([fail, fail2], data: data); |
| 42 | + jsonString = response.toJson(); |
| 43 | + restored = Response.fromJson(jsonString); |
| 44 | + expect(restored.data.keys, ['aaa']); |
| 45 | + expect(restored.data.values, ['bbb']); |
| 46 | + }); |
| 47 | +} |
0 commit comments