@pyreon/coolgrid 0.11.5 → 0.11.6
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.
- package/README.md +35 -45
- package/lib/index.d.ts +4 -4
- package/lib/index.js +1 -1
- package/package.json +25 -25
- package/src/Col/component.tsx +18 -18
- package/src/Col/index.ts +1 -1
- package/src/Col/styled.ts +12 -12
- package/src/Container/component.tsx +10 -10
- package/src/Container/index.ts +1 -1
- package/src/Container/styled.ts +8 -8
- package/src/Container/utils.ts +2 -2
- package/src/Row/component.tsx +9 -9
- package/src/Row/index.ts +1 -1
- package/src/Row/styled.ts +11 -11
- package/src/__tests__/Col.test.ts +50 -50
- package/src/__tests__/Container.styled.test.ts +21 -21
- package/src/__tests__/Container.test.ts +62 -62
- package/src/__tests__/Row.test.ts +57 -57
- package/src/__tests__/config.test.ts +48 -48
- package/src/__tests__/contextCascading.test.ts +31 -31
- package/src/__tests__/index.test.ts +19 -19
- package/src/__tests__/useContext.test.ts +34 -34
- package/src/__tests__/utils.test.ts +44 -44
- package/src/constants.ts +11 -11
- package/src/context/ContainerContext.ts +2 -2
- package/src/context/RowContext.ts +2 -2
- package/src/context/index.ts +2 -2
- package/src/index.ts +5 -5
- package/src/theme.ts +2 -2
- package/src/types.ts +9 -9
- package/src/useContext.tsx +13 -12
- package/src/utils.ts +2 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { VNode } from
|
|
2
|
-
import { beforeEach, describe, expect, it, vi } from
|
|
1
|
+
import type { VNode } from '@pyreon/core'
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
4
|
const mockProvide = vi.fn()
|
|
5
5
|
const mockUseContext = vi.fn()
|
|
6
6
|
|
|
7
|
-
vi.mock(
|
|
8
|
-
const original = await importOriginal<typeof import(
|
|
7
|
+
vi.mock('@pyreon/core', async (importOriginal) => {
|
|
8
|
+
const original = await importOriginal<typeof import('@pyreon/core')>()
|
|
9
9
|
return {
|
|
10
10
|
...original,
|
|
11
11
|
provide: (...args: any[]) => {
|
|
@@ -21,8 +21,8 @@ vi.mock("@pyreon/core", async (importOriginal) => {
|
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
// Mock unistyle context to return empty theme
|
|
24
|
-
vi.mock(
|
|
25
|
-
const original = await importOriginal<typeof import(
|
|
24
|
+
vi.mock('@pyreon/unistyle', async (importOriginal) => {
|
|
25
|
+
const original = await importOriginal<typeof import('@pyreon/unistyle')>()
|
|
26
26
|
return {
|
|
27
27
|
...original,
|
|
28
28
|
}
|
|
@@ -30,102 +30,102 @@ vi.mock("@pyreon/unistyle", async (importOriginal) => {
|
|
|
30
30
|
|
|
31
31
|
const asVNode = (v: unknown) => v as VNode
|
|
32
32
|
|
|
33
|
-
describe(
|
|
33
|
+
describe('Col', () => {
|
|
34
34
|
beforeEach(() => {
|
|
35
35
|
vi.clearAllMocks()
|
|
36
36
|
// Default: no context (empty object)
|
|
37
37
|
mockUseContext.mockReturnValue({})
|
|
38
38
|
})
|
|
39
39
|
|
|
40
|
-
it(
|
|
41
|
-
const Col = (await import(
|
|
42
|
-
const result = asVNode(Col({ children:
|
|
40
|
+
it('returns a VNode', async () => {
|
|
41
|
+
const Col = (await import('../Col')).default
|
|
42
|
+
const result = asVNode(Col({ children: 'test' }))
|
|
43
43
|
expect(result).toBeDefined()
|
|
44
44
|
expect(result.type).toBeDefined()
|
|
45
45
|
})
|
|
46
46
|
|
|
47
|
-
it(
|
|
48
|
-
const Col = (await import(
|
|
49
|
-
expect(Col.displayName).toBe(
|
|
47
|
+
it('has correct displayName', async () => {
|
|
48
|
+
const Col = (await import('../Col')).default
|
|
49
|
+
expect(Col.displayName).toBe('@pyreon/coolgrid/Col')
|
|
50
50
|
})
|
|
51
51
|
|
|
52
|
-
it(
|
|
53
|
-
const Col = (await import(
|
|
54
|
-
expect(Col.pkgName).toBe(
|
|
52
|
+
it('has correct pkgName', async () => {
|
|
53
|
+
const Col = (await import('../Col')).default
|
|
54
|
+
expect(Col.pkgName).toBe('@pyreon/coolgrid')
|
|
55
55
|
})
|
|
56
56
|
|
|
57
|
-
it(
|
|
58
|
-
const Col = (await import(
|
|
59
|
-
expect(Col.PYREON__COMPONENT).toBe(
|
|
57
|
+
it('has PYREON__COMPONENT static', async () => {
|
|
58
|
+
const Col = (await import('../Col')).default
|
|
59
|
+
expect(Col.PYREON__COMPONENT).toBe('@pyreon/coolgrid/Col')
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
-
it(
|
|
63
|
-
const Col = (await import(
|
|
64
|
-
const result = asVNode(Col({ size: 6, children:
|
|
65
|
-
expect(result.props).toHaveProperty(
|
|
62
|
+
it('passes $coolgrid prop with grid values', async () => {
|
|
63
|
+
const Col = (await import('../Col')).default
|
|
64
|
+
const result = asVNode(Col({ size: 6, children: 'test' }))
|
|
65
|
+
expect(result.props).toHaveProperty('$coolgrid')
|
|
66
66
|
})
|
|
67
67
|
|
|
68
|
-
it(
|
|
69
|
-
const Col = (await import(
|
|
70
|
-
Col({ children:
|
|
68
|
+
it('does not provide context (Col only reads, never provides)', async () => {
|
|
69
|
+
const Col = (await import('../Col')).default
|
|
70
|
+
Col({ children: 'test' })
|
|
71
71
|
expect(mockProvide).not.toHaveBeenCalled()
|
|
72
72
|
})
|
|
73
73
|
|
|
74
|
-
it(
|
|
75
|
-
const Col = (await import(
|
|
74
|
+
it('strips context keys from DOM props', async () => {
|
|
75
|
+
const Col = (await import('../Col')).default
|
|
76
76
|
const result = asVNode(
|
|
77
77
|
Col({
|
|
78
78
|
columns: 12,
|
|
79
79
|
gap: 16,
|
|
80
80
|
size: 6,
|
|
81
|
-
|
|
82
|
-
children:
|
|
81
|
+
'data-testid': 'my-col',
|
|
82
|
+
children: 'test',
|
|
83
83
|
}),
|
|
84
84
|
)
|
|
85
85
|
// context keys should be stripped from the rendered props
|
|
86
86
|
// but $coolgrid should be present
|
|
87
87
|
expect(result.props.$coolgrid).toBeDefined()
|
|
88
|
-
expect(result.props[
|
|
88
|
+
expect(result.props['data-testid']).toBe('my-col')
|
|
89
89
|
})
|
|
90
90
|
|
|
91
|
-
it(
|
|
92
|
-
const Col = (await import(
|
|
93
|
-
const customCss =
|
|
94
|
-
const result = asVNode(Col({ css: customCss, children:
|
|
91
|
+
it('passes css as extraStyles when provided', async () => {
|
|
92
|
+
const Col = (await import('../Col')).default
|
|
93
|
+
const customCss = 'background: green;'
|
|
94
|
+
const result = asVNode(Col({ css: customCss, children: 'test' }))
|
|
95
95
|
expect((result.props.$coolgrid as Record<string, unknown>).extraStyles).toBe(customCss)
|
|
96
96
|
})
|
|
97
97
|
|
|
98
|
-
it(
|
|
99
|
-
const Col = (await import(
|
|
100
|
-
const result = asVNode(Col({ columns: 12, gap: 16, size: 6, children:
|
|
98
|
+
it('includes columns and gap in $coolgrid', async () => {
|
|
99
|
+
const Col = (await import('../Col')).default
|
|
100
|
+
const result = asVNode(Col({ columns: 12, gap: 16, size: 6, children: 'test' }))
|
|
101
101
|
const coolgrid = result.props.$coolgrid as Record<string, unknown>
|
|
102
102
|
expect(coolgrid.columns).toBe(12)
|
|
103
103
|
expect(coolgrid.gap).toBe(16)
|
|
104
104
|
expect(coolgrid.size).toBe(6)
|
|
105
105
|
})
|
|
106
106
|
|
|
107
|
-
it(
|
|
108
|
-
const Col = (await import(
|
|
109
|
-
const result = asVNode(Col({ children:
|
|
110
|
-
expect(result.props[
|
|
107
|
+
it('renders with data-coolgrid attribute in dev mode', async () => {
|
|
108
|
+
const Col = (await import('../Col')).default
|
|
109
|
+
const result = asVNode(Col({ children: 'test' }))
|
|
110
|
+
expect(result.props['data-coolgrid']).toBe('col')
|
|
111
111
|
})
|
|
112
112
|
|
|
113
113
|
it("passes component prop as 'as'", async () => {
|
|
114
|
-
const Col = (await import(
|
|
114
|
+
const Col = (await import('../Col')).default
|
|
115
115
|
const customComponent = (() => null) as any
|
|
116
|
-
const result = asVNode(Col({ component: customComponent, children:
|
|
116
|
+
const result = asVNode(Col({ component: customComponent, children: 'test' }))
|
|
117
117
|
expect(result.props.as).toBe(customComponent)
|
|
118
118
|
})
|
|
119
119
|
|
|
120
|
-
it(
|
|
121
|
-
const Col = (await import(
|
|
122
|
-
const result = asVNode(Col({ padding: 8, children:
|
|
120
|
+
it('includes padding in $coolgrid', async () => {
|
|
121
|
+
const Col = (await import('../Col')).default
|
|
122
|
+
const result = asVNode(Col({ padding: 8, children: 'test' }))
|
|
123
123
|
expect((result.props.$coolgrid as Record<string, unknown>).padding).toBe(8)
|
|
124
124
|
})
|
|
125
125
|
|
|
126
|
-
it(
|
|
127
|
-
const Col = (await import(
|
|
128
|
-
const result = asVNode(Col({ children:
|
|
126
|
+
it('renders children in VNode', async () => {
|
|
127
|
+
const Col = (await import('../Col')).default
|
|
128
|
+
const result = asVNode(Col({ children: 'hello' }))
|
|
129
129
|
expect(result.children).toBeDefined()
|
|
130
130
|
})
|
|
131
131
|
})
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { describe, expect, it } from
|
|
2
|
-
import { getContainerWidth } from
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { getContainerWidth } from '../Container/utils'
|
|
3
3
|
|
|
4
|
-
describe(
|
|
5
|
-
it(
|
|
4
|
+
describe('Container/utils – getContainerWidth', () => {
|
|
5
|
+
it('returns width from props when present', () => {
|
|
6
6
|
const result = getContainerWidth({ width: 960 }, {})
|
|
7
7
|
expect(result).toBe(960)
|
|
8
8
|
})
|
|
9
9
|
|
|
10
|
-
it(
|
|
10
|
+
it('prefers props.width over theme.grid.container', () => {
|
|
11
11
|
const result = getContainerWidth(
|
|
12
12
|
{ width: 800 },
|
|
13
|
-
{ grid: { container: { xs:
|
|
13
|
+
{ grid: { container: { xs: '100%', md: 720 } } },
|
|
14
14
|
)
|
|
15
15
|
expect(result).toBe(800)
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
it(
|
|
19
|
-
const result = getContainerWidth({}, { grid: { container: { xs:
|
|
20
|
-
expect(result).toEqual({ xs:
|
|
18
|
+
it('falls back to theme.grid.container', () => {
|
|
19
|
+
const result = getContainerWidth({}, { grid: { container: { xs: '100%', md: 720 } } })
|
|
20
|
+
expect(result).toEqual({ xs: '100%', md: 720 })
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
it(
|
|
24
|
-
const result = getContainerWidth({}, { coolgrid: { container: { xs:
|
|
25
|
-
expect(result).toEqual({ xs:
|
|
23
|
+
it('falls back to theme.coolgrid.container when grid is missing', () => {
|
|
24
|
+
const result = getContainerWidth({}, { coolgrid: { container: { xs: '100%', lg: 960 } } })
|
|
25
|
+
expect(result).toEqual({ xs: '100%', lg: 960 })
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
-
it(
|
|
28
|
+
it('returns undefined/falsy when nothing matches', () => {
|
|
29
29
|
expect(getContainerWidth({}, {})).toBeFalsy()
|
|
30
30
|
})
|
|
31
31
|
|
|
32
|
-
it(
|
|
32
|
+
it('returns undefined/falsy when both are undefined', () => {
|
|
33
33
|
expect(getContainerWidth(undefined, undefined)).toBeFalsy()
|
|
34
34
|
})
|
|
35
35
|
|
|
36
|
-
it(
|
|
36
|
+
it('returns undefined/falsy when both are empty objects', () => {
|
|
37
37
|
expect(getContainerWidth({}, {})).toBeFalsy()
|
|
38
38
|
})
|
|
39
39
|
|
|
40
|
-
it(
|
|
41
|
-
const result = getContainerWidth({ width:
|
|
42
|
-
expect(result).toBe(
|
|
40
|
+
it('returns string width from props', () => {
|
|
41
|
+
const result = getContainerWidth({ width: '100%' }, {})
|
|
42
|
+
expect(result).toBe('100%')
|
|
43
43
|
})
|
|
44
44
|
|
|
45
|
-
it(
|
|
46
|
-
const result = getContainerWidth({ width: { xs:
|
|
47
|
-
expect(result).toEqual({ xs:
|
|
45
|
+
it('returns responsive object from props', () => {
|
|
46
|
+
const result = getContainerWidth({ width: { xs: '100%', md: 720, lg: 960 } }, {})
|
|
47
|
+
expect(result).toEqual({ xs: '100%', md: 720, lg: 960 })
|
|
48
48
|
})
|
|
49
49
|
})
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { VNode } from
|
|
2
|
-
import { beforeEach, describe, expect, it, vi } from
|
|
1
|
+
import type { VNode } from '@pyreon/core'
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
4
|
const mockProvide = vi.fn()
|
|
5
5
|
const mockUseContext = vi.fn()
|
|
6
6
|
|
|
7
|
-
vi.mock(
|
|
8
|
-
const original = await importOriginal<typeof import(
|
|
7
|
+
vi.mock('@pyreon/core', async (importOriginal) => {
|
|
8
|
+
const original = await importOriginal<typeof import('@pyreon/core')>()
|
|
9
9
|
return {
|
|
10
10
|
...original,
|
|
11
11
|
provide: (...args: any[]) => {
|
|
@@ -22,126 +22,126 @@ vi.mock("@pyreon/core", async (importOriginal) => {
|
|
|
22
22
|
|
|
23
23
|
const asVNode = (v: unknown) => v as VNode
|
|
24
24
|
|
|
25
|
-
describe(
|
|
25
|
+
describe('Container', () => {
|
|
26
26
|
beforeEach(() => {
|
|
27
27
|
vi.clearAllMocks()
|
|
28
28
|
// unistyle context returns empty theme
|
|
29
29
|
mockUseContext.mockReturnValue({ theme: {} })
|
|
30
30
|
})
|
|
31
31
|
|
|
32
|
-
it(
|
|
33
|
-
const Container = (await import(
|
|
34
|
-
const result = asVNode(Container({ children:
|
|
32
|
+
it('returns a VNode', async () => {
|
|
33
|
+
const Container = (await import('../Container')).default
|
|
34
|
+
const result = asVNode(Container({ children: 'test' }))
|
|
35
35
|
expect(result).toBeDefined()
|
|
36
36
|
expect(result.type).toBeDefined()
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
it(
|
|
40
|
-
const Container = (await import(
|
|
41
|
-
expect(Container.displayName).toBe(
|
|
39
|
+
it('has correct displayName', async () => {
|
|
40
|
+
const Container = (await import('../Container')).default
|
|
41
|
+
expect(Container.displayName).toBe('@pyreon/coolgrid/Container')
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
it(
|
|
45
|
-
const Container = (await import(
|
|
46
|
-
expect(Container.pkgName).toBe(
|
|
44
|
+
it('has correct pkgName', async () => {
|
|
45
|
+
const Container = (await import('../Container')).default
|
|
46
|
+
expect(Container.pkgName).toBe('@pyreon/coolgrid')
|
|
47
47
|
})
|
|
48
48
|
|
|
49
|
-
it(
|
|
50
|
-
const Container = (await import(
|
|
51
|
-
expect(Container.PYREON__COMPONENT).toBe(
|
|
49
|
+
it('has PYREON__COMPONENT static', async () => {
|
|
50
|
+
const Container = (await import('../Container')).default
|
|
51
|
+
expect(Container.PYREON__COMPONENT).toBe('@pyreon/coolgrid/Container')
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
-
it(
|
|
55
|
-
const Container = (await import(
|
|
56
|
-
const result = asVNode(Container({ children:
|
|
57
|
-
expect(result.props).toHaveProperty(
|
|
58
|
-
expect(result.props.$coolgrid).toHaveProperty(
|
|
54
|
+
it('passes $coolgrid prop with width and extraStyles', async () => {
|
|
55
|
+
const Container = (await import('../Container')).default
|
|
56
|
+
const result = asVNode(Container({ children: 'test' }))
|
|
57
|
+
expect(result.props).toHaveProperty('$coolgrid')
|
|
58
|
+
expect(result.props.$coolgrid).toHaveProperty('width')
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
-
it(
|
|
62
|
-
const Container = (await import(
|
|
63
|
-
Container({ columns: 12, gap: 16, children:
|
|
61
|
+
it('provides ContainerContext', async () => {
|
|
62
|
+
const Container = (await import('../Container')).default
|
|
63
|
+
Container({ columns: 12, gap: 16, children: 'test' })
|
|
64
64
|
expect(mockProvide).toHaveBeenCalledTimes(1)
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
-
it(
|
|
68
|
-
const Container = (await import(
|
|
69
|
-
Container({ columns: 24, gap: 16, gutter: 8, children:
|
|
67
|
+
it('provides context with grid values', async () => {
|
|
68
|
+
const Container = (await import('../Container')).default
|
|
69
|
+
Container({ columns: 24, gap: 16, gutter: 8, children: 'test' })
|
|
70
70
|
const config = mockProvide.mock.calls[0]?.[1] as Record<string, unknown>
|
|
71
71
|
expect(config.columns).toBe(24)
|
|
72
72
|
expect(config.gap).toBe(16)
|
|
73
73
|
expect(config.gutter).toBe(8)
|
|
74
74
|
})
|
|
75
75
|
|
|
76
|
-
it(
|
|
77
|
-
const Container = (await import(
|
|
78
|
-
const result = asVNode(Container({ width: 960, children:
|
|
76
|
+
it('uses width prop to override containerWidth', async () => {
|
|
77
|
+
const Container = (await import('../Container')).default
|
|
78
|
+
const result = asVNode(Container({ width: 960, children: 'test' }))
|
|
79
79
|
expect((result.props.$coolgrid as Record<string, unknown>).width).toBe(960)
|
|
80
80
|
})
|
|
81
81
|
|
|
82
|
-
it(
|
|
83
|
-
const Container = (await import(
|
|
82
|
+
it('accepts width as function', async () => {
|
|
83
|
+
const Container = (await import('../Container')).default
|
|
84
84
|
const widthFn = (_containerWidth: any) => 800
|
|
85
|
-
const result = asVNode(Container({ width: widthFn as any, children:
|
|
85
|
+
const result = asVNode(Container({ width: widthFn as any, children: 'test' }))
|
|
86
86
|
expect((result.props.$coolgrid as Record<string, unknown>).width).toBe(800)
|
|
87
87
|
})
|
|
88
88
|
|
|
89
|
-
it(
|
|
90
|
-
const Container = (await import(
|
|
89
|
+
it('strips context keys from DOM props', async () => {
|
|
90
|
+
const Container = (await import('../Container')).default
|
|
91
91
|
const result = asVNode(
|
|
92
92
|
Container({
|
|
93
93
|
columns: 12,
|
|
94
94
|
gap: 16,
|
|
95
|
-
|
|
96
|
-
children:
|
|
95
|
+
'data-testid': 'container',
|
|
96
|
+
children: 'test',
|
|
97
97
|
}),
|
|
98
98
|
)
|
|
99
|
-
expect(result.props[
|
|
99
|
+
expect(result.props['data-testid']).toBe('container')
|
|
100
100
|
})
|
|
101
101
|
|
|
102
|
-
it(
|
|
103
|
-
const Container = (await import(
|
|
104
|
-
const customCss =
|
|
105
|
-
const result = asVNode(Container({ css: customCss, children:
|
|
102
|
+
it('passes css as extraStyles in $coolgrid', async () => {
|
|
103
|
+
const Container = (await import('../Container')).default
|
|
104
|
+
const customCss = 'background: red;'
|
|
105
|
+
const result = asVNode(Container({ css: customCss, children: 'test' }))
|
|
106
106
|
expect((result.props.$coolgrid as Record<string, unknown>).extraStyles).toBe(customCss)
|
|
107
107
|
})
|
|
108
108
|
|
|
109
|
-
it(
|
|
110
|
-
const Container = (await import(
|
|
109
|
+
it('provides context with all grid keys', async () => {
|
|
110
|
+
const Container = (await import('../Container')).default
|
|
111
111
|
Container({
|
|
112
112
|
columns: 12,
|
|
113
113
|
gap: 16,
|
|
114
114
|
gutter: 8,
|
|
115
115
|
padding: 4,
|
|
116
116
|
size: 6,
|
|
117
|
-
contentAlignX:
|
|
118
|
-
children:
|
|
117
|
+
contentAlignX: 'center',
|
|
118
|
+
children: 'test',
|
|
119
119
|
})
|
|
120
120
|
const config = mockProvide.mock.calls[0]?.[1] as Record<string, unknown>
|
|
121
|
-
expect(config).toHaveProperty(
|
|
122
|
-
expect(config).toHaveProperty(
|
|
123
|
-
expect(config).toHaveProperty(
|
|
124
|
-
expect(config).toHaveProperty(
|
|
125
|
-
expect(config).toHaveProperty(
|
|
126
|
-
expect(config).toHaveProperty(
|
|
121
|
+
expect(config).toHaveProperty('columns')
|
|
122
|
+
expect(config).toHaveProperty('gap')
|
|
123
|
+
expect(config).toHaveProperty('gutter')
|
|
124
|
+
expect(config).toHaveProperty('padding')
|
|
125
|
+
expect(config).toHaveProperty('size')
|
|
126
|
+
expect(config).toHaveProperty('contentAlignX')
|
|
127
127
|
})
|
|
128
128
|
|
|
129
|
-
it(
|
|
130
|
-
const Container = (await import(
|
|
131
|
-
const result = asVNode(Container({ children:
|
|
132
|
-
expect(result.props[
|
|
129
|
+
it('renders with data-coolgrid attribute in dev mode', async () => {
|
|
130
|
+
const Container = (await import('../Container')).default
|
|
131
|
+
const result = asVNode(Container({ children: 'test' }))
|
|
132
|
+
expect(result.props['data-coolgrid']).toBe('container')
|
|
133
133
|
})
|
|
134
134
|
|
|
135
135
|
it("passes component prop as 'as'", async () => {
|
|
136
|
-
const Container = (await import(
|
|
136
|
+
const Container = (await import('../Container')).default
|
|
137
137
|
const customComponent = (() => null) as any
|
|
138
|
-
const result = asVNode(Container({ component: customComponent, children:
|
|
138
|
+
const result = asVNode(Container({ component: customComponent, children: 'test' }))
|
|
139
139
|
expect(result.props.as).toBe(customComponent)
|
|
140
140
|
})
|
|
141
141
|
|
|
142
|
-
it(
|
|
143
|
-
const Container = (await import(
|
|
144
|
-
const result = asVNode(Container({ children:
|
|
142
|
+
it('renders children in VNode', async () => {
|
|
143
|
+
const Container = (await import('../Container')).default
|
|
144
|
+
const result = asVNode(Container({ children: 'hello world' }))
|
|
145
145
|
expect(result.children).toBeDefined()
|
|
146
146
|
})
|
|
147
147
|
})
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { VNode } from
|
|
2
|
-
import { beforeEach, describe, expect, it, vi } from
|
|
1
|
+
import type { VNode } from '@pyreon/core'
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
4
|
const mockProvide = vi.fn()
|
|
5
5
|
const mockUseContext = vi.fn()
|
|
6
6
|
|
|
7
|
-
vi.mock(
|
|
8
|
-
const original = await importOriginal<typeof import(
|
|
7
|
+
vi.mock('@pyreon/core', async (importOriginal) => {
|
|
8
|
+
const original = await importOriginal<typeof import('@pyreon/core')>()
|
|
9
9
|
return {
|
|
10
10
|
...original,
|
|
11
11
|
provide: (...args: any[]) => {
|
|
@@ -22,114 +22,114 @@ vi.mock("@pyreon/core", async (importOriginal) => {
|
|
|
22
22
|
|
|
23
23
|
const asVNode = (v: unknown) => v as VNode
|
|
24
24
|
|
|
25
|
-
describe(
|
|
25
|
+
describe('Row', () => {
|
|
26
26
|
beforeEach(() => {
|
|
27
27
|
vi.clearAllMocks()
|
|
28
28
|
// unistyle context returns empty theme, container context returns empty
|
|
29
29
|
mockUseContext.mockReturnValue({})
|
|
30
30
|
})
|
|
31
31
|
|
|
32
|
-
it(
|
|
33
|
-
const Row = (await import(
|
|
34
|
-
const result = asVNode(Row({ children:
|
|
32
|
+
it('returns a VNode', async () => {
|
|
33
|
+
const Row = (await import('../Row')).default
|
|
34
|
+
const result = asVNode(Row({ children: 'test' }))
|
|
35
35
|
expect(result).toBeDefined()
|
|
36
36
|
expect(result.type).toBeDefined()
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
it(
|
|
40
|
-
const Row = (await import(
|
|
41
|
-
expect(Row.displayName).toBe(
|
|
39
|
+
it('has correct displayName', async () => {
|
|
40
|
+
const Row = (await import('../Row')).default
|
|
41
|
+
expect(Row.displayName).toBe('@pyreon/coolgrid/Row')
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
it(
|
|
45
|
-
const Row = (await import(
|
|
46
|
-
expect(Row.pkgName).toBe(
|
|
44
|
+
it('has correct pkgName', async () => {
|
|
45
|
+
const Row = (await import('../Row')).default
|
|
46
|
+
expect(Row.pkgName).toBe('@pyreon/coolgrid')
|
|
47
47
|
})
|
|
48
48
|
|
|
49
|
-
it(
|
|
50
|
-
const Row = (await import(
|
|
51
|
-
expect(Row.PYREON__COMPONENT).toBe(
|
|
49
|
+
it('has PYREON__COMPONENT static', async () => {
|
|
50
|
+
const Row = (await import('../Row')).default
|
|
51
|
+
expect(Row.PYREON__COMPONENT).toBe('@pyreon/coolgrid/Row')
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
-
it(
|
|
55
|
-
const Row = (await import(
|
|
56
|
-
const result = asVNode(Row({ gap: 16, children:
|
|
57
|
-
expect(result.props).toHaveProperty(
|
|
58
|
-
expect(result.props.$coolgrid).toHaveProperty(
|
|
54
|
+
it('passes $coolgrid prop with row values', async () => {
|
|
55
|
+
const Row = (await import('../Row')).default
|
|
56
|
+
const result = asVNode(Row({ gap: 16, children: 'test' }))
|
|
57
|
+
expect(result.props).toHaveProperty('$coolgrid')
|
|
58
|
+
expect(result.props.$coolgrid).toHaveProperty('gap')
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
-
it(
|
|
62
|
-
const Row = (await import(
|
|
63
|
-
Row({ gap: 16, columns: 12, children:
|
|
61
|
+
it('provides RowContext', async () => {
|
|
62
|
+
const Row = (await import('../Row')).default
|
|
63
|
+
Row({ gap: 16, columns: 12, children: 'test' })
|
|
64
64
|
expect(mockProvide).toHaveBeenCalledTimes(1)
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
-
it(
|
|
68
|
-
const Row = (await import(
|
|
69
|
-
Row({ columns: 24, gap: 16, gutter: 8, children:
|
|
67
|
+
it('provides context with grid values', async () => {
|
|
68
|
+
const Row = (await import('../Row')).default
|
|
69
|
+
Row({ columns: 24, gap: 16, gutter: 8, children: 'test' })
|
|
70
70
|
const config = mockProvide.mock.calls[0]?.[1] as Record<string, unknown>
|
|
71
71
|
expect(config.columns).toBe(24)
|
|
72
72
|
expect(config.gap).toBe(16)
|
|
73
73
|
expect(config.gutter).toBe(8)
|
|
74
74
|
})
|
|
75
75
|
|
|
76
|
-
it(
|
|
77
|
-
const Row = (await import(
|
|
78
|
-
const result = asVNode(Row({ contentAlignX:
|
|
79
|
-
expect((result.props.$coolgrid as Record<string, unknown>).contentAlignX).toBe(
|
|
76
|
+
it('passes contentAlignX to $coolgrid', async () => {
|
|
77
|
+
const Row = (await import('../Row')).default
|
|
78
|
+
const result = asVNode(Row({ contentAlignX: 'center', children: 'test' }))
|
|
79
|
+
expect((result.props.$coolgrid as Record<string, unknown>).contentAlignX).toBe('center')
|
|
80
80
|
})
|
|
81
81
|
|
|
82
|
-
it(
|
|
83
|
-
const Row = (await import(
|
|
82
|
+
it('strips context keys from DOM props', async () => {
|
|
83
|
+
const Row = (await import('../Row')).default
|
|
84
84
|
const result = asVNode(
|
|
85
85
|
Row({
|
|
86
86
|
columns: 12,
|
|
87
87
|
gap: 16,
|
|
88
|
-
|
|
89
|
-
children:
|
|
88
|
+
'data-testid': 'row',
|
|
89
|
+
children: 'test',
|
|
90
90
|
}),
|
|
91
91
|
)
|
|
92
|
-
expect(result.props[
|
|
92
|
+
expect(result.props['data-testid']).toBe('row')
|
|
93
93
|
})
|
|
94
94
|
|
|
95
|
-
it(
|
|
96
|
-
const Row = (await import(
|
|
97
|
-
const customCss =
|
|
98
|
-
const result = asVNode(Row({ css: customCss, children:
|
|
95
|
+
it('passes css as extraStyles in $coolgrid when provided', async () => {
|
|
96
|
+
const Row = (await import('../Row')).default
|
|
97
|
+
const customCss = 'background: blue;'
|
|
98
|
+
const result = asVNode(Row({ css: customCss, children: 'test' }))
|
|
99
99
|
expect((result.props.$coolgrid as Record<string, unknown>).extraStyles).toBe(customCss)
|
|
100
100
|
})
|
|
101
101
|
|
|
102
|
-
it(
|
|
103
|
-
const Row = (await import(
|
|
104
|
-
const result = asVNode(Row({ gutter: 24, children:
|
|
102
|
+
it('passes gutter in $coolgrid', async () => {
|
|
103
|
+
const Row = (await import('../Row')).default
|
|
104
|
+
const result = asVNode(Row({ gutter: 24, children: 'test' }))
|
|
105
105
|
expect((result.props.$coolgrid as Record<string, unknown>).gutter).toBe(24)
|
|
106
106
|
})
|
|
107
107
|
|
|
108
|
-
it(
|
|
109
|
-
const Row = (await import(
|
|
108
|
+
it('provides context including colCss and colComponent', async () => {
|
|
109
|
+
const Row = (await import('../Row')).default
|
|
110
110
|
const colComp = (() => null) as any
|
|
111
|
-
Row({ colCss:
|
|
111
|
+
Row({ colCss: 'color: red;', colComponent: colComp, children: 'test' })
|
|
112
112
|
const config = mockProvide.mock.calls[0]?.[1] as Record<string, unknown>
|
|
113
|
-
expect(config.colCss).toBe(
|
|
113
|
+
expect(config.colCss).toBe('color: red;')
|
|
114
114
|
expect(config.colComponent).toBe(colComp)
|
|
115
115
|
})
|
|
116
116
|
|
|
117
|
-
it(
|
|
118
|
-
const Row = (await import(
|
|
119
|
-
const result = asVNode(Row({ children:
|
|
120
|
-
expect(result.props[
|
|
117
|
+
it('renders with data-coolgrid attribute in dev mode', async () => {
|
|
118
|
+
const Row = (await import('../Row')).default
|
|
119
|
+
const result = asVNode(Row({ children: 'test' }))
|
|
120
|
+
expect(result.props['data-coolgrid']).toBe('row')
|
|
121
121
|
})
|
|
122
122
|
|
|
123
123
|
it("passes component prop as 'as'", async () => {
|
|
124
|
-
const Row = (await import(
|
|
124
|
+
const Row = (await import('../Row')).default
|
|
125
125
|
const customComponent = (() => null) as any
|
|
126
|
-
const result = asVNode(Row({ component: customComponent, children:
|
|
126
|
+
const result = asVNode(Row({ component: customComponent, children: 'test' }))
|
|
127
127
|
expect(result.props.as).toBe(customComponent)
|
|
128
128
|
})
|
|
129
129
|
|
|
130
|
-
it(
|
|
131
|
-
const Row = (await import(
|
|
132
|
-
const result = asVNode(Row({ children:
|
|
130
|
+
it('renders children in VNode', async () => {
|
|
131
|
+
const Row = (await import('../Row')).default
|
|
132
|
+
const result = asVNode(Row({ children: 'hello' }))
|
|
133
133
|
expect(result.children).toBeDefined()
|
|
134
134
|
})
|
|
135
135
|
})
|