@financial-times/cp-content-pipeline-ui 6.7.0 → 6.7.2
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/CHANGELOG.md +14 -0
- package/lib/components/Byline/index.js +1 -1
- package/lib/components/Byline/index.js.map +1 -1
- package/lib/components/Clip/components/Container.js +2 -2
- package/lib/components/Clip/components/Container.js.map +1 -1
- package/lib/components/Clip/template/index.js +1 -0
- package/lib/components/Clip/template/index.js.map +1 -1
- package/lib/components/ImageSet/index.js +1 -1
- package/lib/components/ImageSet/index.js.map +1 -1
- package/lib/components/LiveBlogPost/index.js +21 -9
- package/lib/components/LiveBlogPost/index.js.map +1 -1
- package/lib/components/LiveBlogWrapper/index.js +1 -1
- package/lib/components/LiveBlogWrapper/index.js.map +1 -1
- package/lib/components/Recommended/index.js +1 -1
- package/lib/components/Recommended/index.js.map +1 -1
- package/lib/components/RichText/index.d.ts +1 -1
- package/lib/components/Table/index.js +1 -1
- package/lib/components/Table/index.js.map +1 -1
- package/lib/components/Video/index.js +1 -1
- package/lib/components/Video/index.js.map +1 -1
- package/lib/components/YoutubeVideo/index.js +1 -1
- package/lib/components/YoutubeVideo/index.js.map +1 -1
- package/lib/stories/Clip.stories.d.ts +1 -2
- package/lib/stories/Clip.stories.js +5 -5
- package/lib/stories/Clip.stories.js.map +1 -1
- package/package.json +5 -2
- package/src/components/Byline/index.tsx +8 -4
- package/src/components/Clip/components/Container.tsx +3 -10
- package/src/components/Clip/template/index.ts +1 -0
- package/src/components/Clip/test/__snapshots__/snapshot.spec.tsx.snap +8 -8
- package/src/components/ImageSet/index.tsx +0 -1
- package/src/components/LiveBlogPost/index.tsx +42 -29
- package/src/components/LiveBlogWrapper/index.tsx +0 -1
- package/src/components/Recommended/index.tsx +0 -1
- package/src/components/Table/index.tsx +0 -1
- package/src/components/Video/index.tsx +1 -4
- package/src/components/YoutubeVideo/index.tsx +1 -4
- package/src/stories/Clip.stories.tsx +2 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/components/Expander/client/index.d.ts +0 -49
- package/lib/components/Expander/client/index.js +0 -124
- package/lib/components/Expander/client/index.js.map +0 -1
- package/lib/components/Expander/index.d.ts +0 -15
- package/lib/components/Expander/index.js +0 -27
- package/lib/components/Expander/index.js.map +0 -1
- package/lib/components/Expander/test/client/index.spec.d.ts +0 -1
- package/lib/components/Expander/test/client/index.spec.js +0 -103
- package/lib/components/Expander/test/client/index.spec.js.map +0 -1
- package/lib/components/Expander/test/index.spec.d.ts +0 -1
- package/lib/components/Expander/test/index.spec.js +0 -57
- package/lib/components/Expander/test/index.spec.js.map +0 -1
- package/lib/components/Expander/test/snapshot.spec.d.ts +0 -1
- package/lib/components/Expander/test/snapshot.spec.js +0 -63
- package/lib/components/Expander/test/snapshot.spec.js.map +0 -1
- package/lib/components/LiveBlogPost/client/index.d.ts +0 -5
- package/lib/components/LiveBlogPost/client/index.js +0 -12
- package/lib/components/LiveBlogPost/client/index.js.map +0 -1
- package/lib/stories/Expander.stories.d.ts +0 -54
- package/lib/stories/Expander.stories.js +0 -142
- package/lib/stories/Expander.stories.js.map +0 -1
- package/src/components/Expander/client/index.ts +0 -197
- package/src/components/Expander/client/main.scss +0 -162
- package/src/components/Expander/index.tsx +0 -74
- package/src/components/Expander/test/__snapshots__/snapshot.spec.tsx.snap +0 -225
- package/src/components/Expander/test/client/index.spec.tsx +0 -129
- package/src/components/Expander/test/index.spec.tsx +0 -77
- package/src/components/Expander/test/snapshot.spec.tsx +0 -73
- package/src/components/LiveBlogPost/client/index.ts +0 -9
- package/src/stories/Expander.stories.scss +0 -3
- package/src/stories/Expander.stories.tsx +0 -159
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`Expander Snapshot component rendered on server default render 1`] = `
|
|
4
|
-
<div
|
|
5
|
-
className="cp-expander cp-expander--all-resolutions cp-expander--not-initialised"
|
|
6
|
-
data-component="expander"
|
|
7
|
-
data-state="collapsed"
|
|
8
|
-
id="test-id__container"
|
|
9
|
-
>
|
|
10
|
-
<div
|
|
11
|
-
aria-describedby="test-id"
|
|
12
|
-
className="cp-expander-content"
|
|
13
|
-
id="test-id"
|
|
14
|
-
>
|
|
15
|
-
<div
|
|
16
|
-
className="cp-expander__expand"
|
|
17
|
-
>
|
|
18
|
-
<a
|
|
19
|
-
aria-controls="test-id"
|
|
20
|
-
aria-expanded={false}
|
|
21
|
-
aria-hidden={false}
|
|
22
|
-
className="cp-expander__link"
|
|
23
|
-
data-action="expand"
|
|
24
|
-
data-trackable="truncated-post"
|
|
25
|
-
data-trackable-context-truncated-id="test-id"
|
|
26
|
-
data-trackable-context-truncated-post="expand"
|
|
27
|
-
href="#test-id"
|
|
28
|
-
>
|
|
29
|
-
Expand
|
|
30
|
-
</a>
|
|
31
|
-
</div>
|
|
32
|
-
<div>
|
|
33
|
-
Children 1
|
|
34
|
-
</div>
|
|
35
|
-
<div>
|
|
36
|
-
Children 2
|
|
37
|
-
</div>
|
|
38
|
-
<div
|
|
39
|
-
className="cp-expander__collapse"
|
|
40
|
-
>
|
|
41
|
-
<a
|
|
42
|
-
aria-controls="test-id"
|
|
43
|
-
aria-expanded={false}
|
|
44
|
-
aria-hidden={true}
|
|
45
|
-
className="cp-expander__link"
|
|
46
|
-
data-action="collapse"
|
|
47
|
-
data-trackable="truncated-post"
|
|
48
|
-
data-trackable-context-truncated-id="test-id"
|
|
49
|
-
data-trackable-context-truncated-post="collapse"
|
|
50
|
-
href="#test-id__container"
|
|
51
|
-
>
|
|
52
|
-
Collapse
|
|
53
|
-
</a>
|
|
54
|
-
</div>
|
|
55
|
-
</div>
|
|
56
|
-
</div>
|
|
57
|
-
`;
|
|
58
|
-
|
|
59
|
-
exports[`Expander Snapshot component rendered on server only on mobile 1`] = `
|
|
60
|
-
<div
|
|
61
|
-
className="cp-expander cp-expander--mobile-only cp-expander--not-initialised"
|
|
62
|
-
data-component="expander"
|
|
63
|
-
data-state="collapsed"
|
|
64
|
-
id="test-id__container"
|
|
65
|
-
>
|
|
66
|
-
<div
|
|
67
|
-
aria-describedby="test-id"
|
|
68
|
-
className="cp-expander-content"
|
|
69
|
-
id="test-id"
|
|
70
|
-
>
|
|
71
|
-
<div
|
|
72
|
-
className="cp-expander__expand"
|
|
73
|
-
>
|
|
74
|
-
<a
|
|
75
|
-
aria-controls="test-id"
|
|
76
|
-
aria-expanded={false}
|
|
77
|
-
aria-hidden={false}
|
|
78
|
-
className="cp-expander__link"
|
|
79
|
-
data-action="expand"
|
|
80
|
-
data-trackable="truncated-post"
|
|
81
|
-
data-trackable-context-truncated-id="test-id"
|
|
82
|
-
data-trackable-context-truncated-post="expand"
|
|
83
|
-
href="#test-id"
|
|
84
|
-
>
|
|
85
|
-
Expand
|
|
86
|
-
</a>
|
|
87
|
-
</div>
|
|
88
|
-
<div>
|
|
89
|
-
Children 1
|
|
90
|
-
</div>
|
|
91
|
-
<div>
|
|
92
|
-
Children 2
|
|
93
|
-
</div>
|
|
94
|
-
<div
|
|
95
|
-
className="cp-expander__collapse"
|
|
96
|
-
>
|
|
97
|
-
<a
|
|
98
|
-
aria-controls="test-id"
|
|
99
|
-
aria-expanded={false}
|
|
100
|
-
aria-hidden={true}
|
|
101
|
-
className="cp-expander__link"
|
|
102
|
-
data-action="collapse"
|
|
103
|
-
data-trackable="truncated-post"
|
|
104
|
-
data-trackable-context-truncated-id="test-id"
|
|
105
|
-
data-trackable-context-truncated-post="collapse"
|
|
106
|
-
href="#test-id__container"
|
|
107
|
-
>
|
|
108
|
-
Collapse
|
|
109
|
-
</a>
|
|
110
|
-
</div>
|
|
111
|
-
</div>
|
|
112
|
-
</div>
|
|
113
|
-
`;
|
|
114
|
-
|
|
115
|
-
exports[`Expander Snapshot component rendered on server with different labels 1`] = `
|
|
116
|
-
<div
|
|
117
|
-
className="cp-expander cp-expander--all-resolutions cp-expander--not-initialised"
|
|
118
|
-
data-component="expander"
|
|
119
|
-
data-state="collapsed"
|
|
120
|
-
id="test-id__container"
|
|
121
|
-
>
|
|
122
|
-
<div
|
|
123
|
-
aria-describedby="test-id"
|
|
124
|
-
className="cp-expander-content"
|
|
125
|
-
id="test-id"
|
|
126
|
-
>
|
|
127
|
-
<div
|
|
128
|
-
className="cp-expander__expand"
|
|
129
|
-
>
|
|
130
|
-
<a
|
|
131
|
-
aria-controls="test-id"
|
|
132
|
-
aria-expanded={false}
|
|
133
|
-
aria-hidden={false}
|
|
134
|
-
className="cp-expander__link"
|
|
135
|
-
data-action="expand"
|
|
136
|
-
data-trackable="truncated-post"
|
|
137
|
-
data-trackable-context-truncated-id="test-id"
|
|
138
|
-
data-trackable-context-truncated-post="expand"
|
|
139
|
-
href="#test-id"
|
|
140
|
-
>
|
|
141
|
-
Open
|
|
142
|
-
</a>
|
|
143
|
-
</div>
|
|
144
|
-
<div>
|
|
145
|
-
Children 1
|
|
146
|
-
</div>
|
|
147
|
-
<div>
|
|
148
|
-
Children 2
|
|
149
|
-
</div>
|
|
150
|
-
<div
|
|
151
|
-
className="cp-expander__collapse"
|
|
152
|
-
>
|
|
153
|
-
<a
|
|
154
|
-
aria-controls="test-id"
|
|
155
|
-
aria-expanded={false}
|
|
156
|
-
aria-hidden={true}
|
|
157
|
-
className="cp-expander__link"
|
|
158
|
-
data-action="collapse"
|
|
159
|
-
data-trackable="truncated-post"
|
|
160
|
-
data-trackable-context-truncated-id="test-id"
|
|
161
|
-
data-trackable-context-truncated-post="collapse"
|
|
162
|
-
href="#test-id__container"
|
|
163
|
-
>
|
|
164
|
-
Close
|
|
165
|
-
</a>
|
|
166
|
-
</div>
|
|
167
|
-
</div>
|
|
168
|
-
</div>
|
|
169
|
-
`;
|
|
170
|
-
|
|
171
|
-
exports[`Expander Snapshot component rendered on server with different state 1`] = `
|
|
172
|
-
<div
|
|
173
|
-
className="cp-expander cp-expander--all-resolutions cp-expander--not-initialised"
|
|
174
|
-
data-component="expander"
|
|
175
|
-
data-state="expanded"
|
|
176
|
-
id="test-id__container"
|
|
177
|
-
>
|
|
178
|
-
<div
|
|
179
|
-
aria-describedby="test-id"
|
|
180
|
-
className="cp-expander-content"
|
|
181
|
-
id="test-id"
|
|
182
|
-
>
|
|
183
|
-
<div
|
|
184
|
-
className="cp-expander__expand"
|
|
185
|
-
>
|
|
186
|
-
<a
|
|
187
|
-
aria-controls="test-id"
|
|
188
|
-
aria-expanded={true}
|
|
189
|
-
aria-hidden={true}
|
|
190
|
-
className="cp-expander__link"
|
|
191
|
-
data-action="expand"
|
|
192
|
-
data-trackable="truncated-post"
|
|
193
|
-
data-trackable-context-truncated-id="test-id"
|
|
194
|
-
data-trackable-context-truncated-post="expand"
|
|
195
|
-
href="#test-id"
|
|
196
|
-
>
|
|
197
|
-
Expand
|
|
198
|
-
</a>
|
|
199
|
-
</div>
|
|
200
|
-
<div>
|
|
201
|
-
Children 1
|
|
202
|
-
</div>
|
|
203
|
-
<div>
|
|
204
|
-
Children 2
|
|
205
|
-
</div>
|
|
206
|
-
<div
|
|
207
|
-
className="cp-expander__collapse"
|
|
208
|
-
>
|
|
209
|
-
<a
|
|
210
|
-
aria-controls="test-id"
|
|
211
|
-
aria-expanded={true}
|
|
212
|
-
aria-hidden={false}
|
|
213
|
-
className="cp-expander__link"
|
|
214
|
-
data-action="collapse"
|
|
215
|
-
data-trackable="truncated-post"
|
|
216
|
-
data-trackable-context-truncated-id="test-id"
|
|
217
|
-
data-trackable-context-truncated-post="collapse"
|
|
218
|
-
href="#test-id__container"
|
|
219
|
-
>
|
|
220
|
-
Collapse
|
|
221
|
-
</a>
|
|
222
|
-
</div>
|
|
223
|
-
</div>
|
|
224
|
-
</div>
|
|
225
|
-
`;
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
import React from 'react'
|
|
4
|
-
|
|
5
|
-
import Expander, { ExpanderProps } from '../../index'
|
|
6
|
-
import { ExpanderClient } from '../../client'
|
|
7
|
-
import { render, screen } from '@testing-library/react'
|
|
8
|
-
|
|
9
|
-
//mock IntersectionObserver
|
|
10
|
-
class IntersectionObserver {
|
|
11
|
-
//mock constructor
|
|
12
|
-
constructor(callback) {
|
|
13
|
-
this.callback = callback
|
|
14
|
-
}
|
|
15
|
-
observe() {
|
|
16
|
-
this.active = true
|
|
17
|
-
}
|
|
18
|
-
disconnect() {
|
|
19
|
-
this.active = false
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
intersects() {
|
|
23
|
-
if (this.active) {
|
|
24
|
-
this.callback([{ isIntersecting: true }])
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
//mock scrollIntoView
|
|
30
|
-
window.HTMLElement.prototype.scrollIntoView = jest.fn()
|
|
31
|
-
|
|
32
|
-
describe('Expander client test', () => {
|
|
33
|
-
beforeEach(() => {
|
|
34
|
-
window.IntersectionObserver = IntersectionObserver
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it('find expanders markup and initialises it', () => {
|
|
38
|
-
const props: ExpanderProps = {
|
|
39
|
-
id: 'test-id',
|
|
40
|
-
}
|
|
41
|
-
render(
|
|
42
|
-
<Expander {...props}>
|
|
43
|
-
<div>Children 1</div>
|
|
44
|
-
</Expander>
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
const expanders = ExpanderClient.init()
|
|
48
|
-
expect(expanders.length).toBe(1)
|
|
49
|
-
expect(
|
|
50
|
-
document.querySelectorAll("[data-component='expander']").length
|
|
51
|
-
).toBe(1)
|
|
52
|
-
expect(expanders[0].container.id).toBe('test-id__container')
|
|
53
|
-
expect(
|
|
54
|
-
expanders[0].container.classList.contains('cp-expander--initialised')
|
|
55
|
-
).toBe(true)
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('do not initialised twice expanders', () => {
|
|
59
|
-
const props: ExpanderProps = {
|
|
60
|
-
id: 'test-id',
|
|
61
|
-
}
|
|
62
|
-
render(
|
|
63
|
-
<Expander {...props}>
|
|
64
|
-
<div>Children 1</div>
|
|
65
|
-
</Expander>
|
|
66
|
-
)
|
|
67
|
-
ExpanderClient.init()
|
|
68
|
-
const expanders = ExpanderClient.init()
|
|
69
|
-
|
|
70
|
-
expect(expanders.length).toBe(0)
|
|
71
|
-
expect(
|
|
72
|
-
document.querySelectorAll("[data-component='expander']").length
|
|
73
|
-
).toBe(1)
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
it('expands and collapse', async () => {
|
|
77
|
-
const props: ExpanderProps = {
|
|
78
|
-
id: 'test-id',
|
|
79
|
-
}
|
|
80
|
-
render(
|
|
81
|
-
<Expander {...props}>
|
|
82
|
-
<div>Children 1</div>
|
|
83
|
-
</Expander>
|
|
84
|
-
)
|
|
85
|
-
const expanders = ExpanderClient.init()
|
|
86
|
-
const expanderButton = screen.getByText('Expand')
|
|
87
|
-
const collapserButton = screen.getByText('Collapse')
|
|
88
|
-
expect(expanderButton.getAttribute('aria-expanded')).toBe('false')
|
|
89
|
-
expect(expanderButton.getAttribute('aria-hidden')).toBe('false')
|
|
90
|
-
expect(collapserButton.getAttribute('aria-expanded')).toBe('false')
|
|
91
|
-
expect(collapserButton.getAttribute('aria-hidden')).toBe('true')
|
|
92
|
-
|
|
93
|
-
await expanderButton.click()
|
|
94
|
-
expect(expanderButton.getAttribute('aria-expanded')).toBe('true')
|
|
95
|
-
expect(expanders[0].container?.getAttribute('data-state')).toBe('expanded')
|
|
96
|
-
expect(expanderButton.getAttribute('aria-expanded')).toBe('true')
|
|
97
|
-
expect(expanderButton.getAttribute('aria-hidden')).toBe('true')
|
|
98
|
-
expect(collapserButton.getAttribute('aria-expanded')).toBe('true')
|
|
99
|
-
expect(collapserButton.getAttribute('aria-hidden')).toBe('false')
|
|
100
|
-
|
|
101
|
-
await collapserButton.click()
|
|
102
|
-
expect(expanders[0].container?.getAttribute('data-state')).toBe('collapsed')
|
|
103
|
-
expect(expanderButton.getAttribute('aria-expanded')).toBe('false')
|
|
104
|
-
expect(expanderButton.getAttribute('aria-hidden')).toBe('false')
|
|
105
|
-
expect(collapserButton.getAttribute('aria-expanded')).toBe('false')
|
|
106
|
-
expect(collapserButton.getAttribute('aria-hidden')).toBe('true')
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('track entire read only once', () => {
|
|
110
|
-
const props: ExpanderProps = {
|
|
111
|
-
id: 'test-id',
|
|
112
|
-
}
|
|
113
|
-
render(
|
|
114
|
-
<Expander {...props}>
|
|
115
|
-
<div>Children 1</div>
|
|
116
|
-
</Expander>
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
const expanders = ExpanderClient.init()
|
|
120
|
-
const spy = jest.spyOn(document.body, 'dispatchEvent')
|
|
121
|
-
spy.mockImplementation((event) => {
|
|
122
|
-
expect(event.detail.action).toBe('entire_read')
|
|
123
|
-
})
|
|
124
|
-
expanders[0].trackingEntireRead.observer.intersects()
|
|
125
|
-
expect(spy).toHaveBeenCalledTimes(1)
|
|
126
|
-
expanders[0].trackingEntireRead.observer.intersects()
|
|
127
|
-
expect(spy).toHaveBeenCalledTimes(1)
|
|
128
|
-
})
|
|
129
|
-
})
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
import React from 'react'
|
|
4
|
-
|
|
5
|
-
import Expander, { ExpanderProps } from '../index'
|
|
6
|
-
import { render, screen } from '@testing-library/react'
|
|
7
|
-
|
|
8
|
-
describe('Expander template', () => {
|
|
9
|
-
it('renders', () => {
|
|
10
|
-
const props: ExpanderProps = {
|
|
11
|
-
id: 'test-id',
|
|
12
|
-
}
|
|
13
|
-
const tree = render(
|
|
14
|
-
<Expander {...props}>
|
|
15
|
-
<div>Children 1</div>
|
|
16
|
-
<div>Children 2</div>
|
|
17
|
-
</Expander>
|
|
18
|
-
)
|
|
19
|
-
expect(
|
|
20
|
-
tree.container.querySelector('[data-component="expander"]')
|
|
21
|
-
).toBeTruthy()
|
|
22
|
-
expect(
|
|
23
|
-
tree.container.querySelector('[data-state="collapsed"]')
|
|
24
|
-
).toBeTruthy()
|
|
25
|
-
expect(
|
|
26
|
-
tree.container.querySelector('.cp-expander--not-initialised')
|
|
27
|
-
).toBeTruthy()
|
|
28
|
-
expect(screen.getByText('Expand')).toBeTruthy()
|
|
29
|
-
expect(screen.getByText('Collapse')).toBeTruthy()
|
|
30
|
-
expect(screen.getByText('Children 1')).toBeTruthy()
|
|
31
|
-
expect(screen.getByText('Children 2')).toBeTruthy()
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('with different labels', () => {
|
|
35
|
-
const props: ExpanderProps = {
|
|
36
|
-
id: 'test-id',
|
|
37
|
-
collapseLabel: 'Close',
|
|
38
|
-
expandLabel: 'Open',
|
|
39
|
-
}
|
|
40
|
-
render(
|
|
41
|
-
<Expander {...props}>
|
|
42
|
-
<div>Children</div>
|
|
43
|
-
</Expander>
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
expect(screen.getByText('Open')).toBeTruthy()
|
|
47
|
-
expect(screen.getByText('Close')).toBeTruthy()
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('with different state', () => {
|
|
51
|
-
const props: ExpanderProps = {
|
|
52
|
-
id: 'test-id',
|
|
53
|
-
state: 'expanded',
|
|
54
|
-
}
|
|
55
|
-
const tree = render(
|
|
56
|
-
<Expander {...props}>
|
|
57
|
-
<div>Children</div>
|
|
58
|
-
</Expander>
|
|
59
|
-
)
|
|
60
|
-
expect(tree.container.querySelector('[data-state="expanded"]')).toBeTruthy()
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('add class for only mobile', () => {
|
|
64
|
-
const props: ExpanderProps = {
|
|
65
|
-
id: 'test-id',
|
|
66
|
-
onlyMobile: true,
|
|
67
|
-
}
|
|
68
|
-
const tree = render(
|
|
69
|
-
<Expander {...props}>
|
|
70
|
-
<div>Children</div>
|
|
71
|
-
</Expander>
|
|
72
|
-
)
|
|
73
|
-
expect(
|
|
74
|
-
tree.container.querySelector('.cp-expander--mobile-only')
|
|
75
|
-
).toBeTruthy()
|
|
76
|
-
})
|
|
77
|
-
})
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
import React from 'react'
|
|
4
|
-
import renderer from 'react-test-renderer'
|
|
5
|
-
import Expander, { ExpanderProps } from '../index'
|
|
6
|
-
|
|
7
|
-
describe('Expander Snapshot', () => {
|
|
8
|
-
describe('component rendered on server', () => {
|
|
9
|
-
it('default render', () => {
|
|
10
|
-
const props: ExpanderProps = {
|
|
11
|
-
id: 'test-id',
|
|
12
|
-
}
|
|
13
|
-
const tree = renderer
|
|
14
|
-
.create(
|
|
15
|
-
<Expander {...props}>
|
|
16
|
-
<div>Children 1</div>
|
|
17
|
-
<div>Children 2</div>
|
|
18
|
-
</Expander>
|
|
19
|
-
)
|
|
20
|
-
.toJSON()
|
|
21
|
-
expect(tree).toMatchSnapshot()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('only on mobile', () => {
|
|
25
|
-
const props: ExpanderProps = {
|
|
26
|
-
id: 'test-id',
|
|
27
|
-
onlyMobile: true,
|
|
28
|
-
}
|
|
29
|
-
const tree = renderer
|
|
30
|
-
.create(
|
|
31
|
-
<Expander {...props}>
|
|
32
|
-
<div>Children 1</div>
|
|
33
|
-
<div>Children 2</div>
|
|
34
|
-
</Expander>
|
|
35
|
-
)
|
|
36
|
-
.toJSON()
|
|
37
|
-
expect(tree).toMatchSnapshot()
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('with different labels', () => {
|
|
41
|
-
const props: ExpanderProps = {
|
|
42
|
-
id: 'test-id',
|
|
43
|
-
collapseLabel: 'Close',
|
|
44
|
-
expandLabel: 'Open',
|
|
45
|
-
}
|
|
46
|
-
const tree = renderer
|
|
47
|
-
.create(
|
|
48
|
-
<Expander {...props}>
|
|
49
|
-
<div>Children 1</div>
|
|
50
|
-
<div>Children 2</div>
|
|
51
|
-
</Expander>
|
|
52
|
-
)
|
|
53
|
-
.toJSON()
|
|
54
|
-
expect(tree).toMatchSnapshot()
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it('with different state', () => {
|
|
58
|
-
const props: ExpanderProps = {
|
|
59
|
-
id: 'test-id',
|
|
60
|
-
state: 'expanded',
|
|
61
|
-
}
|
|
62
|
-
const tree = renderer
|
|
63
|
-
.create(
|
|
64
|
-
<Expander {...props}>
|
|
65
|
-
<div>Children 1</div>
|
|
66
|
-
<div>Children 2</div>
|
|
67
|
-
</Expander>
|
|
68
|
-
)
|
|
69
|
-
.toJSON()
|
|
70
|
-
expect(tree).toMatchSnapshot()
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
})
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { ExpanderServer, ExpanderProps } from '../components/Expander'
|
|
2
|
-
import { ExpanderClient } from '../components/Expander/client'
|
|
3
|
-
import React, { useEffect } from 'react'
|
|
4
|
-
import oTracking from '@financial-times/o-tracking/main'
|
|
5
|
-
import './Expander.stories.scss'
|
|
6
|
-
import ClipClient from '../components/Clip/client'
|
|
7
|
-
import './Clip.stories.scss'
|
|
8
|
-
import RichText from '../components/RichText'
|
|
9
|
-
import { ContentTree } from '@financial-times/content-tree'
|
|
10
|
-
import { ClipSet } from '@financial-times/cp-content-pipeline-schema/src/resolvers/content-tree/Workarounds'
|
|
11
|
-
|
|
12
|
-
const structuredContent: ContentTree.Body = {
|
|
13
|
-
type: 'body',
|
|
14
|
-
version: 1,
|
|
15
|
-
children: [
|
|
16
|
-
{
|
|
17
|
-
type: 'paragraph',
|
|
18
|
-
children: [
|
|
19
|
-
{
|
|
20
|
-
type: 'text',
|
|
21
|
-
value:
|
|
22
|
-
'Mike Johnson has survived an attempt to oust him as speaker of the House of Representatives by Marjorie Taylor Greene, a hardline Republican congresswoman from Georgia. ',
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
} as ContentTree.Paragraph,
|
|
26
|
-
{
|
|
27
|
-
type: 'paragraph',
|
|
28
|
-
children: [
|
|
29
|
-
{
|
|
30
|
-
type: 'text',
|
|
31
|
-
value:
|
|
32
|
-
'In a vote on Wednesday night, the lower chamber of Congress rejected Greene’s bid with overwhelming support from Democrats as well as Republicans. ',
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
} as ContentTree.Paragraph,
|
|
36
|
-
,
|
|
37
|
-
{
|
|
38
|
-
type: 'paragraph',
|
|
39
|
-
children: [
|
|
40
|
-
{
|
|
41
|
-
type: 'text',
|
|
42
|
-
value:
|
|
43
|
-
'The vote all but ensures that Johnson will remain in his post until after the November election, and will put a lid on a debate over his political future that has lasted for weeks among Republicans in Congress. ',
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
} as ContentTree.Paragraph,
|
|
47
|
-
{
|
|
48
|
-
type: 'clip-set',
|
|
49
|
-
id: 'http://api.ft.com/content/23a00095-d9fc-4cac-ad7c-477e61e3c159',
|
|
50
|
-
autoplay: false,
|
|
51
|
-
loop: false,
|
|
52
|
-
muted: false,
|
|
53
|
-
dataLayout: 'in-line',
|
|
54
|
-
data: {
|
|
55
|
-
referenceIndex: 3,
|
|
56
|
-
},
|
|
57
|
-
} as ClipSet,
|
|
58
|
-
] as ContentTree.Body['children'],
|
|
59
|
-
}
|
|
60
|
-
const storyArgs: ExpanderProps = {
|
|
61
|
-
expandLabel: 'Open',
|
|
62
|
-
collapseLabel: 'Close',
|
|
63
|
-
onlyMobile: false,
|
|
64
|
-
id: '111232323-12123-2323',
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export default {
|
|
68
|
-
title: 'Expander',
|
|
69
|
-
component: ExpanderServer,
|
|
70
|
-
tags: ['autodocs'],
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const LiveBLogWrapper: React.FC<ExpanderProps & { classNames?: string }> = (
|
|
74
|
-
args
|
|
75
|
-
) => {
|
|
76
|
-
const { classNames } = args
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<div className={classNames}>
|
|
80
|
-
<article
|
|
81
|
-
id="site-content"
|
|
82
|
-
role="main"
|
|
83
|
-
className="article article-grid article-grid--no-full-width-graphics js enhanced"
|
|
84
|
-
data-article-type="no-full-width-graphics"
|
|
85
|
-
>
|
|
86
|
-
<div
|
|
87
|
-
className="article__content"
|
|
88
|
-
data-trackable="article-body"
|
|
89
|
-
data-component="article-body"
|
|
90
|
-
style={{ position: 'relative' }}
|
|
91
|
-
>
|
|
92
|
-
<div
|
|
93
|
-
className="article__content-body n-content-body js-article__content-body"
|
|
94
|
-
data-attribute="article-content-body"
|
|
95
|
-
>
|
|
96
|
-
<LiveBlogPostWrapper {...args} id="111"></LiveBlogPostWrapper>
|
|
97
|
-
</div>
|
|
98
|
-
</div>
|
|
99
|
-
<div className="article__right "></div>
|
|
100
|
-
</article>
|
|
101
|
-
</div>
|
|
102
|
-
)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const LiveBlogPostWrapper = (args: ExpanderProps) => {
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
oTracking.init({
|
|
108
|
-
context: { product: 'next' },
|
|
109
|
-
test: true,
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
const clips = ClipClient.init(null, {})
|
|
113
|
-
|
|
114
|
-
return () => {
|
|
115
|
-
clips.forEach((clip) => clip.unload())
|
|
116
|
-
}
|
|
117
|
-
}, [])
|
|
118
|
-
return (
|
|
119
|
-
<article id={args.id}>
|
|
120
|
-
<div className="n-content-body">
|
|
121
|
-
<div
|
|
122
|
-
data-trackable="truncated-post"
|
|
123
|
-
data-trackable-context-post="1234"
|
|
124
|
-
data-component="example-boundary"
|
|
125
|
-
>
|
|
126
|
-
<ExpanderServer {...args} id={`${args.id}_expander`}>
|
|
127
|
-
<RichText structuredContent={{ tree: structuredContent }} />
|
|
128
|
-
</ExpanderServer>
|
|
129
|
-
</div>
|
|
130
|
-
</div>
|
|
131
|
-
</article>
|
|
132
|
-
)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export const OnlyServer = (args: ExpanderProps) => {
|
|
136
|
-
return <LiveBLogWrapper {...args} />
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
OnlyServer.args = { ...storyArgs }
|
|
140
|
-
|
|
141
|
-
export const WithClient = (args: ExpanderProps) => {
|
|
142
|
-
useEffect(() => {
|
|
143
|
-
const clips = ClipClient.init(null, {})
|
|
144
|
-
const expanders = ExpanderClient.init()
|
|
145
|
-
return () => {
|
|
146
|
-
clips.forEach((clip) => clip.unload())
|
|
147
|
-
expanders.forEach((expander) => expander?.destroy())
|
|
148
|
-
}
|
|
149
|
-
}, [])
|
|
150
|
-
return <LiveBLogWrapper {...args} />
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
WithClient.args = { ...storyArgs }
|
|
154
|
-
|
|
155
|
-
export const OnlyMobileWithClient = WithClient
|
|
156
|
-
OnlyMobileWithClient.args = { ...storyArgs, onlyMobile: true }
|
|
157
|
-
|
|
158
|
-
export const OnlyMobileServer = OnlyServer
|
|
159
|
-
OnlyMobileServer.args = { ...storyArgs, onlyMobile: true }
|