@charcoal-ui/react 3.1.2-beta.6 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ import { light } from '@charcoal-ui/theme'
2
+ import 'jest-styled-components'
3
+
4
+ import React from 'react'
5
+ import renderder from 'react-test-renderer'
6
+ import { ThemeProvider } from 'styled-components'
7
+ import Checkbox from '.'
8
+
9
+ export function render(children: JSX.Element) {
10
+ return renderder
11
+ .create(<ThemeProvider theme={light}>{children}</ThemeProvider>)
12
+ .toJSON()
13
+ }
14
+
15
+ const array = [...Array<undefined>(1000)].map((_, i) => i)
16
+
17
+ describe('Checkbox', () => {
18
+ test('<Checkbox />', () => {
19
+ function ManyCheckbox() {
20
+ return (
21
+ <>
22
+ {array.map((i) => (
23
+ <Checkbox key={i} label="test" />
24
+ ))}
25
+ </>
26
+ )
27
+ }
28
+ render(<ManyCheckbox />)
29
+ })
30
+ })
@@ -0,0 +1,66 @@
1
+ import { dark, light } from '@charcoal-ui/theme'
2
+ import renderer from 'react-test-renderer'
3
+ import { ThemeProvider } from 'styled-components'
4
+ import { Story } from '../../_lib/compat'
5
+ import path from 'path'
6
+ import glob from 'glob'
7
+
8
+ import 'jest-styled-components'
9
+
10
+ function render(children: JSX.Element) {
11
+ return renderer.create(children).toJSON()
12
+ }
13
+
14
+ const themes = Object.entries({
15
+ light,
16
+ dark,
17
+ })
18
+
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ interface StoryWithMetadata<ArgsType = any> {
21
+ filename: string
22
+ name: string
23
+ story: Story<ArgsType>
24
+ args: ArgsType
25
+ }
26
+ const stories: StoryWithMetadata[] = glob
27
+ .sync(path.resolve(__dirname, '*.story.tsx'))
28
+ .flatMap((filePath) => {
29
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
30
+ const exports = require(`./${path.relative(
31
+ __dirname,
32
+ filePath
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ )}`) as Record<string, any>
35
+
36
+ return Object.entries(exports)
37
+ .filter(
38
+ ([exportName, exportValue]) =>
39
+ exportName !== 'default' && typeof exportValue === 'function'
40
+ )
41
+ .map(([exportName, exportValue]) => ({
42
+ filename: path.relative(__dirname, filePath),
43
+ name: exportName,
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ story: exportValue as Story<any>,
46
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
47
+ args: { ...exports.default.args, ...exportValue.args },
48
+ }))
49
+ })
50
+
51
+ describe.each(themes)('using %s theme', (_name, theme) => {
52
+ describe.each(stories)(
53
+ 'storiesOf($filename).add($name)',
54
+ ({ story: Story, args }) => {
55
+ it('snapshot', () => {
56
+ expect(
57
+ render(
58
+ <ThemeProvider theme={theme}>
59
+ <Story {...args} />
60
+ </ThemeProvider>
61
+ )
62
+ ).toMatchSnapshot()
63
+ })
64
+ }
65
+ )
66
+ })