-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(android-setup): Create three state machine steps #2865
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
05eb185
feat(android-setup): Add prompt-locate-adb state machine step
RobGallo 3404dce
feat(android-setup): Add prompt-connect-to-device state machine step
RobGallo 7aec111
feat(android-setup): Add detect-devices state machine step
RobGallo e187460
feat(android-setup): Add new step configs to allAndroidSetupStateMach…
RobGallo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confusion here was because it wasn't clear what hasAdbPath was doing. I read it as "is there a path in the store" when it really means "Do we have a validated ADB location?" The underlying code will decide based on whether or not the AndroidServiceConfiguratorFactory was able to return an AndroidServiceConfigurator