Commit 99e343a2 authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Re-title, format iOS device tests (#10733)

parent 1bc54e06
...@@ -22,7 +22,7 @@ void main() { ...@@ -22,7 +22,7 @@ void main() {
final FakePlatform osx = new FakePlatform.fromPlatform(const LocalPlatform()); final FakePlatform osx = new FakePlatform.fromPlatform(const LocalPlatform());
osx.operatingSystem = 'macos'; osx.operatingSystem = 'macos';
group('test screenshot', () { group('screenshot', () {
MockProcessManager mockProcessManager; MockProcessManager mockProcessManager;
MockFile mockOutputFile; MockFile mockOutputFile;
IOSDevice iosDeviceUnderTest; IOSDevice iosDeviceUnderTest;
...@@ -32,75 +32,68 @@ void main() { ...@@ -32,75 +32,68 @@ void main() {
mockOutputFile = new MockFile(); mockOutputFile = new MockFile();
}); });
testUsingContext( testUsingContext('error if idevicescreenshot is not installed', () async {
'screenshot without ideviceinstaller error', when(mockOutputFile.path).thenReturn(fs.path.join('some', 'test', 'path', 'image.png'));
() async { // Let everything else return exit code 0 so process.dart doesn't crash.
when(mockOutputFile.path).thenReturn(fs.path.join('some', 'test', 'path', 'image.png')); // The matcher order is important.
// Let everything else return exit code 0 so process.dart doesn't crash. when(
// The matcher order is important. mockProcessManager.run(any, environment: null, workingDirectory: null)
when( ).thenReturn(
mockProcessManager.run(any, environment: null, workingDirectory: null) new Future<ProcessResult>.value(new ProcessResult(2, 0, '', ''))
).thenReturn( );
new Future<ProcessResult>.value(new ProcessResult(2, 0, '', '')) // Let `which idevicescreenshot` fail with exit code 1.
); when(
// Let `which idevicescreenshot` fail with exit code 1. mockProcessManager.runSync(
when( <String>['which', 'idevicescreenshot'], environment: null, workingDirectory: null)
mockProcessManager.runSync( ).thenReturn(
<String>['which', 'idevicescreenshot'], environment: null, workingDirectory: null) new ProcessResult(1, 1, '', '')
).thenReturn( );
new ProcessResult(1, 1, '', '')
);
iosDeviceUnderTest = new IOSDevice('1234'); iosDeviceUnderTest = new IOSDevice('1234');
await iosDeviceUnderTest.takeScreenshot(mockOutputFile); await iosDeviceUnderTest.takeScreenshot(mockOutputFile);
verify(mockProcessManager.runSync( verify(mockProcessManager.runSync(
<String>['which', 'idevicescreenshot'], environment: null, workingDirectory: null)); <String>['which', 'idevicescreenshot'], environment: null, workingDirectory: null));
verifyNever(mockProcessManager.run( verifyNever(mockProcessManager.run(
<String>['idevicescreenshot', fs.path.join('some', 'test', 'path', 'image.png')], <String>['idevicescreenshot', fs.path.join('some', 'test', 'path', 'image.png')],
environment: null, environment: null,
workingDirectory: null workingDirectory: null
)); ));
expect(testLogger.errorText, contains('brew install ideviceinstaller')); expect(testLogger.errorText, contains('brew install ideviceinstaller'));
}, },
overrides: <Type, Generator>{ overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Platform: () => osx, Platform: () => osx,
} });
);
testUsingContext( testUsingContext('idevicescreenshot captures and returns screenshot', () async {
'screenshot with ideviceinstaller gets command', when(mockOutputFile.path).thenReturn(fs.path.join('some', 'test', 'path', 'image.png'));
() async { // Let everything else return exit code 0.
when(mockOutputFile.path).thenReturn(fs.path.join('some', 'test', 'path', 'image.png')); // The matcher order is important.
// Let everything else return exit code 0. when(
// The matcher order is important. mockProcessManager.run(any, environment: null, workingDirectory: null)
when( ).thenReturn(
mockProcessManager.run(any, environment: null, workingDirectory: null) new Future<ProcessResult>.value(new ProcessResult(4, 0, '', ''))
).thenReturn( );
new Future<ProcessResult>.value(new ProcessResult(4, 0, '', '')) // Let there be idevicescreenshot in the PATH.
); when(
// Let there be idevicescreenshot in the PATH. mockProcessManager.runSync(
when( <String>['which', 'idevicescreenshot'], environment: null, workingDirectory: null)
mockProcessManager.runSync( ).thenReturn(
<String>['which', 'idevicescreenshot'], environment: null, workingDirectory: null) new ProcessResult(3, 0, fs.path.join('some', 'path', 'to', 'iscreenshot'), '')
).thenReturn( );
new ProcessResult(3, 0, fs.path.join('some', 'path', 'to', 'iscreenshot'), '')
);
iosDeviceUnderTest = new IOSDevice('1234'); iosDeviceUnderTest = new IOSDevice('1234');
await iosDeviceUnderTest.takeScreenshot(mockOutputFile); await iosDeviceUnderTest.takeScreenshot(mockOutputFile);
verify(mockProcessManager.runSync( verify(mockProcessManager.runSync(
<String>['which', 'idevicescreenshot'], environment: null, workingDirectory: null)); <String>['which', 'idevicescreenshot'], environment: null, workingDirectory: null));
verify(mockProcessManager.run( verify(mockProcessManager.run(
<String>[ <String>[
fs.path.join('some', 'path', 'to', 'iscreenshot'), fs.path.join('some', 'path', 'to', 'iscreenshot'),
fs.path.join('some', 'test', 'path', 'image.png') fs.path.join('some', 'test', 'path', 'image.png')
], ],
environment: null, environment: null,
workingDirectory: null workingDirectory: null
)); ));
}, }, overrides: <Type, Generator>{ProcessManager: () => mockProcessManager});
overrides: <Type, Generator>{ProcessManager: () => mockProcessManager}
);
}); });
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment