@pyreon/elements 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 +38 -35
- package/lib/index.d.ts +15 -15
- package/package.json +24 -24
- package/src/Element/component.tsx +14 -14
- package/src/Element/constants.ts +25 -25
- package/src/Element/index.ts +2 -2
- package/src/Element/types.ts +3 -3
- package/src/Element/utils.ts +1 -1
- package/src/List/component.tsx +7 -7
- package/src/List/index.ts +2 -2
- package/src/Overlay/component.tsx +22 -22
- package/src/Overlay/context.tsx +2 -2
- package/src/Overlay/index.ts +3 -3
- package/src/Overlay/useOverlay.tsx +97 -97
- package/src/Portal/component.tsx +6 -6
- package/src/Portal/index.ts +2 -2
- package/src/Text/component.tsx +6 -6
- package/src/Text/index.ts +2 -2
- package/src/Text/styled.ts +4 -4
- package/src/Util/component.tsx +5 -5
- package/src/Util/index.ts +2 -2
- package/src/__tests__/Content.test.tsx +46 -46
- package/src/__tests__/Element.test.ts +251 -251
- package/src/__tests__/Iterator.test.ts +142 -142
- package/src/__tests__/List.test.ts +61 -61
- package/src/__tests__/Overlay.test.ts +125 -125
- package/src/__tests__/Portal.test.ts +33 -33
- package/src/__tests__/Text.test.ts +128 -128
- package/src/__tests__/Util.test.ts +31 -31
- package/src/__tests__/Wrapper.test.tsx +60 -60
- package/src/__tests__/equalBeforeAfter.test.ts +41 -41
- package/src/__tests__/helpers.test.ts +29 -29
- package/src/__tests__/overlayContext.test.tsx +14 -14
- package/src/__tests__/responsiveProps.test.ts +116 -116
- package/src/__tests__/useOverlay.test.ts +283 -283
- package/src/__tests__/utils.test.ts +43 -43
- package/src/constants.ts +1 -1
- package/src/helpers/Content/component.tsx +5 -5
- package/src/helpers/Content/index.ts +1 -1
- package/src/helpers/Content/styled.ts +16 -16
- package/src/helpers/Content/types.ts +7 -7
- package/src/helpers/Iterator/component.tsx +28 -28
- package/src/helpers/Iterator/index.ts +2 -2
- package/src/helpers/Iterator/types.ts +3 -3
- package/src/helpers/Wrapper/component.tsx +6 -6
- package/src/helpers/Wrapper/index.ts +1 -1
- package/src/helpers/Wrapper/styled.ts +8 -8
- package/src/helpers/Wrapper/types.ts +3 -3
- package/src/helpers/Wrapper/utils.ts +1 -1
- package/src/helpers/index.ts +2 -2
- package/src/index.ts +16 -16
- package/src/types.ts +7 -7
- package/src/utils.ts +1 -1
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import type { VNode } from
|
|
2
|
-
import { describe, expect, it, vi } from
|
|
1
|
+
import type { VNode } from '@pyreon/core'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
4
|
// ---------------------------------------------------------------------------
|
|
5
5
|
// Mocks
|
|
6
6
|
// ---------------------------------------------------------------------------
|
|
7
|
-
vi.mock(
|
|
7
|
+
vi.mock('~/utils', () => ({
|
|
8
8
|
IS_DEVELOPMENT: true,
|
|
9
9
|
}))
|
|
10
10
|
|
|
11
|
-
import Wrapper from
|
|
12
|
-
import Styled from
|
|
11
|
+
import Wrapper from '../helpers/Wrapper/component'
|
|
12
|
+
import Styled from '../helpers/Wrapper/styled'
|
|
13
13
|
|
|
14
14
|
const asVNode = (v: unknown) => v as VNode
|
|
15
15
|
|
|
16
|
-
describe(
|
|
17
|
-
describe(
|
|
18
|
-
it(
|
|
19
|
-
const result = asVNode(Wrapper({ tag:
|
|
16
|
+
describe('Wrapper component', () => {
|
|
17
|
+
describe('normal element (no flex fix needed)', () => {
|
|
18
|
+
it('returns a VNode whose type is the Styled component', () => {
|
|
19
|
+
const result = asVNode(Wrapper({ tag: 'div' }))
|
|
20
20
|
expect(result.type).toBe(Styled)
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
it(
|
|
23
|
+
it('passes normalElement as $element prop with block, direction, alignX, alignY, equalCols, extraStyles', () => {
|
|
24
24
|
const result = asVNode(
|
|
25
25
|
Wrapper({
|
|
26
|
-
tag:
|
|
26
|
+
tag: 'div',
|
|
27
27
|
block: true,
|
|
28
|
-
direction:
|
|
29
|
-
alignX:
|
|
30
|
-
alignY:
|
|
28
|
+
direction: 'inline',
|
|
29
|
+
alignX: 'center',
|
|
30
|
+
alignY: 'top',
|
|
31
31
|
equalCols: false,
|
|
32
|
-
extendCss:
|
|
32
|
+
extendCss: 'color: red;',
|
|
33
33
|
}),
|
|
34
34
|
)
|
|
35
35
|
|
|
36
36
|
expect(result.props.$element).toEqual({
|
|
37
37
|
block: true,
|
|
38
|
-
direction:
|
|
39
|
-
alignX:
|
|
40
|
-
alignY:
|
|
38
|
+
direction: 'inline',
|
|
39
|
+
alignX: 'center',
|
|
40
|
+
alignY: 'top',
|
|
41
41
|
equalCols: false,
|
|
42
|
-
extraStyles:
|
|
42
|
+
extraStyles: 'color: red;',
|
|
43
43
|
})
|
|
44
44
|
})
|
|
45
45
|
|
|
46
46
|
it("passes tag as the 'as' prop", () => {
|
|
47
|
-
const result = asVNode(Wrapper({ tag:
|
|
48
|
-
expect(result.props.as).toBe(
|
|
47
|
+
const result = asVNode(Wrapper({ tag: 'div' }))
|
|
48
|
+
expect(result.props.as).toBe('div')
|
|
49
49
|
})
|
|
50
50
|
|
|
51
|
-
it(
|
|
51
|
+
it('passes ref through', () => {
|
|
52
52
|
const ref = () => {}
|
|
53
|
-
const result = asVNode(Wrapper({ tag:
|
|
53
|
+
const result = asVNode(Wrapper({ tag: 'div', ref }))
|
|
54
54
|
expect(result.props.ref).toBe(ref)
|
|
55
55
|
})
|
|
56
56
|
|
|
57
|
-
it(
|
|
58
|
-
const result = asVNode(Wrapper({ tag:
|
|
59
|
-
expect(result.props.children).toBe(
|
|
57
|
+
it('passes children through', () => {
|
|
58
|
+
const result = asVNode(Wrapper({ tag: 'div', children: 'child content' }))
|
|
59
|
+
expect(result.props.children).toBe('child content')
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
-
it(
|
|
63
|
-
const result = asVNode(Wrapper({ tag:
|
|
64
|
-
expect(result.props[
|
|
62
|
+
it('adds data-pyr-element in development mode', () => {
|
|
63
|
+
const result = asVNode(Wrapper({ tag: 'div' }))
|
|
64
|
+
expect(result.props['data-pyr-element']).toBe('Element')
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
-
it(
|
|
68
|
-
const result = asVNode(Wrapper({ tag:
|
|
69
|
-
expect(result.props.id).toBe(
|
|
70
|
-
expect(result.props.role).toBe(
|
|
67
|
+
it('spreads extra props', () => {
|
|
68
|
+
const result = asVNode(Wrapper({ tag: 'section', id: 'wrapper', role: 'main' } as any))
|
|
69
|
+
expect(result.props.id).toBe('wrapper')
|
|
70
|
+
expect(result.props.role).toBe('main')
|
|
71
71
|
})
|
|
72
72
|
})
|
|
73
73
|
|
|
74
|
-
describe(
|
|
75
|
-
it(
|
|
76
|
-
const result = asVNode(Wrapper({ tag:
|
|
74
|
+
describe('flex-fix path (button/fieldset/legend)', () => {
|
|
75
|
+
it('renders parent Styled with parentFixElement for button', () => {
|
|
76
|
+
const result = asVNode(Wrapper({ tag: 'button', children: 'Click me' }))
|
|
77
77
|
expect(result.type).toBe(Styled)
|
|
78
78
|
expect((result.props.$element as any).parentFix).toBe(true)
|
|
79
79
|
})
|
|
80
80
|
|
|
81
|
-
it(
|
|
81
|
+
it('parent Styled receives parentFixElement props (block + extraStyles only)', () => {
|
|
82
82
|
const result = asVNode(
|
|
83
83
|
Wrapper({
|
|
84
|
-
tag:
|
|
84
|
+
tag: 'button',
|
|
85
85
|
block: true,
|
|
86
|
-
extendCss:
|
|
87
|
-
direction:
|
|
88
|
-
alignX:
|
|
89
|
-
alignY:
|
|
86
|
+
extendCss: 'border: none;',
|
|
87
|
+
direction: 'inline',
|
|
88
|
+
alignX: 'center',
|
|
89
|
+
alignY: 'center',
|
|
90
90
|
}),
|
|
91
91
|
)
|
|
92
92
|
|
|
93
93
|
expect(result.props.$element).toEqual({
|
|
94
94
|
parentFix: true,
|
|
95
95
|
block: true,
|
|
96
|
-
extraStyles:
|
|
96
|
+
extraStyles: 'border: none;',
|
|
97
97
|
})
|
|
98
|
-
expect(result.props.as).toBe(
|
|
98
|
+
expect(result.props.as).toBe('button')
|
|
99
99
|
})
|
|
100
100
|
|
|
101
|
-
it(
|
|
101
|
+
it('child Styled receives childFixElement props (direction, alignX, alignY, equalCols)', () => {
|
|
102
102
|
const result = asVNode(
|
|
103
103
|
Wrapper({
|
|
104
|
-
tag:
|
|
105
|
-
direction:
|
|
106
|
-
alignX:
|
|
107
|
-
alignY:
|
|
104
|
+
tag: 'fieldset',
|
|
105
|
+
direction: 'rows',
|
|
106
|
+
alignX: 'left',
|
|
107
|
+
alignY: 'bottom',
|
|
108
108
|
equalCols: true,
|
|
109
109
|
}),
|
|
110
110
|
)
|
|
@@ -115,32 +115,32 @@ describe("Wrapper component", () => {
|
|
|
115
115
|
expect(child.props.$childFix).toBe(true)
|
|
116
116
|
expect(child.props.$element).toEqual({
|
|
117
117
|
childFix: true,
|
|
118
|
-
direction:
|
|
119
|
-
alignX:
|
|
120
|
-
alignY:
|
|
118
|
+
direction: 'rows',
|
|
119
|
+
alignX: 'left',
|
|
120
|
+
alignY: 'bottom',
|
|
121
121
|
equalCols: true,
|
|
122
122
|
})
|
|
123
123
|
})
|
|
124
124
|
|
|
125
125
|
it("uses 'div' as inner tag by default", () => {
|
|
126
|
-
const result = asVNode(Wrapper({ tag:
|
|
126
|
+
const result = asVNode(Wrapper({ tag: 'button' }))
|
|
127
127
|
const child = asVNode(result.props.children)
|
|
128
|
-
expect(child.props.as).toBe(
|
|
128
|
+
expect(child.props.as).toBe('div')
|
|
129
129
|
})
|
|
130
130
|
|
|
131
131
|
it("uses 'span' as inner tag when isInline is true", () => {
|
|
132
|
-
const result = asVNode(Wrapper({ tag:
|
|
132
|
+
const result = asVNode(Wrapper({ tag: 'button', isInline: true }))
|
|
133
133
|
const child = asVNode(result.props.children)
|
|
134
|
-
expect(child.props.as).toBe(
|
|
134
|
+
expect(child.props.as).toBe('span')
|
|
135
135
|
})
|
|
136
136
|
})
|
|
137
137
|
|
|
138
|
-
describe(
|
|
139
|
-
it(
|
|
138
|
+
describe('dangerouslySetInnerHTML skips fix', () => {
|
|
139
|
+
it('renders single Styled without parentFix for button when dangerouslySetInnerHTML is set', () => {
|
|
140
140
|
const result = asVNode(
|
|
141
141
|
Wrapper({
|
|
142
|
-
tag:
|
|
143
|
-
dangerouslySetInnerHTML: { __html:
|
|
142
|
+
tag: 'button',
|
|
143
|
+
dangerouslySetInnerHTML: { __html: '<b>Bold</b>' },
|
|
144
144
|
} as any),
|
|
145
145
|
)
|
|
146
146
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { VNode } from
|
|
2
|
-
import { h } from
|
|
3
|
-
import { describe, expect, it } from
|
|
4
|
-
import { Element } from
|
|
5
|
-
import Content from
|
|
6
|
-
import Wrapper from
|
|
1
|
+
import type { VNode } from '@pyreon/core'
|
|
2
|
+
import { h } from '@pyreon/core'
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
import { Element } from '../Element'
|
|
5
|
+
import Content from '../helpers/Content/component'
|
|
6
|
+
import Wrapper from '../helpers/Wrapper/component'
|
|
7
7
|
|
|
8
8
|
const asVNode = (v: unknown) => v as VNode
|
|
9
9
|
|
|
@@ -12,67 +12,67 @@ const getContentSlots = (result: VNode): VNode[] => {
|
|
|
12
12
|
if (!Array.isArray(children)) return []
|
|
13
13
|
return children.filter(
|
|
14
14
|
(c: unknown) =>
|
|
15
|
-
c != null && typeof c ===
|
|
15
|
+
c != null && typeof c === 'object' && 'type' in (c as VNode) && (c as VNode).type === Content,
|
|
16
16
|
) as VNode[]
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
describe(
|
|
20
|
-
it(
|
|
19
|
+
describe('Element equalBeforeAfter', () => {
|
|
20
|
+
it('always passes a ref function to Wrapper', () => {
|
|
21
21
|
const result = asVNode(
|
|
22
22
|
Element({
|
|
23
23
|
equalBeforeAfter: true,
|
|
24
|
-
direction:
|
|
25
|
-
beforeContent: h(
|
|
26
|
-
afterContent: h(
|
|
27
|
-
children:
|
|
24
|
+
direction: 'inline',
|
|
25
|
+
beforeContent: h('span', null, 'Before'),
|
|
26
|
+
afterContent: h('span', null, 'After'),
|
|
27
|
+
children: 'Main',
|
|
28
28
|
}),
|
|
29
29
|
)
|
|
30
30
|
expect(result.type).toBe(Wrapper)
|
|
31
|
-
expect(typeof result.props.ref).toBe(
|
|
31
|
+
expect(typeof result.props.ref).toBe('function')
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
it(
|
|
35
|
-
const result = asVNode(Element({ equalBeforeAfter: true, children:
|
|
34
|
+
it('does not crash without before/after content', () => {
|
|
35
|
+
const result = asVNode(Element({ equalBeforeAfter: true, children: 'Main only' }))
|
|
36
36
|
expect(result.type).toBe(Wrapper)
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
it(
|
|
39
|
+
it('does not crash with only beforeContent', () => {
|
|
40
40
|
const result = asVNode(
|
|
41
41
|
Element({
|
|
42
42
|
equalBeforeAfter: true,
|
|
43
|
-
beforeContent: h(
|
|
44
|
-
children:
|
|
43
|
+
beforeContent: h('span', null, 'Before'),
|
|
44
|
+
children: 'Main',
|
|
45
45
|
}),
|
|
46
46
|
)
|
|
47
47
|
expect(result.type).toBe(Wrapper)
|
|
48
48
|
})
|
|
49
49
|
|
|
50
|
-
it(
|
|
50
|
+
it('does not crash with only afterContent', () => {
|
|
51
51
|
const result = asVNode(
|
|
52
52
|
Element({
|
|
53
53
|
equalBeforeAfter: true,
|
|
54
|
-
afterContent: h(
|
|
55
|
-
children:
|
|
54
|
+
afterContent: h('span', null, 'After'),
|
|
55
|
+
children: 'Main',
|
|
56
56
|
}),
|
|
57
57
|
)
|
|
58
58
|
expect(result.type).toBe(Wrapper)
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
-
it(
|
|
61
|
+
it('renders three slot children when both before and after exist', () => {
|
|
62
62
|
const result = asVNode(
|
|
63
63
|
Element({
|
|
64
64
|
equalBeforeAfter: true,
|
|
65
|
-
direction:
|
|
66
|
-
beforeContent: h(
|
|
67
|
-
afterContent: h(
|
|
68
|
-
children:
|
|
65
|
+
direction: 'inline',
|
|
66
|
+
beforeContent: h('span', null, 'Short'),
|
|
67
|
+
afterContent: h('span', null, 'Longer content'),
|
|
68
|
+
children: 'Center',
|
|
69
69
|
}),
|
|
70
70
|
)
|
|
71
71
|
const slots = getContentSlots(result)
|
|
72
72
|
expect(slots).toHaveLength(3)
|
|
73
73
|
})
|
|
74
74
|
|
|
75
|
-
it(
|
|
75
|
+
it('merged ref calls external function ref', () => {
|
|
76
76
|
let captured: HTMLElement | null = null
|
|
77
77
|
const ref = (node: HTMLElement | null) => {
|
|
78
78
|
captured = node
|
|
@@ -81,9 +81,9 @@ describe("Element equalBeforeAfter", () => {
|
|
|
81
81
|
Element({
|
|
82
82
|
equalBeforeAfter: true,
|
|
83
83
|
ref,
|
|
84
|
-
beforeContent: h(
|
|
85
|
-
afterContent: h(
|
|
86
|
-
children:
|
|
84
|
+
beforeContent: h('span', null, 'Before'),
|
|
85
|
+
afterContent: h('span', null, 'After'),
|
|
86
|
+
children: 'Main',
|
|
87
87
|
}),
|
|
88
88
|
)
|
|
89
89
|
const fakeNode = {} as HTMLElement
|
|
@@ -91,15 +91,15 @@ describe("Element equalBeforeAfter", () => {
|
|
|
91
91
|
expect(captured).toBe(fakeNode)
|
|
92
92
|
})
|
|
93
93
|
|
|
94
|
-
it(
|
|
94
|
+
it('merged ref sets object ref current', () => {
|
|
95
95
|
const ref = { current: null as HTMLElement | null }
|
|
96
96
|
const result = asVNode(
|
|
97
97
|
Element({
|
|
98
98
|
equalBeforeAfter: true,
|
|
99
99
|
ref,
|
|
100
|
-
beforeContent: h(
|
|
101
|
-
afterContent: h(
|
|
102
|
-
children:
|
|
100
|
+
beforeContent: h('span', null, 'Before'),
|
|
101
|
+
afterContent: h('span', null, 'After'),
|
|
102
|
+
children: 'Main',
|
|
103
103
|
}),
|
|
104
104
|
)
|
|
105
105
|
const fakeNode = {} as HTMLElement
|
|
@@ -107,16 +107,16 @@ describe("Element equalBeforeAfter", () => {
|
|
|
107
107
|
expect(ref.current).toBe(fakeNode)
|
|
108
108
|
})
|
|
109
109
|
|
|
110
|
-
it(
|
|
110
|
+
it('uses inline direction for equalBeforeAfter', () => {
|
|
111
111
|
const result = asVNode(
|
|
112
112
|
Element({
|
|
113
113
|
equalBeforeAfter: true,
|
|
114
|
-
direction:
|
|
115
|
-
beforeContent: h(
|
|
116
|
-
afterContent: h(
|
|
117
|
-
children:
|
|
114
|
+
direction: 'inline',
|
|
115
|
+
beforeContent: h('span', null, 'B'),
|
|
116
|
+
afterContent: h('span', null, 'A'),
|
|
117
|
+
children: 'Main',
|
|
118
118
|
}),
|
|
119
119
|
)
|
|
120
|
-
expect(result.props.direction).toBe(
|
|
120
|
+
expect(result.props.direction).toBe('inline')
|
|
121
121
|
})
|
|
122
122
|
})
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import { describe, expect, it } from
|
|
2
|
-
import { INLINE_ELEMENTS_FLEX_FIX } from
|
|
3
|
-
import { isWebFixNeeded } from
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { INLINE_ELEMENTS_FLEX_FIX } from '../helpers/Wrapper/constants'
|
|
3
|
+
import { isWebFixNeeded } from '../helpers/Wrapper/utils'
|
|
4
4
|
|
|
5
|
-
describe(
|
|
6
|
-
describe(
|
|
7
|
-
it(
|
|
8
|
-
expect(isWebFixNeeded(
|
|
5
|
+
describe('Wrapper utils', () => {
|
|
6
|
+
describe('isWebFixNeeded', () => {
|
|
7
|
+
it('returns true for button', () => {
|
|
8
|
+
expect(isWebFixNeeded('button')).toBe(true)
|
|
9
9
|
})
|
|
10
10
|
|
|
11
|
-
it(
|
|
12
|
-
expect(isWebFixNeeded(
|
|
11
|
+
it('returns true for fieldset', () => {
|
|
12
|
+
expect(isWebFixNeeded('fieldset')).toBe(true)
|
|
13
13
|
})
|
|
14
14
|
|
|
15
|
-
it(
|
|
16
|
-
expect(isWebFixNeeded(
|
|
15
|
+
it('returns true for legend', () => {
|
|
16
|
+
expect(isWebFixNeeded('legend')).toBe(true)
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
-
it(
|
|
20
|
-
expect(isWebFixNeeded(
|
|
19
|
+
it('returns false for div', () => {
|
|
20
|
+
expect(isWebFixNeeded('div')).toBe(false)
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
it(
|
|
24
|
-
expect(isWebFixNeeded(
|
|
23
|
+
it('returns false for span', () => {
|
|
24
|
+
expect(isWebFixNeeded('span')).toBe(false)
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
-
it(
|
|
28
|
-
expect(isWebFixNeeded(
|
|
27
|
+
it('returns false for section', () => {
|
|
28
|
+
expect(isWebFixNeeded('section')).toBe(false)
|
|
29
29
|
})
|
|
30
30
|
|
|
31
|
-
it(
|
|
31
|
+
it('returns false for undefined', () => {
|
|
32
32
|
expect(isWebFixNeeded(undefined)).toBe(false)
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
-
it(
|
|
36
|
-
expect(isWebFixNeeded(
|
|
35
|
+
it('returns false for empty string', () => {
|
|
36
|
+
expect(isWebFixNeeded('')).toBe(false)
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
it(
|
|
40
|
-
expect(isWebFixNeeded(
|
|
39
|
+
it('returns false for input', () => {
|
|
40
|
+
expect(isWebFixNeeded('input')).toBe(false)
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
-
it(
|
|
44
|
-
expect(isWebFixNeeded(
|
|
43
|
+
it('returns false for form', () => {
|
|
44
|
+
expect(isWebFixNeeded('form')).toBe(false)
|
|
45
45
|
})
|
|
46
46
|
})
|
|
47
47
|
|
|
48
|
-
describe(
|
|
49
|
-
it(
|
|
48
|
+
describe('INLINE_ELEMENTS_FLEX_FIX', () => {
|
|
49
|
+
it('contains button', () => {
|
|
50
50
|
expect(INLINE_ELEMENTS_FLEX_FIX.button).toBe(true)
|
|
51
51
|
})
|
|
52
52
|
|
|
53
|
-
it(
|
|
53
|
+
it('contains fieldset', () => {
|
|
54
54
|
expect(INLINE_ELEMENTS_FLEX_FIX.fieldset).toBe(true)
|
|
55
55
|
})
|
|
56
56
|
|
|
57
|
-
it(
|
|
57
|
+
it('contains legend', () => {
|
|
58
58
|
expect(INLINE_ELEMENTS_FLEX_FIX.legend).toBe(true)
|
|
59
59
|
})
|
|
60
60
|
|
|
61
|
-
it(
|
|
61
|
+
it('only has 3 entries', () => {
|
|
62
62
|
expect(Object.keys(INLINE_ELEMENTS_FLEX_FIX)).toHaveLength(3)
|
|
63
63
|
})
|
|
64
64
|
})
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { popContext } from
|
|
2
|
-
import { afterEach, describe, expect, it, vi } from
|
|
3
|
-
import OverlayContextProvider, { useOverlayContext } from
|
|
1
|
+
import { popContext } from '@pyreon/core'
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import OverlayContextProvider, { useOverlayContext } from '../Overlay/context'
|
|
4
4
|
|
|
5
|
-
describe(
|
|
6
|
-
it(
|
|
7
|
-
expect(typeof useOverlayContext).toBe(
|
|
5
|
+
describe('Overlay context', () => {
|
|
6
|
+
it('useOverlayContext is a function', () => {
|
|
7
|
+
expect(typeof useOverlayContext).toBe('function')
|
|
8
8
|
})
|
|
9
9
|
|
|
10
|
-
it(
|
|
10
|
+
it('returns the default context (empty object) when called outside a provider', () => {
|
|
11
11
|
const ctx = useOverlayContext()
|
|
12
12
|
expect(ctx).toEqual({})
|
|
13
13
|
})
|
|
14
14
|
})
|
|
15
15
|
|
|
16
|
-
describe(
|
|
16
|
+
describe('OverlayContextProvider component', () => {
|
|
17
17
|
afterEach(() => {
|
|
18
18
|
try {
|
|
19
19
|
popContext()
|
|
@@ -22,7 +22,7 @@ describe("OverlayContextProvider component", () => {
|
|
|
22
22
|
}
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
it(
|
|
25
|
+
it('provides blocked/setBlocked/setUnblocked via context', () => {
|
|
26
26
|
const setBlocked = vi.fn()
|
|
27
27
|
const setUnblocked = vi.fn()
|
|
28
28
|
|
|
@@ -30,7 +30,7 @@ describe("OverlayContextProvider component", () => {
|
|
|
30
30
|
blocked: true,
|
|
31
31
|
setBlocked,
|
|
32
32
|
setUnblocked,
|
|
33
|
-
children:
|
|
33
|
+
children: 'child',
|
|
34
34
|
})
|
|
35
35
|
|
|
36
36
|
const ctx = useOverlayContext()
|
|
@@ -39,18 +39,18 @@ describe("OverlayContextProvider component", () => {
|
|
|
39
39
|
expect(ctx.setUnblocked).toBe(setUnblocked)
|
|
40
40
|
})
|
|
41
41
|
|
|
42
|
-
it(
|
|
42
|
+
it('renders children (returns a value)', () => {
|
|
43
43
|
const result = OverlayContextProvider({
|
|
44
44
|
blocked: false,
|
|
45
45
|
setBlocked: vi.fn(),
|
|
46
46
|
setUnblocked: vi.fn(),
|
|
47
|
-
children:
|
|
47
|
+
children: 'Hello overlay',
|
|
48
48
|
})
|
|
49
49
|
|
|
50
50
|
expect(result).toBeDefined()
|
|
51
51
|
})
|
|
52
52
|
|
|
53
|
-
it(
|
|
53
|
+
it('provides blocked as false', () => {
|
|
54
54
|
OverlayContextProvider({
|
|
55
55
|
blocked: false,
|
|
56
56
|
setBlocked: vi.fn(),
|
|
@@ -62,7 +62,7 @@ describe("OverlayContextProvider component", () => {
|
|
|
62
62
|
expect(ctx.blocked).toBe(false)
|
|
63
63
|
})
|
|
64
64
|
|
|
65
|
-
it(
|
|
65
|
+
it('provides blocked as a function when passed as a function', () => {
|
|
66
66
|
const blockedFn = () => true
|
|
67
67
|
|
|
68
68
|
OverlayContextProvider({
|