-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ou item filter on App items was crashing Dashboards [DHIS2-9725] (…
…#1183) The path is a property on the filter object. Added unit tests for the component
- Loading branch information
1 parent
860104f
commit 614a42f
Showing
5 changed files
with
443 additions
and
9 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
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,117 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { render } from '@testing-library/react' | ||
import { Provider } from 'react-redux' | ||
import configureMockStore from 'redux-mock-store' | ||
|
||
import Item from '../Item' | ||
|
||
const mockStore = configureMockStore() | ||
|
||
const item = { | ||
appKey: 'scorecard', | ||
id: 'rainbowdash', | ||
shortened: false, | ||
} | ||
|
||
test('renders a valid App item in view mode', () => { | ||
const store = { | ||
itemFilters: {}, | ||
} | ||
const { container } = render( | ||
<Provider store={mockStore(store)}> | ||
<D2Provider> | ||
<Item item={item} dashboardMode={'view'} /> | ||
</D2Provider> | ||
</Provider> | ||
) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
|
||
test('renders a valid App item with filter in view mode', () => { | ||
const store = { | ||
itemFilters: { | ||
ou: [{ path: '/rainbow' }], | ||
}, | ||
} | ||
|
||
const { container } = render( | ||
<Provider store={mockStore(store)}> | ||
<D2Provider> | ||
<Item item={item} dashboardMode={'view'} /> | ||
</D2Provider> | ||
</Provider> | ||
) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
|
||
test('renders a valid App item with filter in edit mode', () => { | ||
const store = { | ||
itemFilters: { | ||
ou: [{ path: '/rainbow' }], | ||
}, | ||
} | ||
|
||
const { container } = render( | ||
<Provider store={mockStore(store)}> | ||
<D2Provider> | ||
<Item item={item} dashboardMode={'edit'} /> | ||
</D2Provider> | ||
</Provider> | ||
) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
|
||
test('renders an invalid App item', () => { | ||
const store = { | ||
itemFilters: { | ||
ou: [{ path: '/rainbow' }], | ||
}, | ||
} | ||
|
||
const invalidItem = { | ||
appKey: 'unknownApp', | ||
id: 'unknown', | ||
shortened: false, | ||
} | ||
|
||
const { container } = render( | ||
<Provider store={mockStore(store)}> | ||
<D2Provider> | ||
<Item item={invalidItem} dashboardMode={'edit'} /> | ||
</D2Provider> | ||
</Provider> | ||
) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
|
||
// Mock context provider | ||
class D2Provider extends React.Component { | ||
getChildContext() { | ||
return { | ||
d2: { | ||
system: { | ||
installedApps: [ | ||
{ | ||
key: 'scorecard', | ||
name: 'Scorecard', | ||
launchUrl: 'launchurl', | ||
}, | ||
], | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
render() { | ||
return this.props.children | ||
} | ||
} | ||
|
||
D2Provider.childContextTypes = { | ||
d2: PropTypes.object, | ||
} | ||
|
||
D2Provider.propTypes = { | ||
children: PropTypes.node, | ||
} |
124 changes: 124 additions & 0 deletions
124
src/components/Item/AppItem/__tests__/__snapshots__/Item.spec.js.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,124 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders a valid App item in view mode 1`] = ` | ||
<div> | ||
<div | ||
class="itemHeaderWrap" | ||
> | ||
<p | ||
class="itemTitle" | ||
> | ||
Scorecard | ||
</p> | ||
</div> | ||
<hr | ||
style="background-color: rgb(243, 245, 247); height: 1px; margin: 0px 0px 5px 0px;" | ||
/> | ||
<iframe | ||
class="dashboard-item-content" | ||
src="launchurl?dashboardItemId=rainbowdash" | ||
title="Scorecard" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`renders a valid App item with filter in edit mode 1`] = ` | ||
<div> | ||
<div | ||
class="itemHeaderWrap" | ||
> | ||
<p | ||
class="itemTitle" | ||
> | ||
Scorecard | ||
</p> | ||
<div | ||
class="itemActionsWrap" | ||
> | ||
<button | ||
class="deleteItemButton" | ||
title="Delete item" | ||
type="button" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
class="MuiSvgIcon-root-1" | ||
focusable="false" | ||
role="presentation" | ||
style="fill: #d32f2f;" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" | ||
/> | ||
</svg> | ||
</button> | ||
</div> | ||
</div> | ||
<hr | ||
style="background-color: rgb(243, 245, 247); height: 1px; margin: 0px 0px 5px 0px;" | ||
/> | ||
<iframe | ||
class="dashboard-item-content" | ||
src="launchurl?dashboardItemId=rainbowdash" | ||
title="Scorecard" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`renders a valid App item with filter in view mode 1`] = ` | ||
<div> | ||
<div | ||
class="itemHeaderWrap" | ||
> | ||
<p | ||
class="itemTitle" | ||
> | ||
Scorecard | ||
</p> | ||
</div> | ||
<hr | ||
style="background-color: rgb(243, 245, 247); height: 1px; margin: 0px 0px 5px 0px;" | ||
/> | ||
<iframe | ||
class="dashboard-item-content" | ||
src="launchurl?dashboardItemId=rainbowdash&userOrgUnit=rainbow" | ||
title="Scorecard" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`renders an invalid App item 1`] = ` | ||
<div> | ||
<div | ||
class="itemHeaderWrap" | ||
> | ||
<p | ||
class="itemTitle" | ||
> | ||
unknownApp app not found | ||
</p> | ||
</div> | ||
<hr | ||
style="background-color: rgb(243, 245, 247); height: 1px; margin: 0px 0px 5px 0px;" | ||
/> | ||
<div | ||
class="dashboard-item-content" | ||
style="display: flex; justify-content: center; align-items: center; height: 90%;" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
class="MuiSvgIcon-root-10 MuiSvgIcon-colorDisabled-15" | ||
disabled="" | ||
focusable="false" | ||
role="presentation" | ||
style="width: 100px; height: 100px;" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8 0-1.85.63-3.55 1.69-4.9L16.9 18.31C15.55 19.37 13.85 20 12 20zm6.31-3.1L7.1 5.69C8.45 4.63 10.15 4 12 4c4.42 0 8 3.58 8 8 0 1.85-.63 3.55-1.69 4.9z" | ||
/> | ||
</svg> | ||
</div> | ||
</div> | ||
`; |
Oops, something went wrong.