forked from QuisApp/flutter_contacts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontact_test.dart
53 lines (49 loc) · 1.61 KB
/
contact_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
test('new contact should have no null values except for photo', () {
final contact = Contact();
final json = contact.toJson();
final nulls = nullValues(json);
expect(nulls, ['/thumbnail', '/photo']);
});
test('add phone numbers', () async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
const MethodChannel('github.com/QuisApp/flutter_contacts'),
(MethodCall methodCall) async {
if (methodCall.method == 'insert') {
final c = methodCall.arguments[0];
c['displayName'] = '${c['name']['first']} ${c['name']['last']}';
c['id'] = '12345';
return c;
}
return null;
},
);
final newContact = Contact()
..name = Name(first: 'John', last: 'Doe')
..phones = [
Phone('555-123-4567'),
Phone('555-999-9999', label: PhoneLabel.work)
];
final returnedContact = await newContact.insert();
expect(returnedContact.displayName, 'John Doe');
expect(returnedContact.phones.length, 2);
});
}
List<String> nullValues(dynamic x, {String path = ''}) {
if (x is Map) {
var nulls = <String>[];
x.forEach((k, v) => nulls.addAll(nullValues(v, path: '$path/$k')));
return nulls;
} else if (x is List) {
return nullValues(x.asMap(), path: path);
} else if (x == null) {
return [path];
} else {
return [];
}
}