Skip to content

Commit

Permalink
Added test for getIosDevices() #172
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcc007 committed Dec 16, 2019
1 parent ed88f1a commit ee07ff5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/daemon_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ List getIosDevices() {
.trim()
.split('\n')
.sublist(1);
if (iosDeployDevices.isEmpty || iosDeployDevices[0] == noAttachedDevices) {
if (iosDeployDevices[0] == noAttachedDevices) {
return [];
}
return iosDeployDevices.map((line) {
Expand Down
50 changes: 50 additions & 0 deletions test/daemon_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,56 @@ main() {
expect(emulator1, isNot(equals(device1)));
});
});

group('getIosDevices', (){
FakeProcessManager fakeProcessManager;
FakePlatform fakePlatform;

setUp(() {
fakeProcessManager = FakeProcessManager();
fakePlatform = FakePlatform.fromPlatform(const LocalPlatform())
..operatingSystem = 'macos';
});

testUsingContext('no real device',(){
fakeProcessManager.calls = [
Call(
'sh -c ios-deploy -c || echo "no attached devices"',
ProcessResult(
0,
0,
'[....] Waiting up to 5 seconds for iOS device to be connected\nno attached devices',
'')),
];
final iosDevices = getIosDevices();
expect(iosDevices, isEmpty);
fakeProcessManager.verifyCalls();
}, overrides: <Type, Generator>{
ProcessManager: () => fakeProcessManager,
Platform: () => fakePlatform,
});

testUsingContext('real device',(){
final uuid='uuid';
final model = 'model';
final expected = [{'id': uuid, 'model': model}];
fakeProcessManager.calls = [
Call(
'sh -c ios-deploy -c || echo "no attached devices"',
ProcessResult(
0,
0,
"[....] Waiting up to 5 seconds for iOS device to be connected\n[....] Found $uuid (N69uAP, $model, iphoneos, arm64) a.k.a. 'My iPhone' connected through USB.",
'')),
];
final iosDevices = getIosDevices();
expect(iosDevices, expected);
fakeProcessManager.verifyCalls();
}, overrides: <Type, Generator>{
ProcessManager: () => fakeProcessManager,
Platform: () => fakePlatform,
});
});
}

class MockProcess extends Mock implements Process {}
Expand Down

0 comments on commit ee07ff5

Please sign in to comment.