@linktr.ee/messaging-react 4.1.6 → 4.1.7-rc-1787179679
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/dist/testing.cjs +1 -1
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.js +2 -2
- package/dist/testing.js.map +1 -1
- package/package.json +2 -2
- package/src/components/AttachmentCard/MediaPlayer.test.tsx +346 -0
- package/src/components/AttachmentCard/Thumbnail.test.tsx +215 -0
- package/src/components/AttachmentCard/index.test.tsx +160 -0
- package/src/components/ChannelList/ChannelListContext.test.tsx +87 -0
- package/src/components/ChannelList/CustomChannelPreview.test.tsx +410 -3
- package/src/components/ChannelList/index.test.tsx +132 -1
- package/src/components/LinkAttachment/LinkAttachment.test.tsx +327 -0
- package/src/components/LinkAttachment/components/_shared/BubbleTail.test.tsx +76 -0
- package/src/components/LinkAttachment/components/_shared/CardBody.test.tsx +248 -0
- package/src/components/LinkAttachment/components/_shared/CardCta.test.tsx +123 -0
- package/src/components/LinkAttachment/components/_shared/CardShell.test.tsx +193 -0
- package/src/components/LinkAttachment/components/_shared/CardThumbnail.test.tsx +242 -0
- package/src/components/LinkAttachment/components/_shared/hex.test.ts +37 -0
- package/src/components/LinkAttachment/components/_shared/normalizeExternalHref.test.ts +72 -0
- package/src/components/LinkAttachment/components/_shared/useChinPalette.test.ts +162 -0
- package/src/testing/createMockMessagingClient.ts +2 -2
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { act, renderHook } from '@testing-library/react'
|
|
2
|
+
import { describe, expect, it } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { useChinPalette } from './useChinPalette'
|
|
5
|
+
import type { ChinPaletteInput } from './useChinPalette'
|
|
6
|
+
|
|
7
|
+
const THUMBNAIL = 'https://cdn.example.com/cover.jpg'
|
|
8
|
+
|
|
9
|
+
const render = (input: ChinPaletteInput) =>
|
|
10
|
+
renderHook((props: ChinPaletteInput) => useChinPalette(props), {
|
|
11
|
+
initialProps: input,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
describe('useChinPalette', () => {
|
|
15
|
+
it('publishes a validated accent for a ready featured hero', () => {
|
|
16
|
+
const { result } = render({
|
|
17
|
+
variant: 'dark',
|
|
18
|
+
accentColor: '#7008E7',
|
|
19
|
+
thumbnailUrl: THUMBNAIL,
|
|
20
|
+
})
|
|
21
|
+
expect(result.current.accentHex).toBe('#7008E7')
|
|
22
|
+
expect(result.current.thumbnailUrl).toBe(THUMBNAIL)
|
|
23
|
+
expect(result.current.isLoading).toBe(false)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('hashes a bare hex and tolerates surrounding whitespace', () => {
|
|
27
|
+
const { result } = render({
|
|
28
|
+
variant: 'dark',
|
|
29
|
+
accentColor: ' 7008E7 ',
|
|
30
|
+
thumbnailUrl: THUMBNAIL,
|
|
31
|
+
})
|
|
32
|
+
expect(result.current.accentHex).toBe('#7008E7')
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it.each([
|
|
36
|
+
'rebeccapurple',
|
|
37
|
+
'rgb(112, 8, 231)',
|
|
38
|
+
'#12g',
|
|
39
|
+
'#1234',
|
|
40
|
+
'',
|
|
41
|
+
undefined,
|
|
42
|
+
])('drops the unusable accent %s', (accentColor) => {
|
|
43
|
+
const { result } = render({
|
|
44
|
+
variant: 'dark',
|
|
45
|
+
accentColor,
|
|
46
|
+
thumbnailUrl: THUMBNAIL,
|
|
47
|
+
})
|
|
48
|
+
expect(result.current.accentHex).toBeUndefined()
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('drops the accent for a classic card, which has no hero', () => {
|
|
52
|
+
const { result } = render({
|
|
53
|
+
variant: 'dark',
|
|
54
|
+
accentColor: '#7008E7',
|
|
55
|
+
layout: 'classic',
|
|
56
|
+
thumbnailUrl: THUMBNAIL,
|
|
57
|
+
})
|
|
58
|
+
expect(result.current.accentHex).toBeUndefined()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it.each(['loading', 'failed'] as const)(
|
|
62
|
+
'drops the accent while status is %s',
|
|
63
|
+
(status) => {
|
|
64
|
+
const { result } = render({
|
|
65
|
+
variant: 'dark',
|
|
66
|
+
accentColor: '#7008E7',
|
|
67
|
+
status,
|
|
68
|
+
thumbnailUrl: THUMBNAIL,
|
|
69
|
+
})
|
|
70
|
+
expect(result.current.accentHex).toBeUndefined()
|
|
71
|
+
expect(result.current.isLoading).toBe(status === 'loading')
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
it.each([undefined, ''])(
|
|
76
|
+
'drops the accent when the hero url is %s',
|
|
77
|
+
(thumbnailUrl) => {
|
|
78
|
+
const { result } = render({
|
|
79
|
+
variant: 'dark',
|
|
80
|
+
accentColor: '#7008E7',
|
|
81
|
+
thumbnailUrl,
|
|
82
|
+
})
|
|
83
|
+
expect(result.current.accentHex).toBeUndefined()
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
it('drops the accent for playable audio, whose hero is the player', () => {
|
|
88
|
+
const { result } = render({
|
|
89
|
+
variant: 'dark',
|
|
90
|
+
accentColor: '#7008E7',
|
|
91
|
+
thumbnailUrl: THUMBNAIL,
|
|
92
|
+
mimeType: 'audio/mpeg',
|
|
93
|
+
sourceUrl: 'https://cdn.example.com/clip.mp3',
|
|
94
|
+
})
|
|
95
|
+
expect(result.current.accentHex).toBeUndefined()
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('keeps the accent for playable video, whose poster is the hero', () => {
|
|
99
|
+
const { result } = render({
|
|
100
|
+
variant: 'dark',
|
|
101
|
+
accentColor: '#7008E7',
|
|
102
|
+
thumbnailUrl: THUMBNAIL,
|
|
103
|
+
mimeType: 'video/mp4',
|
|
104
|
+
sourceUrl: 'https://cdn.example.com/clip.mp4',
|
|
105
|
+
})
|
|
106
|
+
expect(result.current.accentHex).toBe('#7008E7')
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it('withdraws the hero and its accent once the image fails', () => {
|
|
110
|
+
const { result } = render({
|
|
111
|
+
variant: 'dark',
|
|
112
|
+
accentColor: '#7008E7',
|
|
113
|
+
thumbnailUrl: THUMBNAIL,
|
|
114
|
+
})
|
|
115
|
+
act(() => {
|
|
116
|
+
result.current.onImageError()
|
|
117
|
+
})
|
|
118
|
+
expect(result.current.thumbnailUrl).toBeUndefined()
|
|
119
|
+
expect(result.current.accentHex).toBeUndefined()
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('gives a new hero url a fresh chance to load', () => {
|
|
123
|
+
const { result, rerender } = render({
|
|
124
|
+
variant: 'dark',
|
|
125
|
+
accentColor: '#7008E7',
|
|
126
|
+
thumbnailUrl: THUMBNAIL,
|
|
127
|
+
})
|
|
128
|
+
act(() => {
|
|
129
|
+
result.current.onImageError()
|
|
130
|
+
})
|
|
131
|
+
expect(result.current.accentHex).toBeUndefined()
|
|
132
|
+
|
|
133
|
+
rerender({
|
|
134
|
+
variant: 'dark',
|
|
135
|
+
accentColor: '#7008E7',
|
|
136
|
+
thumbnailUrl: 'https://cdn.example.com/other.jpg',
|
|
137
|
+
})
|
|
138
|
+
expect(result.current.thumbnailUrl).toBe(
|
|
139
|
+
'https://cdn.example.com/other.jpg'
|
|
140
|
+
)
|
|
141
|
+
expect(result.current.accentHex).toBe('#7008E7')
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it.each([
|
|
145
|
+
['dark', '#FFFFFF'],
|
|
146
|
+
['light', '#040403'],
|
|
147
|
+
] as const)('inks the %s surface with %s', (variant, ink) => {
|
|
148
|
+
const { result } = render({ variant })
|
|
149
|
+
expect(result.current.chinTextColor).toBe(ink)
|
|
150
|
+
expect(result.current.surface).toBe(variant)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('treats the audio strip as a light surface on either side', () => {
|
|
154
|
+
const { result } = render({
|
|
155
|
+
variant: 'dark',
|
|
156
|
+
mimeType: 'audio/mpeg',
|
|
157
|
+
sourceUrl: 'https://cdn.example.com/clip.mp3',
|
|
158
|
+
})
|
|
159
|
+
expect(result.current.chinTextColor).toBe('#040403')
|
|
160
|
+
expect(result.current.surface).toBe('light')
|
|
161
|
+
})
|
|
162
|
+
})
|
|
@@ -141,11 +141,11 @@ export function createMockMessagingClient({
|
|
|
141
141
|
})
|
|
142
142
|
// Read/unread bookkeeping consults channel mute status; without a live
|
|
143
143
|
// connection the real method throws, so report "not muted".
|
|
144
|
-
channel.muteStatus = (
|
|
144
|
+
channel.muteStatus = () => ({
|
|
145
145
|
muted: false,
|
|
146
146
|
createdAt: null,
|
|
147
147
|
expiresAt: null,
|
|
148
|
-
})
|
|
148
|
+
})
|
|
149
149
|
|
|
150
150
|
// Neutralise the rest of the connection-dependent channel API that
|
|
151
151
|
// stream-chat-react calls during the chat lifecycle. Each of these POSTs to
|