Skip to content

Commit 79eb1ba

Browse files
committed
convert test/Theme
1 parent 9a7ab43 commit 79eb1ba

File tree

1 file changed

+50
-48
lines changed

1 file changed

+50
-48
lines changed

packages/editor/test/Theme.js renamed to packages/editor/test/Theme.tsx

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ import { EditorProvider, Theme } from '../src'
1111

1212
afterEach(cleanup)
1313

14-
if (global.document) {
15-
document.createRange = () => ({
16-
setStart: () => {},
17-
setEnd: () => {},
18-
commonAncestorContainer: {
19-
nodeName: 'BODY',
20-
ownerDocument: document,
21-
},
22-
})
14+
if ((global as any).document) {
15+
document.createRange = () =>
16+
(({
17+
setStart: () => {},
18+
setEnd: () => {},
19+
commonAncestorContainer: {
20+
nodeName: 'BODY',
21+
ownerDocument: document,
22+
},
23+
} as unknown) as Range)
2324
}
2425

2526
const theme = {
@@ -53,7 +54,7 @@ test('edits theme.colors', async () => {
5354
let context
5455
const GetContext = props => {
5556
context = useThemeUI()
56-
return false
57+
return null
5758
}
5859
const tree = render(
5960
<EditorProvider theme={theme}>
@@ -63,26 +64,26 @@ test('edits theme.colors', async () => {
6364
)
6465
const swatch = tree.getByText('text')
6566
fireEvent.click(swatch)
66-
const [ input ] = await waitForElement(() => tree.getAllByPlaceholderText('hex'))
67+
const [input] = await waitForElement(() =>
68+
tree.getAllByPlaceholderText('hex')
69+
)
6770
fireEvent.change(input, {
6871
target: {
69-
value: '#ff0000'
70-
}
72+
value: '#ff0000',
73+
},
7174
})
7275
expect(context.theme.colors.text).toBe('#ff0000')
7376
})
7477

7578
test('edits theme.colors within a color mode', async () => {
7679
let context
77-
const GetContext = props => {
80+
const GetContext = () => {
7881
context = useThemeUI()
79-
return false
82+
return null
8083
}
8184
const tree = render(
82-
<Context.Provider
83-
value={{
84-
colorMode: 'dark',
85-
}}>
85+
// TODO: Remove any after @theme-ui/color-mode was transformed to TypeScript
86+
<Context.Provider value={{ colorMode: 'dark' } as any}>
8687
<EditorProvider theme={theme}>
8788
<Theme.Colors />
8889
<GetContext />
@@ -91,20 +92,22 @@ test('edits theme.colors within a color mode', async () => {
9192
)
9293
const swatch = tree.getByText('text')
9394
fireEvent.click(swatch)
94-
const [ input ] = await waitForElement(() => tree.getAllByPlaceholderText('hex'))
95+
const [input] = await waitForElement(() =>
96+
tree.getAllByPlaceholderText('hex')
97+
)
9598
fireEvent.change(input, {
9699
target: {
97-
value: '#ff0000'
98-
}
100+
value: '#ff0000',
101+
},
99102
})
100103
expect(context.theme.colors.modes.dark.text).toBe('#ff0000')
101104
})
102105

103106
test('edits theme.fontSizes', async () => {
104107
let context
105-
const GetContext = props => {
108+
const GetContext = () => {
106109
context = useThemeUI()
107-
return false
110+
return null
108111
}
109112
const tree = render(
110113
<EditorProvider theme={theme}>
@@ -115,8 +118,8 @@ test('edits theme.fontSizes', async () => {
115118
const input = await waitForElement(() => tree.getByLabelText('0'))
116119
fireEvent.change(input, {
117120
target: {
118-
value: '11'
119-
}
121+
value: '11',
122+
},
120123
})
121124
expect(context.theme.fontSizes[0]).toBe(11)
122125
})
@@ -125,7 +128,7 @@ test('supports non-array theme.fontSizes objects', async () => {
125128
let context
126129
const GetContext = props => {
127130
context = useThemeUI()
128-
return false
131+
return null
129132
}
130133
const tree = render(
131134
<EditorProvider
@@ -134,7 +137,7 @@ test('supports non-array theme.fontSizes objects', async () => {
134137
small: 12,
135138
normal: 16,
136139
large: 24,
137-
}
140+
},
138141
}}>
139142
<Theme.FontSizes />
140143
<GetContext />
@@ -143,8 +146,8 @@ test('supports non-array theme.fontSizes objects', async () => {
143146
const input = await waitForElement(() => tree.getByLabelText('small'))
144147
fireEvent.change(input, {
145148
target: {
146-
value: '11'
147-
}
149+
value: '11',
150+
},
148151
})
149152
expect(context.theme.fontSizes.small).toBe(11)
150153
})
@@ -153,7 +156,7 @@ test('renders without a theme', () => {
153156
let context
154157
const GetContext = props => {
155158
context = useThemeUI()
156-
return false
159+
return null
157160
}
158161
const tree = render(
159162
<EditorProvider>
@@ -172,7 +175,7 @@ test('edits theme.fontWeights', async () => {
172175
let context
173176
const GetContext = props => {
174177
context = useThemeUI()
175-
return false
178+
return null
176179
}
177180
const tree = render(
178181
<EditorProvider theme={theme}>
@@ -183,8 +186,8 @@ test('edits theme.fontWeights', async () => {
183186
const input = await waitForElement(() => tree.getByLabelText('body'))
184187
fireEvent.change(input, {
185188
target: {
186-
value: '500'
187-
}
189+
value: '500',
190+
},
188191
})
189192
expect(context.theme.fontWeights.body).toBe('500')
190193
})
@@ -193,7 +196,7 @@ test('edits theme.lineHeights', async () => {
193196
let context
194197
const GetContext = props => {
195198
context = useThemeUI()
196-
return false
199+
return null
197200
}
198201
const tree = render(
199202
<EditorProvider theme={theme}>
@@ -204,8 +207,8 @@ test('edits theme.lineHeights', async () => {
204207
const input = await waitForElement(() => tree.getByLabelText('body'))
205208
fireEvent.change(input, {
206209
target: {
207-
value: '1.625'
208-
}
210+
value: '1.625',
211+
},
209212
})
210213
expect(context.theme.lineHeights.body).toBe(1.625)
211214
})
@@ -214,7 +217,7 @@ test('edits theme.fonts', async () => {
214217
let context
215218
const GetContext = props => {
216219
context = useThemeUI()
217-
return false
220+
return null
218221
}
219222
const tree = render(
220223
<EditorProvider theme={theme}>
@@ -225,8 +228,8 @@ test('edits theme.fonts', async () => {
225228
const input = await waitForElement(() => tree.getByLabelText('body'))
226229
fireEvent.change(input, {
227230
target: {
228-
value: 'Georgia'
229-
}
231+
value: 'Georgia',
232+
},
230233
})
231234
expect(context.theme.fonts.body).toBe('Georgia')
232235
expect(context.theme.fonts.heading).toBe('Georgia, serif')
@@ -236,7 +239,7 @@ test('edits theme.space', async () => {
236239
let context
237240
const GetContext = props => {
238241
context = useThemeUI()
239-
return false
242+
return null
240243
}
241244
const tree = render(
242245
<EditorProvider theme={theme}>
@@ -247,8 +250,8 @@ test('edits theme.space', async () => {
247250
const input = await waitForElement(() => tree.getByLabelText('0'))
248251
fireEvent.change(input, {
249252
target: {
250-
value: '2'
251-
}
253+
value: '2',
254+
},
252255
})
253256
expect(context.theme.space[0]).toBe(2)
254257
expect(context.theme.space[1]).toBe(4)
@@ -258,7 +261,7 @@ test('supports non-array theme.space objects', async () => {
258261
let context
259262
const GetContext = props => {
260263
context = useThemeUI()
261-
return false
264+
return null
262265
}
263266
const tree = render(
264267
<EditorProvider
@@ -267,7 +270,7 @@ test('supports non-array theme.space objects', async () => {
267270
small: 4,
268271
normal: 8,
269272
large: 16,
270-
}
273+
},
271274
}}>
272275
<Theme.Space />
273276
<GetContext />
@@ -276,9 +279,8 @@ test('supports non-array theme.space objects', async () => {
276279
const input = await waitForElement(() => tree.getByLabelText('small'))
277280
fireEvent.change(input, {
278281
target: {
279-
value: '3'
280-
}
282+
value: '3',
283+
},
281284
})
282285
expect(context.theme.space.small).toBe(3)
283286
})
284-

0 commit comments

Comments
 (0)