Skip to content
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): Add cancel action behavior to a few steps #2929

Merged
merged 3 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/electron/platform/android/setup/steps/detect-devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { AndroidSetupStepConfig } from 'electron/platform/android/setup/android-

export const detectDevices: AndroidSetupStepConfig = deps => {
return {
actions: {
cancel: () => {
deps.stepTransition('prompt-connect-to-device');
},
},
actions: {},
onEnter: async () => {
deps.setSelectedDevice(null);
deps.setAvailableDevices([]);
Expand All @@ -24,6 +20,7 @@ export const detectDevices: AndroidSetupStepConfig = deps => {
case 1: {
deps.setSelectedDeviceId(devices[0].id);
deps.setSelectedDevice(devices[0]);
deps.setAvailableDevices(devices);
deps.stepTransition('detect-service');
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { AndroidSetupStepConfig } from 'electron/platform/android/setup/android-
export const promptConfiguringPortForwardingFailed: AndroidSetupStepConfig = deps => {
return {
actions: {
cancel: () => {
deps.stepTransition('prompt-choose-device');
},
next: () => deps.stepTransition('configuring-port-forwarding'),
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { AndroidSetupStepConfig } from 'electron/platform/android/setup/android-

export const promptGrantPermissions: AndroidSetupStepConfig = deps => ({
actions: {
cancel: () => {
deps.stepTransition('prompt-choose-device');
},
next: () => {
deps.stepTransition('detect-permissions');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { AndroidSetupStepConfig } from 'electron/platform/android/setup/android-

export const promptInstallService: AndroidSetupStepConfig = deps => ({
actions: {
cancel: () => {
deps.stepTransition('prompt-choose-device');
},
next: () => {
deps.stepTransition('installing-service');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,10 @@ describe('Android setup step: detectDevices', () => {
it('has expected properties', () => {
const deps = {} as AndroidSetupStepConfigDeps;
const step = detectDevices(deps);
checkExpectedActionsAreDefined(step, ['cancel']);
checkExpectedActionsAreDefined(step, []);
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));
Expand Down Expand Up @@ -64,6 +54,7 @@ describe('Android setup step: detectDevices', () => {
depsMock.setup(m => m.setAvailableDevices([])).verifiable(Times.once());
depsMock.setup(m => m.setSelectedDeviceId('device1')).verifiable(Times.once());
depsMock.setup(m => m.setSelectedDevice(devices[0])).verifiable(Times.once());
depsMock.setup(m => m.setAvailableDevices(devices)).verifiable(Times.once());
depsMock.setup(m => m.stepTransition('detect-service')).verifiable(Times.once());

const step = detectDevices(depsMock.object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ describe('Android setup step: promptConfiguringPortForwardingFailed', () => {
it('has expected properties', () => {
const deps = {} as AndroidSetupStepConfigDeps;
const step = promptConfiguringPortForwardingFailed(deps);
checkExpectedActionsAreDefined(step, ['next']);
checkExpectedActionsAreDefined(step, ['cancel', 'next']);
expect(step.onEnter).not.toBeDefined();
});

it('cancel transitions to prompt-choose-device', async () => {
const depsMock = Mock.ofType<AndroidSetupStepConfigDeps>(undefined, MockBehavior.Strict);
depsMock.setup(m => m.stepTransition('prompt-choose-device')).verifiable(Times.once());

const step = promptConfiguringPortForwardingFailed(depsMock.object);
step.actions.cancel();

depsMock.verifyAll();
});

it('next transitions to configuring-port-forwarding as expected', () => {
const depsMock = Mock.ofType<AndroidSetupStepConfigDeps>(undefined, MockBehavior.Strict);
depsMock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ describe('Android setup step: promptGrantPermissions', () => {
it('has expected properties', () => {
const deps = {} as AndroidSetupStepConfigDeps;
const step = promptGrantPermissions(deps);
checkExpectedActionsAreDefined(step, ['next']);
checkExpectedActionsAreDefined(step, ['cancel', 'next']);
expect(step.onEnter).not.toBeDefined();
});

it('cancel transitions to prompt-choose-device', async () => {
const depsMock = Mock.ofType<AndroidSetupStepConfigDeps>(undefined, MockBehavior.Strict);
depsMock.setup(m => m.stepTransition('prompt-choose-device')).verifiable(Times.once());

const step = promptGrantPermissions(depsMock.object);
step.actions.cancel();

depsMock.verifyAll();
});

it('onEnter transitions to detect-permissions as expected', () => {
const depsMock = Mock.ofType<AndroidSetupStepConfigDeps>(undefined, MockBehavior.Strict);
depsMock.setup(m => m.stepTransition('detect-permissions')).verifiable(Times.once());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ describe('Android setup step: promptInstallService', () => {
it('has expected properties', () => {
const deps = {} as AndroidSetupStepConfigDeps;
const step = promptInstallService(deps);
checkExpectedActionsAreDefined(step, ['next']);
checkExpectedActionsAreDefined(step, ['cancel', 'next']);
expect(step.onEnter).not.toBeDefined();
});

it('cancel transitions to prompt-choose-device', async () => {
const depsMock = Mock.ofType<AndroidSetupStepConfigDeps>(undefined, MockBehavior.Strict);
depsMock.setup(m => m.stepTransition('prompt-choose-device')).verifiable(Times.once());

const step = promptInstallService(depsMock.object);
step.actions.cancel();

depsMock.verifyAll();
});

it('onEnter transitions to installing-service as expected', () => {
const depsMock = Mock.ofType<AndroidSetupStepConfigDeps>(undefined, MockBehavior.Strict);
depsMock.setup(m => m.stepTransition('installing-service')).verifiable(Times.once());
Expand Down