Skip to content

Commit

Permalink
fix: missing subtitle on target page changed view (#681)
Browse files Browse the repository at this point in the history
* Update tests to use snapshots

* Convert component to NamedSFC

* Add support for subtitle on TargetPageChangedView
  • Loading branch information
smoralesd authored and msft-github-bot committed May 17, 2019
1 parent 916b688 commit 925b9ff
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 79 deletions.
9 changes: 9 additions & 0 deletions src/DetailsView/Styles/detailsview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,15 @@ div.insights-file-issue-details-dialog-container {
font-size: 16px;
}
}
.target-page-changed {
.target-page-changed-subtitle {
color: $secondary-text;
max-width: 570px;
font-size: 14px;
margin-top: 4px;
margin-bottom: 16px;
}
}
.issues-table {
height: 100%;
width: 100%;
Expand Down
40 changes: 19 additions & 21 deletions src/DetailsView/components/target-page-changed-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Toggle } from 'office-ui-fabric-react/lib/Toggle';
import * as React from 'react';

import { DisplayableVisualizationTypeData } from '../../common/configs/visualization-configuration-factory';
import { NamedSFC } from '../../common/react/named-sfc';
import { VisualizationType } from '../../common/types/visualization-type';

export interface TargetPageChangedViewProps {
Expand All @@ -12,25 +13,22 @@ export interface TargetPageChangedViewProps {
toggleClickHandler: (event) => void;
}

export class TargetPageChangedView extends React.Component<TargetPageChangedViewProps, {}> {
public render(): JSX.Element {
const data = this.props.displayableData;
const title = data ? data.title : '';
const label = data ? data.toggleLabel : '';
export const TargetPageChangedView = NamedSFC<TargetPageChangedViewProps>('TargetPageChangedView', props => {
const { title = '', toggleLabel = '', subtitle } = props.displayableData;

return (
<div className="target-page-changed">
<h1>{title}</h1>
<Toggle
onText="On"
offText="Off"
checked={false}
onClick={this.props.toggleClickHandler}
label={label}
className="details-view-toggle"
/>
<p>The target page was changed. Use the toggle to enable the visualization in the current target page.</p>
</div>
);
}
}
return (
<div className="target-page-changed">
<h1>{title}</h1>
<div className="target-page-changed-subtitle">{subtitle}</div>
<Toggle
onText="On"
offText="Off"
checked={false}
onClick={props.toggleClickHandler}
label={toggleLabel}
className="details-view-toggle"
/>
<p>The target page was changed. Use the toggle to enable the visualization in the current target page.</p>
</div>
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TargetPageChangedView renders case { subtitle:
{ '$$typeof': Symbol(react.element),
type: 'span',
key: null,
ref: null,
props: { children: 'subtitle' },
_owner: null,
_store: { [validated]: false },
[_self]: null,
[_source]: null } } 1`] = `
<div
className="target-page-changed"
>
<h1>
</h1>
<div
className="target-page-changed-subtitle"
/>
<StyledToggleBase
checked={false}
className="details-view-toggle"
label=""
offText="Off"
onClick={[Function]}
onText="On"
/>
<p>
The target page was changed. Use the toggle to enable the visualization in the current target page.
</p>
</div>
`;

exports[`TargetPageChangedView renders case { title: 'title' } 1`] = `
<div
className="target-page-changed"
>
<h1>
title
</h1>
<div
className="target-page-changed-subtitle"
/>
<StyledToggleBase
checked={false}
className="details-view-toggle"
label=""
offText="Off"
onClick={[Function]}
onText="On"
/>
<p>
The target page was changed. Use the toggle to enable the visualization in the current target page.
</p>
</div>
`;

exports[`TargetPageChangedView renders case { title: 'title',
toggleLabel: 'toggle-label',
subtitle:
{ '$$typeof': Symbol(react.element),
type: 'span',
key: null,
ref: null,
props: { children: 'subtitle' },
_owner: null,
_store: { [validated]: false },
[_self]: null,
[_source]: null } } 1`] = `
<div
className="target-page-changed"
>
<h1>
title
</h1>
<div
className="target-page-changed-subtitle"
/>
<StyledToggleBase
checked={false}
className="details-view-toggle"
label="toggle-label"
offText="Off"
onClick={[Function]}
onText="On"
/>
<p>
The target page was changed. Use the toggle to enable the visualization in the current target page.
</p>
</div>
`;

exports[`TargetPageChangedView renders case { toggleLabel: 'toggle-label' } 1`] = `
<div
className="target-page-changed"
>
<h1>
</h1>
<div
className="target-page-changed-subtitle"
/>
<StyledToggleBase
checked={false}
className="details-view-toggle"
label="toggle-label"
offText="Off"
onClick={[Function]}
onText="On"
/>
<p>
The target page was changed. Use the toggle to enable the visualization in the current target page.
</p>
</div>
`;

exports[`TargetPageChangedView renders case {} 1`] = `
<div
className="target-page-changed"
>
<h1>
</h1>
<div
className="target-page-changed-subtitle"
/>
<StyledToggleBase
checked={false}
className="details-view-toggle"
label=""
offText="Off"
onClick={[Function]}
onText="On"
/>
<p>
The target page was changed. Use the toggle to enable the visualization in the current target page.
</p>
</div>
`;
Original file line number Diff line number Diff line change
@@ -1,68 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { Toggle } from 'office-ui-fabric-react/lib/Toggle';
import { shallow } from 'enzyme';
import * as React from 'react';

import { DisplayableVisualizationTypeData } from '../../../../../common/configs/visualization-configuration-factory';
import { VisualizationType } from '../../../../../common/types/visualization-type';
import { TargetPageChangedView, TargetPageChangedViewProps } from '../../../../../DetailsView/components/target-page-changed-view';

describe('TargetPageChangedView', () => {
const clickHandlerStub: () => void = () => {};

test('render TargetPageChangedView', () => {
const visualizationType = VisualizationType.Landmarks;
const displayableData = {
title: 'test title',
toggleLabel: 'test toggle label',
} as DisplayableVisualizationTypeData;

const props: TargetPageChangedViewProps = {
visualizationType: visualizationType,
toggleClickHandler: clickHandlerStub,
displayableData,
};
type RenderTestCases = {
title?: string;
toggleLabel?: string;
subtitle?: JSX.Element;
};

const targetPageChangedView = new TargetPageChangedView(props);

const expectedComponent = (
<div className="target-page-changed">
<h1>{displayableData.title}</h1>
<Toggle
onText="On"
offText="Off"
checked={false}
onClick={clickHandlerStub}
label={displayableData.toggleLabel}
className="details-view-toggle"
/>
<p>The target page was changed. Use the toggle to enable the visualization in the current target page.</p>
</div>
);

expect(targetPageChangedView.render()).toEqual(expectedComponent);
});

test('render TargetPageChangedView with unsupported type', () => {
const visualizationType = VisualizationType.Landmarks;
const displayableData = null;

const props: TargetPageChangedViewProps = {
visualizationType: visualizationType,
toggleClickHandler: clickHandlerStub,
displayableData,
};

const targetPageChangedView = new TargetPageChangedView(props);

const expectedComponent = (
<div className="target-page-changed">
<h1>{''}</h1>
<Toggle onText="On" offText="Off" checked={false} onClick={clickHandlerStub} label="" className="details-view-toggle" />
<p>The target page was changed. Use the toggle to enable the visualization in the current target page.</p>
</div>
);

expect(targetPageChangedView.render()).toEqual(expectedComponent);
describe('TargetPageChangedView', () => {
describe('renders', () => {
const clickHandlerStub: () => void = () => {};
const testCases: RenderTestCases[] = [
{},
{ title: 'title' },
{ toggleLabel: 'toggle-label' },
{ subtitle: <span>subtitle</span> },
{ title: 'title', toggleLabel: 'toggle-label', subtitle: <span>subtitle</span> },
];

it.each(testCases)('case %o', testCase => {
const { title = '', toggleLabel = '' } = testCase;

const visualizationType = VisualizationType.Landmarks;
const displayableData = { title, toggleLabel } as DisplayableVisualizationTypeData;

const props: TargetPageChangedViewProps = {
visualizationType,
displayableData,
toggleClickHandler: clickHandlerStub,
};

const wrapped = shallow(<TargetPageChangedView {...props} />);

expect(wrapped.getElement()).toMatchSnapshot();
});
});
});

0 comments on commit 925b9ff

Please sign in to comment.