-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: missing subtitle on target page changed view (#681)
* Update tests to use snapshots * Convert component to NamedSFC * Add support for subtitle on TargetPageChangedView
- Loading branch information
1 parent
916b688
commit 925b9ff
Showing
4 changed files
with
202 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
...ts/unit/tests/DetailsView/components/__snapshots__/target-page-changed-view.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
`; |
91 changes: 33 additions & 58 deletions
91
src/tests/unit/tests/DetailsView/components/target-page-changed-view.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |