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): Fix adbLocation-related problems #2900

Merged
merged 2 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.
import { getStoreStateMessage, Messages } from '../../../common/messages';
import { StoreNames } from '../../../common/stores/store-names';
import { SetTelemetryStatePayload } from '../../actions/action-payloads';
import { SetAdbLocationPayload, SetTelemetryStatePayload } from '../../actions/action-payloads';
import { Interpreter } from '../../interpreter';
import { UserConfigurationActionCreator } from '../user-configuration-action-creator';

Expand Down Expand Up @@ -38,8 +38,8 @@ export const registerUserConfigurationMessageCallback = (
Messages.UserConfig.SaveIssueFilingSettings,
userConfigurationActionCreator.saveIssueFilingSettings,
);
interpreter.registerTypeToPayloadCallback(
interpreter.registerTypeToPayloadCallback<SetAdbLocationPayload>(
Messages.UserConfig.SetAdbLocationConfig,
userConfigurationActionCreator.setAdbLocation,
payload => userConfigurationActionCreator.setAdbLocation(payload.adbLocation),
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
import { UserConfigurationActions } from '../actions/user-configuration-actions';

export class UserConfigurationActionCreator {
private readonly currentScope: string = 'UserConfigurationActionCreator';

constructor(private readonly userConfigActions: UserConfigurationActions) {}

public getUserConfigurationState = () => this.userConfigActions.getCurrentState.invoke(null);
Expand All @@ -33,5 +35,5 @@ export class UserConfigurationActionCreator {
this.userConfigActions.saveIssueFilingSettings.invoke(payload);

public setAdbLocation = (adbLocation: string) =>
this.userConfigActions.setAdbLocation.invoke(adbLocation);
this.userConfigActions.setAdbLocation.invoke(adbLocation, this.currentScope);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const promptLocateAdb: AndroidSetupStepConfig = deps => {
actions: {
saveAdbPath: (path: string) => {
deps.setAdbPath(path);
deps.stepTransition('prompt-connect-to-device');
deps.stepTransition('detect-adb');
Copy link
Contributor Author

@DaveTryon DaveTryon Jun 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The steps must successfully go through the detect-adb step before progressing to anything that needs ADB. This path was allowing us to try to prompt for devices without a validated ADB

},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ import { Action } from 'common/flux/action';
import { isFunction } from 'lodash';
import { IMock, It, Mock, Times } from 'typemoq';

export const createActionMock = <Payload>(payload: Payload): IMock<Action<Payload>> => {
export const createActionMock = <Payload>(
payload: Payload,
scope: string = null,
): IMock<Action<Payload>> => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows us to mock the invocation with the specified scope

const actionMock = Mock.ofType<Action<Payload>>(Action);
actionMock.setup(action => action.invoke(payload)).verifiable(Times.once());
if (scope) {
actionMock.setup(action => action.invoke(payload, scope)).verifiable(Times.once());
} else {
actionMock.setup(action => action.invoke(payload)).verifiable(Times.once());
}
return actionMock;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ describe('UserConfigurationActionCreator', () => {
it('should SetAdbLocation Message', () => {
const expectedAdbLocation = 'Somewhere over the rainbow';

const setAdbLocationConfigMock = createActionMock(expectedAdbLocation);
const setAdbLocationConfigMock = createActionMock(
expectedAdbLocation,
'UserConfigurationActionCreator',
);
const actionsMock = createActionsMock('setAdbLocation', setAdbLocationConfigMock.object);
const testSubject = new UserConfigurationActionCreator(actionsMock.object);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Android setup step: promptLocateAdb', () => {

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());
depsMock.setup(m => m.stepTransition('detect-adb')).verifiable(Times.once());

const step = promptLocateAdb(depsMock.object);
step.actions.saveAdbPath(testPath);
Expand Down