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(nav-bar-content): remove update-handler from ReflowAssessmentView #2699

Merged
merged 1 commit into from
May 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
24 changes: 2 additions & 22 deletions src/DetailsView/components/reflow-assessment-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
// Licensed under the MIT License.
import * as React from 'react';

import {
AssessmentViewUpdateHandler,
AssessmentViewUpdateHandlerDeps,
AssessmentViewUpdateHandlerProps,
} from 'DetailsView/components/assessment-view-update-handler';
import { AssessmentTestResult } from '../../common/assessment/assessment-test-result';
import { Tab } from '../../common/itab';
import {
Expand All @@ -17,10 +12,7 @@ import {
import { GettingStartedView } from './getting-started-view';
import { TargetChangeDialog, TargetChangeDialogDeps } from './target-change-dialog';

export type ReflowAssessmentViewDeps = {
assessmentViewUpdateHandler: AssessmentViewUpdateHandler;
} & AssessmentViewUpdateHandlerDeps &
TargetChangeDialogDeps;
export type ReflowAssessmentViewDeps = TargetChangeDialogDeps;

export type ReflowAssessmentViewProps = {
deps: ReflowAssessmentViewDeps;
Expand All @@ -29,7 +21,7 @@ export type ReflowAssessmentViewProps = {
currentTarget: Tab;
prevTarget: PersistedTabInfo;
assessmentTestResult: AssessmentTestResult;
} & AssessmentViewUpdateHandlerProps;
};

export class ReflowAssessmentView extends React.Component<ReflowAssessmentViewProps> {
public render(): JSX.Element {
Expand All @@ -47,18 +39,6 @@ export class ReflowAssessmentView extends React.Component<ReflowAssessmentViewPr
return null;
}

public componentDidMount(): void {
this.props.deps.assessmentViewUpdateHandler.onMount(this.props);
}

public componentDidUpdate(prevProps: ReflowAssessmentViewProps): void {
this.props.deps.assessmentViewUpdateHandler.update(prevProps, this.props);
}

public componentWillUnmount(): void {
this.props.deps.assessmentViewUpdateHandler.onUnmount(this.props);
}

private renderTargetChangeDialog(): JSX.Element {
return (
<TargetChangeDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
exports[`AssessmentViewTest render for gettting started 1`] = `
<div>
<TargetChangeDialog
deps={
Object {
"assessmentViewUpdateHandler": proxy {
"___id": "BCDF5CE5-F0DF-40B7-8BA0-69DF395033C8",
},
}
}
deps={Object {}}
newTab={
Object {
"id": 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@ import { AssessmentTestResult } from 'common/assessment/assessment-test-result';
import { AssessmentData } from 'common/types/store-data/assessment-result-data';
import { shallow } from 'enzyme';
import * as React from 'react';
import { IMock, Mock, Times } from 'typemoq';
import { Mock } from 'typemoq';

import { AssessmentViewUpdateHandler } from 'DetailsView/components/assessment-view-update-handler';
import {
ReflowAssessmentView,
ReflowAssessmentViewDeps,
ReflowAssessmentViewProps,
} from '../../../../../DetailsView/components/reflow-assessment-view';

describe('AssessmentViewTest', () => {
let updateHandlerMock: IMock<AssessmentViewUpdateHandler>;

beforeEach(() => {
updateHandlerMock = Mock.ofType(AssessmentViewUpdateHandler);
});

test('render for requirement', () => {
const props = generateProps('requirement');
const rendered = shallow(<ReflowAssessmentView {...props} />);
Expand All @@ -32,37 +25,6 @@ describe('AssessmentViewTest', () => {
expect(rendered.getElement()).toMatchSnapshot();
});

test('componentDidMount', () => {
const props = generateProps('requirement');
updateHandlerMock.setup(u => u.onMount(props)).verifiable(Times.once());
const testObject = new ReflowAssessmentView(props);

testObject.componentDidMount();

updateHandlerMock.verifyAll();
});

test('componentWillUnmount', () => {
const props = generateProps('requirement');
updateHandlerMock.setup(u => u.onUnmount(props)).verifiable(Times.once());
const testObject = new ReflowAssessmentView(props);

testObject.componentWillUnmount();

updateHandlerMock.verifyAll();
});

test('componentDidUpdate', () => {
const prevProps = generateProps('requirement1');
const props = generateProps('requirement2');
updateHandlerMock.setup(u => u.update(prevProps, props)).verifiable(Times.once());
const testObject = new ReflowAssessmentView(props);

testObject.componentDidUpdate(prevProps);

updateHandlerMock.verifyAll();
});

function generateProps(subview: string): ReflowAssessmentViewProps {
const assessmentDataMock = Mock.ofType<AssessmentData>();

Expand All @@ -73,9 +35,7 @@ describe('AssessmentViewTest', () => {
} as AssessmentTestResult;

const reflowProps = {
deps: {
assessmentViewUpdateHandler: updateHandlerMock.object,
} as ReflowAssessmentViewDeps,
deps: {} as ReflowAssessmentViewDeps,
prevTarget: { id: 4 },
currentTarget: { id: 5 },
assessmentNavState: {
Expand Down