Skip to content

Commit f01566d

Browse files
chernichenkoOleksandr Chernichenko
andauthored
V9.0.0 alpha.0 - Fixing tests (#210)
* fix tests * fix tests * fix tests * fix tests * fix tests * fix tests * fix tests * fix tests Co-authored-by: Oleksandr Chernichenko <[email protected]>
1 parent 483d359 commit f01566d

30 files changed

+315
-27853
lines changed

package-lock.json

Lines changed: 65 additions & 27566 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"react": "^17.0.2",
5656
"react-dom": "^17.0.2",
5757
"react-image-magnify": "^2.7.4",
58-
"react-swipeable-views": "0.13.3",
58+
"react-swipeable-views": "^0.14.0",
5959
"react-swipeable-views-utils": "0.13.3",
6060
"react-visibility-sensor": "^5.1.1",
6161
"resize-observer-polyfill": "^1.5.1",

src/PWA.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const classes = {
1717

1818
const StyledPWAContextProvider = styled(PWAContext.Provider)(({ theme }) => ({
1919
[`& .${classes.body}`]: {
20-
'-webkit-tap-highlight-color': 'transparent',
20+
'WebkitTapHighlightColor?': 'transparent',
2121
},
2222

2323
[`& .${classes.a}`]: {

src/carousel/Carousel.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const Carousel = React.forwardRef((props, ref) => {
9898
const classes = { ...defaultClasses, ...c }
9999

100100
const { selected, setSelected } = useSelected(props)
101-
const count = children && children.length
101+
const count = !!children ? children.length : 0
102102

103103
let Tag = infinite ? VirtualizeSwipeableViews : SwipeableViews
104104
Tag = autoplay ? AutoPlaySwipeableViews : Tag
@@ -140,6 +140,7 @@ const Carousel = React.forwardRef((props, ref) => {
140140
onMouseEnter={onMouseEnter}
141141
onMouseLeave={onMouseLeave}
142142
onClick={onClick}
143+
height={height}
143144
>
144145
{aboveAdornments}
145146
<Fill height={height}>
@@ -154,15 +155,15 @@ const Carousel = React.forwardRef((props, ref) => {
154155
interval={interval}
155156
containerStyle={{ alignItems: 'center' }}
156157
/>
157-
{arrows !== false && (
158+
{arrows !== false ? (
158159
<CarouselArrows
159160
className={arrows === 'desktop' ? classes.hideTouchArrows : null}
160161
selected={selected}
161162
setSelected={setSelected}
162163
count={count}
163164
infinite={infinite}
164165
/>
165-
)}
166+
) : <div />}
166167
{indicators && <CarouselDots count={count} selected={selected} />}
167168
</div>
168169
</Fill>

src/carousel/CarouselDots.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ CarouselDots.propTypes = {
8181
/**
8282
* The total number of dots to show.
8383
*/
84-
count: PropTypes.number.isRequired,
84+
count: PropTypes.number,
8585

8686
/**
8787
* The index of the selected dot.

src/drawer/Drawer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default function Drawer({
9494
variant,
9595
showCloseButton,
9696
open,
97-
onClose,
97+
onClose = () => {},
9898
title,
9999
children,
100100
className,

src/nav/NavTab.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import React, { useCallback } from 'react'
2-
import { styled } from '@mui/material/styles'
3-
import { Hidden, Fade, Tab, Paper } from '@mui/material'
2+
import { styled, useTheme } from '@mui/material/styles'
3+
import { Fade, Tab, Paper } from '@mui/material'
44
import PropTypes from 'prop-types'
55
import Link from '../link/Link'
6-
6+
import useMediaQuery from '@mui/material/useMediaQuery'
77
import { bindHover, bindPopover } from 'material-ui-popup-state'
88
import { usePopupState } from 'material-ui-popup-state/hooks'
9-
109
import HoverPopover from 'material-ui-popup-state/HoverPopover'
1110

1211
const PREFIX = 'RSFNavTab'
@@ -95,6 +94,8 @@ const Root = styled('div')(({ theme }) => ({
9594
*/
9695
const NavTab = function({ href, as, prefetch, children, classes: c = {}, ...props }) {
9796
const classes = { ...defaultClasses, ...c }
97+
const theme = useTheme()
98+
const isSmall = useMediaQuery(theme.breakpoints.down('sm'))
9899

99100
const popupState = usePopupState({
100101
variant: 'popover',
@@ -136,9 +137,8 @@ const NavTab = function({ href, as, prefetch, children, classes: c = {}, ...prop
136137
}}
137138
/>
138139
</Link>
139-
{!children ? null : (
140-
<Hidden smDown>
141-
<HoverPopover
140+
{(children && !isSmall) ? (
141+
<HoverPopover
142142
{...bindPopover(popupState)}
143143
className={classes.popover}
144144
anchorOrigin={{
@@ -163,8 +163,7 @@ const NavTab = function({ href, as, prefetch, children, classes: c = {}, ...prop
163163
{children}
164164
</Paper>
165165
</HoverPopover>
166-
</Hidden>
167-
)}
166+
) : null}
168167
</Root>
169168
)
170169
}

src/theme/createTheme.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { createTheme as createMuiTheme, adaptV4Theme } from '@mui/material/styles'
1+
import { createTheme, adaptV4Theme } from '@mui/material/styles'
2+
// import { createTheme } from '@mui/material/styles';
23
import merge from 'lodash/merge'
34

45
/**
@@ -8,11 +9,11 @@ import merge from 'lodash/merge'
89
* @return {Object} A material UI theme
910
*/
1011

11-
export default function createTheme(values = {}) {
12-
const theme = createMuiTheme(
12+
export default function createThemeFunc(values = {}) {
13+
const theme = createTheme(
1314
merge(
1415
{},
15-
adaptV4Theme({
16+
{
1617
zIndex: {
1718
modal: 999,
1819
amp: {
@@ -23,7 +24,7 @@ export default function createTheme(values = {}) {
2324
loadMaskOffsetTop: 64 + 56 + 4,
2425
drawerWidth: 330,
2526
components: {},
26-
}),
27+
},
2728
values,
2829
),
2930
)

test/Accordion.test.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
AccordionSummary as ExpansionPanelSummary,
77
Accordion as ExpansionPanel,
88
} from '@mui/material'
9+
import { getFiberIndex } from './methods'
910

1011
describe('Accordion', () => {
1112
it('should be empty render without children', () => {
@@ -45,9 +46,9 @@ describe('Accordion', () => {
4546
).toBe(0)
4647
})
4748

48-
it.skip('should expand section on section click ', () => {
49+
it('should expand section on section click ', () => {
4950
wrapper
50-
.find(ExpansionPanelSummary)
51+
.find('.MuiButtonBase-root')
5152
.last()
5253
.simulate('click')
5354

@@ -59,10 +60,10 @@ describe('Accordion', () => {
5960
).toBe(true)
6061
})
6162

62-
it.skip('should verify that previous opened section is closed on new section click', () => {
63+
it('should verify that previous opened section is closed on new section click', () => {
6364
wrapper
64-
.find(ExpansionPanelSummary)
65-
.first()
65+
.find('.MuiButtonBase-root')
66+
.at(getFiberIndex(0))
6667
.simulate('click')
6768

6869
expect(
@@ -73,7 +74,7 @@ describe('Accordion', () => {
7374
).toBe(true)
7475

7576
wrapper
76-
.find(ExpansionPanelSummary)
77+
.find('.MuiButtonBase-root')
7778
.last()
7879
.simulate('click')
7980

@@ -96,10 +97,10 @@ describe('Accordion', () => {
9697
).toBe(1)
9798
})
9899

99-
it.skip('should close the section if clicked again on the same section', () => {
100+
it('should close the section if clicked again on the same section', () => {
100101
wrapper
101-
.find(ExpansionPanelSummary)
102-
.first()
102+
.find('.MuiButtonBase-root')
103+
.at(getFiberIndex(0))
103104
.simulate('click')
104105
expect(
105106
wrapper
@@ -109,8 +110,8 @@ describe('Accordion', () => {
109110
).toBe(true)
110111

111112
wrapper
112-
.find(ExpansionPanelSummary)
113-
.first()
113+
.find('.MuiButtonBase-root')
114+
.at(getFiberIndex(0))
114115
.simulate('click')
115116
expect(
116117
wrapper

test/BackToTop.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('BackToTop', () => {
3434
expect(wrapper.find(CustomIcon).exists()).toBe(true)
3535
})
3636

37-
it.skip('should show back to top button when scrolled more than showUnderY prop value', () => {
37+
it('should show back to top button when scrolled more than showUnderY prop value', () => {
3838
window.pageYOffset = 201
3939
wrapper = mount(<BackToTop showUnderY={200} />)
4040

@@ -44,32 +44,32 @@ describe('BackToTop', () => {
4444

4545
expect(wrapper.find(Fab).prop('style').visibility).toBe('hidden')
4646

47-
wrapper.find(Fab).simulate('click')
47+
wrapper.find('.MuiFab-root').last().simulate('click')
4848

4949
expect(wrapper.find(Fab).prop('style').visibility).toBe(undefined)
5050
})
5151

52-
it.skip('should scroll to top instantly if scroll position is more than instantBehaviorUnderY prop value', () => {
52+
it('should scroll to top instantly if scroll position is more than instantBehaviorUnderY prop value', () => {
5353
window.scrollY = 300
5454
wrapper = mount(<BackToTop instantBehaviorUnderY={250} />)
5555

5656
act(() => {
5757
map.scroll()
5858
})
5959

60-
wrapper.find(Fab).simulate('click')
60+
wrapper.find('.MuiFab-root').last().simulate('click')
6161
expect(window.scrollTo).toHaveBeenCalledWith({ behavior: 'auto', left: 0, top: 0 })
6262
})
6363

64-
it.skip('should scroll to top smoothly if scroll position is less than instantBehaviorUnderY prop value', () => {
64+
it('should scroll to top smoothly if scroll position is less than instantBehaviorUnderY prop value', () => {
6565
window.pageYOffset = 201
6666
wrapper = mount(<BackToTop instantBehaviorUnderY={250} />)
6767

6868
act(() => {
6969
map.scroll()
7070
})
7171

72-
wrapper.find(Fab).simulate('click')
72+
wrapper.find('.MuiFab-root').last().simulate('click')
7373
expect(window.scrollTo).toHaveBeenCalledWith({ behavior: 'smooth', left: 0, top: 0 })
7474
})
7575
})

test/ExpandableSection.test.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,44 +79,40 @@ describe('ExpandableSection', () => {
7979
expect(wrapper.find(Accordion).prop('classes').root).toContain('margins')
8080
})
8181

82-
it.skip('should set fixed expanded state when expanded prop provided', () => {
82+
it('should set fixed expanded state when expanded prop provided', () => {
8383
wrapper = mount(<ExpandableSection expanded CollapseIcon={TestIcon} />)
8484

8585
expect(wrapper.find(TestIcon).exists()).toBe(true)
8686
expect(
8787
wrapper
8888
.find(Accordion)
89-
.childAt(0)
9089
.prop('expanded'),
9190
).toBe(true)
92-
wrapper.find(AccordionSummary).simulate('click')
91+
wrapper.find('.MuiAccordionSummary-root').last().simulate('click')
9392
expect(
9493
wrapper
9594
.find(Accordion)
96-
.childAt(0)
9795
.prop('expanded'),
9896
).toBe(true)
9997
})
10098

101-
it.skip('should manage expanded state internally', () => {
99+
it('should manage expanded state internally', () => {
102100
wrapper = mount(<ExpandableSection />)
103101

104102
expect(
105103
wrapper
106104
.find(Accordion)
107-
.childAt(0)
108105
.prop('expanded'),
109106
).toBe(false)
110-
wrapper.find(AccordionSummary).simulate('click')
107+
wrapper.find('.MuiAccordionSummary-root').last().simulate('click')
111108
expect(
112109
wrapper
113110
.find(Accordion)
114-
.childAt(0)
115111
.prop('expanded'),
116112
).toBe(true)
117113
})
118114

119-
it.skip('should trigger provided onChange function', () => {
115+
it('should trigger provided onChange function', () => {
120116
const Test = () => {
121117
const [expanded, setExpanded] = useState(true)
122118

@@ -137,23 +133,21 @@ describe('ExpandableSection', () => {
137133
expect(
138134
wrapper
139135
.find(Accordion)
140-
.childAt(0)
141136
.prop('expanded'),
142137
).toBe(true)
143138

144-
wrapper.find(AccordionSummary).simulate('click')
139+
wrapper.find('.MuiAccordionSummary-root').last().simulate('click')
145140

146141
expect(wrapper.find(ExpandMoreIcon).exists()).toBe(true)
147142
expect(wrapper.find(TestIcon).exists()).toBe(false)
148143
expect(
149144
wrapper
150145
.find(Accordion)
151-
.childAt(0)
152146
.prop('expanded'),
153147
).toBe(false)
154148
})
155149

156-
it.skip('should not change expanded state when onChange prevents default', () => {
150+
it('should not change expanded state when onChange prevents default', () => {
157151
const Test = () => {
158152
const handleChange = (e, expanded) => {
159153
e.preventDefault()
@@ -167,26 +161,24 @@ describe('ExpandableSection', () => {
167161
expect(
168162
wrapper
169163
.find(Accordion)
170-
.childAt(0)
171164
.prop('expanded'),
172165
).toBe(false)
173166

174167
wrapper
175-
.find(Accordion)
176-
.childAt(0)
168+
.find('.RSFExpandableSection-root')
169+
.last()
177170
.simulate('click')
178171

179172
expect(
180173
wrapper
181174
.find(Accordion)
182-
.childAt(0)
183175
.prop('expanded'),
184176
).toBe(false)
185177
})
186178

187-
it.skip('should change expanded state when onChange does not prevent default', () => {
179+
it('should change expanded state when onChange does not prevent default', () => {
188180
const Test = () => {
189-
const handleChange = (e, expanded) => {}
181+
const handleChange = () => {}
190182

191183
return <ExpandableSection onChange={handleChange} />
192184
}
@@ -196,16 +188,14 @@ describe('ExpandableSection', () => {
196188
expect(
197189
wrapper
198190
.find(Accordion)
199-
.childAt(0)
200191
.prop('expanded'),
201192
).toBe(false)
202193

203-
wrapper.find(AccordionSummary).simulate('click')
194+
wrapper.find('.RSFExpandableSection-summary').last().simulate('click')
204195

205196
expect(
206197
wrapper
207198
.find(Accordion)
208-
.childAt(0)
209199
.prop('expanded'),
210200
).toBe(true)
211201
})

0 commit comments

Comments
 (0)