Skip to content

Commit b5d33fe

Browse files
authored
Improve test coverage (#44)
* Improve test coverage * Imrpove test coverage * Improve test coverage * 100% test coverage * Fix warnings * Add todo test * thumbnail prop description from master * proptype
1 parent 26e854d commit b5d33fe

40 files changed

+1217
-121
lines changed

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@
150150
],
151151
"moduleNameMapper": {
152152
"react-storefront/(.*)": "<rootDir>/src/$1"
153-
},
154-
"roots": [
155-
"test"
156-
]
153+
}
157154
}
158155
}

src/carousel/MagnifyHint.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,6 @@ MagnifyHint.propTypes = {
178178
*/
179179
expandTextDesktop: PropTypes.string,
180180

181-
/**
182-
* If `true`, the Carousel is currently being hovered upon.
183-
*/
184-
open: PropTypes.bool,
185-
186181
/**
187182
* If `true`, zooming is disabled and the hint for zooming is not shown.
188183
*/

src/carousel/MediaCarousel.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function MediaCarousel(props) {
212212
onLoad={i === 0 ? onFullSizeImagesLoaded : null}
213213
magnifyProps={magnifyProps}
214214
{...item}
215-
magnify={lightboxActive && !isSmall ? false : item.magnify}
215+
magnify={isSmall ? undefined : item.magnify}
216216
imageProps={
217217
lightboxActive && !isSmall
218218
? {
@@ -255,18 +255,9 @@ MediaCarousel.propTypes = {
255255
classes: PropTypes.object,
256256

257257
/**
258-
* Array of objects containing the data for an image to be used for thumbnails. If `false`, no
259-
* thumbnails will be displayed.
258+
* If `true`, the carousel will have thumbnails below it.
260259
*/
261-
thumbnails: PropTypes.oneOfType([
262-
PropTypes.arrayOf(
263-
PropTypes.shape({
264-
src: PropTypes.string,
265-
alt: PropTypes.string,
266-
}),
267-
),
268-
PropTypes.bool,
269-
]),
260+
thumbnails: PropTypes.bool,
270261
/**
271262
* Data for an image to be used for a thumbnail when the images are not yet loaded.
272263
*/

src/drawer/Drawer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export default function Drawer({
123123
drawerResize.current = new ResizeObserver(() => {
124124
document.body.style.paddingBottom = el && el.clientHeight + 'px'
125125
})
126-
drawerResize.observe(el)
126+
drawerResize.current.observe(el)
127127
}
128128

129129
return () => {

src/drawer/DrawerCloseButton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default function DrawerCloseButton({
7373
ButtonElement = IconButton
7474
} else {
7575
ButtonElement = props => (
76-
<Fab color="primary" className={clsx(!open && classes.hidden)} {...props}>
76+
<Fab color="primary" {...props} className={clsx(props.className, !open && classes.hidden)}>
7777
<Icon />
7878
</Fab>
7979
)

src/drawer/DrawerContext.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/menu/MenuLeaf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function MenuLeaf({ item, trackSelected, ...others }) {
1212
as={item.as}
1313
className={classes.link}
1414
server={item.server}
15-
state={item.state ? () => JSON.parse(item.state) : null}
15+
pageData={item.pageData ? item.pageData : null}
1616
onClick={close}
1717
>
1818
<a>

src/nav/NavTab.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function NavTab({ classes, href, as, prefetch, children, ...props }) {
9494
const menuItemBlurPending = useRef(false)
9595

9696
// accessibility: open the menu when the user presses enter with the tab focused
97-
const handleTabKeyDown = useCallback(e => {
97+
const handleEnterKeyDown = useCallback(e => {
9898
if (e.key === 'Enter') {
9999
e.preventDefault()
100100
setAnchorEl(e.currentTarget)
@@ -108,11 +108,7 @@ function NavTab({ classes, href, as, prefetch, children, ...props }) {
108108
// So we need to let the event loop finish one cycle to see if another item in the menu receives focus before
109109
// determining that the menu has lost focus and should be closed.
110110
menuItemBlurPending.current = false
111-
112-
if (!focused) {
113-
setFocused(true)
114-
}
115-
}, [focused])
111+
}, [])
116112

117113
// When a menu item loses focus, we close the menu if another menu item doesn't immediately gain focus
118114
const handleMenuItemBlur = useCallback(() => {
@@ -153,7 +149,7 @@ function NavTab({ classes, href, as, prefetch, children, ...props }) {
153149
prefetch={prefetch}
154150
>
155151
<Tab
156-
onKeyDown={handleTabKeyDown}
152+
onKeyDown={handleEnterKeyDown}
157153
classes={{ root: classes.tab }}
158154
aria-haspopup={children != null}
159155
aria-expanded={open}

src/plp/SortButton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function SortButton({ title, drawerProps, onClick, sortProps, drawerBreakpoint,
4949
if (open) {
5050
setState({ mountDrawer: true, open: true, anchorEl: anchorEl })
5151
} else {
52-
setState({ open: false, anchorEl: null })
52+
setState({ ...state, open: false, anchorEl: null })
5353
}
5454
}
5555

src/props/createLazyProps.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* }, { timeout: 50 })
4444
* ```
4545
*
46-
* @param {Function} createApiUrl A function to use to create the URL
46+
* @param {Function} fetchCallback A function to use to create the URL
4747
* @param {Object} options
4848
* @param {Object} options.timeout The max duration to wait before resolving so that the page
4949
* component will be rendered and can display a skeleton while waiting for the promise returned
@@ -68,21 +68,13 @@ export default function createLazyProps(fetchCallback, { timeout = 50 } = {}) {
6868
return new Promise((resolve, reject) => {
6969
const fetchPromise = fetchCallback(options)
7070

71-
let resolved = false
72-
7371
setTimeout(() => {
74-
if (!resolved) {
75-
resolved = true
76-
resolve({ lazy: fetchPromise })
77-
}
72+
resolve({ lazy: fetchPromise })
7873
}, timeout)
7974

8075
fetchPromise
8176
.then(result => {
82-
if (!resolved) {
83-
resolved = true
84-
resolve(result)
85-
}
77+
resolve(result)
8678
})
8779
.catch(e => {
8880
reject(e)

0 commit comments

Comments
 (0)