-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android-setup): Create three state machine steps (#2865)
* feat(android-setup): Add prompt-locate-adb state machine step * feat(android-setup): Add prompt-connect-to-device state machine step * feat(android-setup): Add detect-devices state machine step * feat(android-setup): Add new step configs to allAndroidSetupStateMachineConfigs
- Loading branch information
Showing
9 changed files
with
221 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/electron/platform/android/setup/steps/detect-devices.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { AndroidSetupStepConfig } from 'electron/platform/android/setup/android-setup-steps-configs'; | ||
|
||
export const detectDevices: AndroidSetupStepConfig = deps => { | ||
return { | ||
actions: { | ||
cancel: () => { | ||
deps.stepTransition('prompt-connect-to-device'); | ||
}, | ||
}, | ||
onEnter: async () => { | ||
const devices = await deps.getDevices(); | ||
|
||
switch (devices.length) { | ||
case 0: { | ||
deps.stepTransition('prompt-connect-to-device'); | ||
break; | ||
} | ||
case 1: { | ||
deps.setSelectedDeviceId(devices[0].id); | ||
deps.stepTransition('detect-service'); | ||
break; | ||
} | ||
default: { | ||
deps.stepTransition('prompt-choose-device'); | ||
break; | ||
} | ||
} | ||
}, | ||
}; | ||
}; |
12 changes: 12 additions & 0 deletions
12
src/electron/platform/android/setup/steps/prompt-connect-to-device.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { AndroidSetupStepConfig } from 'electron/platform/android/setup/android-setup-steps-configs'; | ||
|
||
export const promptConnectToDevice: AndroidSetupStepConfig = deps => { | ||
return { | ||
actions: { | ||
next: () => deps.stepTransition('detect-devices'), | ||
}, | ||
}; | ||
}; |
15 changes: 15 additions & 0 deletions
15
src/electron/platform/android/setup/steps/prompt-locate-adb.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { AndroidSetupStepConfig } from 'electron/platform/android/setup/android-setup-steps-configs'; | ||
|
||
export const promptLocateAdb: AndroidSetupStepConfig = deps => { | ||
return { | ||
actions: { | ||
saveAdbPath: (path: string) => { | ||
deps.setAdbPath(path); | ||
deps.stepTransition('prompt-connect-to-device'); | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/tests/unit/tests/electron/platform/android/setup/steps/detect-devices.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { DeviceInfo } from 'electron/platform/android/android-service-configurator'; | ||
import { AndroidSetupStepConfigDeps } from 'electron/platform/android/setup/android-setup-steps-configs'; | ||
import { detectDevices } from 'electron/platform/android/setup/steps/detect-devices'; | ||
import { Mock, MockBehavior, Times } from 'typemoq'; | ||
import { checkExpectedActionsAreDefined } from './actions-tester'; | ||
|
||
describe('Android setup step: detectDevices', () => { | ||
it('has expected properties', () => { | ||
const deps = {} as AndroidSetupStepConfigDeps; | ||
const step = detectDevices(deps); | ||
checkExpectedActionsAreDefined(step, ['cancel']); | ||
expect(step.onEnter).toBeDefined(); | ||
}); | ||
|
||
it('cancel transitions to prompt-connect-to-device as expected', () => { | ||
const depsMock = Mock.ofType<AndroidSetupStepConfigDeps>(undefined, MockBehavior.Strict); | ||
depsMock.setup(m => m.stepTransition('prompt-connect-to-device')).verifiable(Times.once()); | ||
|
||
const step = detectDevices(depsMock.object); | ||
step.actions.cancel(); | ||
|
||
depsMock.verifyAll(); | ||
}); | ||
|
||
it('onEnter transitions to prompt-connect-to-device as expected', async () => { | ||
const devices: DeviceInfo[] = []; | ||
const p = new Promise<DeviceInfo[]>(resolve => resolve(devices)); | ||
|
||
const depsMock = Mock.ofType<AndroidSetupStepConfigDeps>(undefined, MockBehavior.Strict); | ||
depsMock | ||
.setup(m => m.getDevices()) | ||
.returns(_ => p) | ||
.verifiable(Times.once()); | ||
|
||
depsMock.setup(m => m.stepTransition('prompt-connect-to-device')).verifiable(Times.once()); | ||
|
||
const step = detectDevices(depsMock.object); | ||
await step.onEnter(); | ||
|
||
depsMock.verifyAll(); | ||
}); | ||
|
||
it('onEnter transitions to detect-service as expected', async () => { | ||
const devices: DeviceInfo[] = [ | ||
{ | ||
id: 'device1', | ||
} as DeviceInfo, | ||
]; | ||
|
||
const p = new Promise<DeviceInfo[]>(resolve => resolve(devices)); | ||
|
||
const depsMock = Mock.ofType<AndroidSetupStepConfigDeps>(undefined, MockBehavior.Strict); | ||
depsMock | ||
.setup(m => m.getDevices()) | ||
.returns(_ => p) | ||
.verifiable(Times.once()); | ||
|
||
depsMock.setup(m => m.stepTransition('detect-service')).verifiable(Times.once()); | ||
depsMock.setup(m => m.setSelectedDeviceId('device1')).verifiable(Times.once()); | ||
|
||
const step = detectDevices(depsMock.object); | ||
await step.onEnter(); | ||
|
||
depsMock.verifyAll(); | ||
}); | ||
|
||
it('onEnter transitions to prompt-choose-device as expected', async () => { | ||
const devices: DeviceInfo[] = [ | ||
{ | ||
id: 'device1', | ||
} as DeviceInfo, | ||
{ | ||
id: 'device2', | ||
} as DeviceInfo, | ||
]; | ||
|
||
const p = new Promise<DeviceInfo[]>(resolve => resolve(devices)); | ||
|
||
const depsMock = Mock.ofType<AndroidSetupStepConfigDeps>(undefined, MockBehavior.Strict); | ||
depsMock | ||
.setup(m => m.getDevices()) | ||
.returns(_ => p) | ||
.verifiable(Times.once()); | ||
|
||
depsMock.setup(m => m.stepTransition('prompt-choose-device')).verifiable(Times.once()); | ||
|
||
const step = detectDevices(depsMock.object); | ||
await step.onEnter(); | ||
|
||
depsMock.verifyAll(); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
src/tests/unit/tests/electron/platform/android/setup/steps/prompt-connect-to-device.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { AndroidSetupStepConfigDeps } from 'electron/platform/android/setup/android-setup-steps-configs'; | ||
import { promptConnectToDevice } from 'electron/platform/android/setup/steps/prompt-connect-to-device'; | ||
import { Mock, MockBehavior, Times } from 'typemoq'; | ||
import { checkExpectedActionsAreDefined } from './actions-tester'; | ||
|
||
describe('Android setup step: promptConnectToDevice', () => { | ||
it('has expected properties', () => { | ||
const deps = {} as AndroidSetupStepConfigDeps; | ||
const step = promptConnectToDevice(deps); | ||
checkExpectedActionsAreDefined(step, ['next']); | ||
expect(step.onEnter).not.toBeDefined(); | ||
}); | ||
|
||
it('next transitions to detect-devices as expected', () => { | ||
const depsMock = Mock.ofType<AndroidSetupStepConfigDeps>(undefined, MockBehavior.Strict); | ||
depsMock.setup(m => m.stepTransition('detect-devices')).verifiable(Times.once()); | ||
|
||
const step = promptConnectToDevice(depsMock.object); | ||
step.actions.next(); | ||
|
||
depsMock.verifyAll(); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
src/tests/unit/tests/electron/platform/android/setup/steps/prompt-locate-adb.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { AndroidSetupStepConfigDeps } from 'electron/platform/android/setup/android-setup-steps-configs'; | ||
import { promptLocateAdb } from 'electron/platform/android/setup/steps/prompt-locate-adb'; | ||
import { Mock, MockBehavior, Times } from 'typemoq'; | ||
import { checkExpectedActionsAreDefined } from './actions-tester'; | ||
|
||
describe('Android setup step: promptLocateAdb', () => { | ||
it('has expected properties', () => { | ||
const deps = {} as AndroidSetupStepConfigDeps; | ||
const step = promptLocateAdb(deps); | ||
checkExpectedActionsAreDefined(step, ['saveAdbPath']); | ||
expect(step.onEnter).not.toBeDefined(); | ||
}); | ||
|
||
it('saveAdbPath transitions to prompt-connect-to-device as expected', () => { | ||
const testPath = 'my test path'; | ||
|
||
const depsMock = Mock.ofType<AndroidSetupStepConfigDeps>(undefined, MockBehavior.Strict); | ||
depsMock.setup(m => m.setAdbPath(testPath)).verifiable(Times.once()); | ||
depsMock.setup(m => m.stepTransition('prompt-connect-to-device')).verifiable(Times.once()); | ||
|
||
const step = promptLocateAdb(depsMock.object); | ||
step.actions.saveAdbPath(testPath); | ||
|
||
depsMock.verifyAll(); | ||
}); | ||
}); |