-
Notifications
You must be signed in to change notification settings - Fork 674
/
Copy pathBox.spec.tsx
107 lines (94 loc) · 2.81 KB
/
Box.spec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* @jest-environment jsdom
*/
import { renderJSON, render, waitFor } from '@theme-ui/test-utils'
import { ThemeUIProvider } from '@theme-ui/theme-provider'
import { Box } from '..'
import { theme } from './__test-utils__'
import { __internalProps } from '../src/util'
describe('Box', () => {
test('renders', () => {
const json = renderJSON(<Box p={2}>Hello</Box>)
expect(json).toMatchSnapshot()
})
test('renders with padding props', () => {
const json = renderJSON(<Box px={2} py={4} />)
expect(json).toHaveStyleRule('padding-left', '8px')
expect(json).toHaveStyleRule('padding-right', '8px')
expect(json).toHaveStyleRule('padding-top', '32px')
expect(json).toHaveStyleRule('padding-bottom', '32px')
})
test('renders with margin props', () => {
const json = renderJSON(<Box m={3} mb={4} />)
expect(json).toHaveStyleRule('margin', '16px')
expect(json).toHaveStyleRule('margin-bottom', '32px')
})
test('renders with color props', () => {
const json = renderJSON(<Box color="tomato" bg="black" />)
expect(json).toHaveStyleRule('color', 'tomato')
expect(json).toHaveStyleRule('background-color', 'black')
})
test('renders with sx prop', () => {
const json = renderJSON(
<Box
sx={{
bg: 'tomato',
borderRadius: 4,
}}
/>
)
expect(json).toHaveStyleRule('background-color', 'tomato')
expect(json).toHaveStyleRule('border-radius', '4px')
})
test('renders with variant prop', () => {
const json = renderJSON(
<ThemeUIProvider theme={theme}>
<Box variant="boxes.beep" />
</ThemeUIProvider>
)
expect(json).toHaveStyleRule('background-color', 'highlight')
expect(json).toHaveStyleRule('padding', '32px')
})
test('renders with base styles', () => {
const json = renderJSON(
<Box
bg="cyan"
sx={{ color: 'tomato' }}
{...__internalProps({
__css: {
p: 4,
color: 'black',
bg: 'white',
},
})}
/>
)
expect(json).toHaveStyleRule('padding', '32px')
expect(json).toHaveStyleRule('color', 'tomato')
expect(json).toHaveStyleRule('background-color', 'cyan')
})
test('renders with __themeKey variant', () => {
const json = renderJSON(
<ThemeUIProvider theme={theme}>
<Box
// @ts-expect-error
__themeKey="boxes"
variant="beep"
/>
</ThemeUIProvider>
)
expect(json).toHaveStyleRule('background-color', 'highlight')
expect(json).toHaveStyleRule('padding', '32px')
})
})
test('accepts ref', async () => {
let ref: HTMLElement | null = null
render(
<ThemeUIProvider theme={theme}>
<Box ref={(r) => (ref = r)} />
</ThemeUIProvider>
)
await waitFor(() => {
expect(ref).toBeTruthy()
})
})