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 actions to install-service step #2882

Merged
merged 1 commit into from
Jun 15, 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,15 @@ import { AndroidSetupStepLayout, AndroidSetupStepLayoutProps } from './android-s
import { CommonAndroidSetupStepProps } from './android-setup-types';
import * as styles from './prompt-install-service-step.scss';

export const installAutomationId = 'install';
export const PromptInstallServiceStep = NamedFC<CommonAndroidSetupStepProps>(
'PromptInstallServiceStep',
(props: CommonAndroidSetupStepProps) => {
const onCancelButton = () => {
// To be implemented in future feature work
console.log(`androidSetupActionCreator.cancel()`);
};

const onInstallButton = () => {
// To be implemented in future feature work
console.log(`androidSetupActionCreator.installService()`);
};

const layoutProps: AndroidSetupStepLayoutProps = {
headerText: 'Let us install the latest version on your device',
leftFooterButtonProps: {
text: 'Cancel',
onClick: onCancelButton,
onClick: _ => props.deps.androidSetupActionCreator.cancel(),
},
rightFooterButtonProps: {
text: 'Next',
Expand All @@ -49,7 +40,11 @@ export const PromptInstallServiceStep = NamedFC<CommonAndroidSetupStepProps>(
either missing or out of date. We'll need to install the latest version.
</>
<DeviceDescription {...descriptionProps}></DeviceDescription>
<PrimaryButton text="Install" onClick={onInstallButton} />
<PrimaryButton
text="Install"
data-automation-id={installAutomationId}
onClick={props.deps.androidSetupActionCreator.next}
/>
</AndroidSetupStepLayout>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ exports[`PromptInstallServiceStep renders with device 1`] = `
isEmulator={false}
/>
<CustomizedPrimaryButton
data-automation-id="install"
onClick={[Function]}
text="Install"
/>
Expand Down Expand Up @@ -60,6 +61,7 @@ exports[`PromptInstallServiceStep renders with emulator 1`] = `
isEmulator={true}
/>
<CustomizedPrimaryButton
data-automation-id="install"
onClick={[Function]}
text="Install"
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { AndroidSetupActionCreator } from 'electron/flux/action-creator/android-setup-action-creator';
import { DeviceInfo } from 'electron/platform/android/android-service-configurator';
import { AndroidSetupStepLayout } from 'electron/views/device-connect-view/components/android-setup/android-setup-step-layout';
import { CommonAndroidSetupStepProps } from 'electron/views/device-connect-view/components/android-setup/android-setup-types';
import { PromptInstallServiceStep } from 'electron/views/device-connect-view/components/android-setup/prompt-install-service-step';
import {
installAutomationId,
PromptInstallServiceStep,
} from 'electron/views/device-connect-view/components/android-setup/prompt-install-service-step';
import { shallow } from 'enzyme';
import * as React from 'react';
import { AndroidSetupStepPropsBuilder } from 'tests/unit/common/android-setup-step-props-builder';
import { IMock, Mock, Times } from 'typemoq';

describe('PromptInstallServiceStep', () => {
let props: CommonAndroidSetupStepProps;
let androidSetupActionCreatorMock: IMock<AndroidSetupActionCreator>;

beforeEach(() => {
props = new AndroidSetupStepPropsBuilder('prompt-install-service').build();
androidSetupActionCreatorMock = Mock.ofType(AndroidSetupActionCreator);
props = new AndroidSetupStepPropsBuilder('prompt-install-service')
.withDep('androidSetupActionCreator', androidSetupActionCreatorMock.object)
.build();
});

it('renders with device', () => {
Expand Down Expand Up @@ -39,4 +49,17 @@ describe('PromptInstallServiceStep', () => {
const rendered = shallow(<PromptInstallServiceStep {...props} />);
expect(rendered.getElement()).toMatchSnapshot();
});

it('calls cancel action when cancel button selected', () => {
const rendered = shallow(<PromptInstallServiceStep {...props} />);
const stubEvent = {} as React.MouseEvent<HTMLButtonElement>;
rendered.find(AndroidSetupStepLayout).prop('leftFooterButtonProps').onClick(stubEvent);
androidSetupActionCreatorMock.verify(m => m.cancel(), Times.once());
});

it('handles the install button with the next action', () => {
const rendered = shallow(<PromptInstallServiceStep {...props} />);
rendered.find({ 'data-automation-id': installAutomationId }).simulate('click');
androidSetupActionCreatorMock.verify(m => m.next(), Times.once());
});
});