@linktr.ee/messaging-react 4.1.7-rc-1787240421 → 4.1.7-rc-1787247439

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linktr.ee/messaging-react",
3
- "version": "4.1.7-rc-1787240421",
3
+ "version": "4.1.7-rc-1787247439",
4
4
  "description": "React messaging components built on messaging-core for web applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -50,19 +50,17 @@
50
50
  "chromatic:local": "yarn storybook:build && chromatic"
51
51
  },
52
52
  "dependencies": {
53
- "@linktr.ee/messaging-core": "2.5.0-rc-1787240421",
53
+ "@linktr.ee/messaging-core": "2.5.0-rc-1787247439",
54
54
  "@linktr.ee/messaging-taxonomy": "^0.10.0",
55
55
  "@phosphor-icons/react": "^2.1.10"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@linktr.ee/arbor": "25.0.0",
59
59
  "@linktr.ee/design-tokens": "14.0.0",
60
- "@storybook/addon-essentials": "^8.5.0",
61
- "@storybook/addon-interactions": "^8.5.0",
62
- "@storybook/addon-links": "^8.5.0",
63
- "@storybook/react": "^8.5.0",
64
- "@storybook/react-vite": "^8.5.0",
65
- "@storybook/test": "^8.5.0",
60
+ "@storybook/addon-docs": "10.5.7",
61
+ "@storybook/addon-links": "10.5.7",
62
+ "@storybook/react": "10.5.7",
63
+ "@storybook/react-vite": "10.5.7",
66
64
  "@tailwindcss/container-queries": "^0.1.1",
67
65
  "@testing-library/dom": "^10.0.0",
68
66
  "@testing-library/jest-dom": "^6.1.5",
@@ -79,7 +77,7 @@
79
77
  "postcss": "^8.4.49",
80
78
  "react": "^18.3.1",
81
79
  "react-dom": "^18.3.1",
82
- "storybook": "^8.5.0",
80
+ "storybook": "10.5.7",
83
81
  "stream-chat": "^9.41.1",
84
82
  "stream-chat-react": "^13.14.5",
85
83
  "tailwindcss": "^3.4.17",
@@ -0,0 +1,182 @@
1
+ import { describe, expect, it, vi } from 'vitest'
2
+
3
+ import { fireEvent, renderWithProviders, screen } from '../../test/utils'
4
+
5
+ import { triggerDownload } from './_shared/triggerDownload'
6
+ import { bubbleVariantForState, bubbleGroupPositionFromStream } from './types'
7
+
8
+ import MessageAttachment from '.'
9
+
10
+ vi.mock('./_shared/triggerDownload', () => ({
11
+ triggerDownload: vi.fn(() => Promise.resolve()),
12
+ }))
13
+
14
+ const mockedDownload = vi.mocked(triggerDownload)
15
+
16
+ describe('MessageAttachment behavior', () => {
17
+ it('renders file rows with precedence, fallback names, and cancellation', () => {
18
+ const onClick = vi.fn(() => false)
19
+ const { rerender } = renderWithProviders(
20
+ <MessageAttachment.File.Sent
21
+ src="https://cdn.example.com/fallback.txt"
22
+ filename="fallback.txt"
23
+ items={[
24
+ {
25
+ src: 'https://cdn.example.com/first.pdf',
26
+ filename: 'first.pdf',
27
+ },
28
+ { src: 'https://cdn.example.com/second.pdf' },
29
+ ]}
30
+ onClick={onClick}
31
+ />
32
+ )
33
+ expect(screen.getByText('first.pdf')).toBeInTheDocument()
34
+ expect(screen.getByText('second.pdf')).toBeInTheDocument()
35
+ fireEvent.click(screen.getByRole('button', { name: 'Download first.pdf' }))
36
+ expect(onClick).toHaveBeenCalledWith(0)
37
+ expect(mockedDownload).not.toHaveBeenCalled()
38
+
39
+ rerender(
40
+ <MessageAttachment.File.Sent src="https://cdn.example.com/fallback.txt" />
41
+ )
42
+ fireEvent.click(
43
+ screen.getByRole('button', { name: 'Download fallback.txt' })
44
+ )
45
+ expect(mockedDownload).toHaveBeenCalledWith(
46
+ 'https://cdn.example.com/fallback.txt',
47
+ 'fallback.txt'
48
+ )
49
+ })
50
+
51
+ it('renders no file when inputs are absent and supports composer dismissal', () => {
52
+ const { container } = renderWithProviders(
53
+ <MessageAttachment.File.Received />
54
+ )
55
+ expect(container.firstChild).toBeNull()
56
+ const onDismiss = vi.fn()
57
+ renderWithProviders(
58
+ <MessageAttachment.File.Composer
59
+ src="https://cdn.example.com/file"
60
+ onDismiss={onDismiss}
61
+ />
62
+ )
63
+ fireEvent.click(screen.getByRole('button', { name: 'Dismiss attachment' }))
64
+ expect(onDismiss).toHaveBeenCalledOnce()
65
+ })
66
+
67
+ it('renders image stacks, forwards loading, and supports click cancellation', () => {
68
+ const onClick = vi.fn(() => false)
69
+ renderWithProviders(
70
+ <MessageAttachment.Image.Sent
71
+ src="https://cdn.example.com/fallback.jpg"
72
+ items={[
73
+ { src: 'https://cdn.example.com/one.jpg' },
74
+ { src: 'https://cdn.example.com/two.jpg', loading: 'eager' },
75
+ ]}
76
+ loading="lazy"
77
+ onClick={onClick}
78
+ />
79
+ )
80
+ expect(screen.getAllByRole('img')[0]).toHaveAttribute('loading', 'lazy')
81
+ expect(screen.getAllByRole('img')).toHaveLength(2)
82
+ fireEvent.click(screen.getByRole('button', { name: 'Open image 2 of 2' }))
83
+ expect(onClick).toHaveBeenCalledWith(1)
84
+ expect(screen.queryByTestId('image-viewer')).not.toHaveAttribute('open')
85
+ })
86
+
87
+ it('opens images at the clicked index and suffixes a shared filename', () => {
88
+ renderWithProviders(
89
+ <MessageAttachment.Image.Sent
90
+ filename="photos.jpg"
91
+ items={[
92
+ { src: 'https://cdn.example.com/one.jpg' },
93
+ { src: 'https://cdn.example.com/two.jpg' },
94
+ ]}
95
+ />
96
+ )
97
+ fireEvent.click(screen.getByRole('button', { name: 'Open image 2 of 2' }))
98
+ expect(screen.getByTestId('image-viewer')).toHaveAttribute(
99
+ 'aria-label',
100
+ 'photos.jpg (2)'
101
+ )
102
+ expect(screen.getByRole('img', { name: 'photos.jpg (2)' })).toHaveAttribute(
103
+ 'src',
104
+ 'https://cdn.example.com/two.jpg'
105
+ )
106
+ })
107
+
108
+ it('renders video poster and fallback, and wires viewer attributes', () => {
109
+ const onDismiss = vi.fn()
110
+ const { rerender } = renderWithProviders(
111
+ <MessageAttachment.Video.Composer
112
+ src="https://cdn.example.com/video.mp4"
113
+ poster="/poster.jpg"
114
+ mimeType="video/mp4"
115
+ preload="auto"
116
+ onDismiss={onDismiss}
117
+ />
118
+ )
119
+ expect(
120
+ screen.getByRole('img', { name: 'Video 1 thumbnail' })
121
+ ).toHaveAttribute('src', '/poster.jpg')
122
+ fireEvent.click(screen.getByRole('button', { name: 'Dismiss attachment' }))
123
+ expect(onDismiss).toHaveBeenCalledOnce()
124
+ rerender(
125
+ <MessageAttachment.Video.Sent
126
+ items={[{ src: 'https://cdn.example.com/video.mp4' }]}
127
+ />
128
+ )
129
+ expect(screen.getByLabelText('Play video 1 of 1')).toBeInTheDocument()
130
+ })
131
+
132
+ it('supports PDF titles, download actions, dismiss, and viewer index', () => {
133
+ const onDismiss = vi.fn()
134
+ renderWithProviders(
135
+ <MessageAttachment.Pdf.Composer
136
+ src="https://cdn.example.com/report.pdf"
137
+ title="Quarterly report"
138
+ onDismiss={onDismiss}
139
+ />
140
+ )
141
+ expect(screen.getByText('Quarterly report')).toBeInTheDocument()
142
+ fireEvent.click(screen.getByRole('button', { name: 'Dismiss attachment' }))
143
+ expect(onDismiss).toHaveBeenCalledOnce()
144
+
145
+ renderWithProviders(
146
+ <MessageAttachment.Pdf.Sent
147
+ items={[
148
+ { src: 'https://cdn.example.com/one.pdf' },
149
+ { src: 'https://cdn.example.com/two.pdf', filename: 'two.pdf' },
150
+ ]}
151
+ />
152
+ )
153
+ fireEvent.click(screen.getByRole('button', { name: 'Open two.pdf' }))
154
+ expect(screen.getAllByTestId('pdf-viewer').at(-1)).toHaveAttribute(
155
+ 'aria-label',
156
+ 'two.pdf'
157
+ )
158
+ })
159
+
160
+ it('maps state and stream grouping contracts', () => {
161
+ expect(bubbleVariantForState('composer')).toBe('dark')
162
+ expect(bubbleVariantForState('sent')).toBe('dark')
163
+ expect(bubbleVariantForState('received')).toBe('light')
164
+ expect(bubbleGroupPositionFromStream({})).toBe('single')
165
+ expect(
166
+ bubbleGroupPositionFromStream({
167
+ groupedByUser: true,
168
+ firstOfGroup: true,
169
+ endOfGroup: true,
170
+ })
171
+ ).toBe('single')
172
+ expect(
173
+ bubbleGroupPositionFromStream({ groupedByUser: true, firstOfGroup: true })
174
+ ).toBe('first')
175
+ expect(
176
+ bubbleGroupPositionFromStream({ groupedByUser: true, endOfGroup: true })
177
+ ).toBe('end')
178
+ expect(bubbleGroupPositionFromStream({ groupedByUser: true })).toBe(
179
+ 'middle'
180
+ )
181
+ })
182
+ })
@@ -0,0 +1,111 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { renderWithProviders, screen } from '../../../test/utils'
4
+
5
+ import Bubble from './Bubble'
6
+
7
+ describe('Bubble', () => {
8
+ it.each([
9
+ [undefined, false],
10
+ [null, false],
11
+ ['', false],
12
+ ['caption', true],
13
+ [0, true],
14
+ ])('renders caption %j according to its value', (text, present) => {
15
+ renderWithProviders(
16
+ <Bubble variant="dark" text={text} data-testid="bubble">
17
+ <span>child</span>
18
+ </Bubble>
19
+ )
20
+ const bubble = screen.getByTestId('bubble')
21
+ if (present) expect(bubble.querySelector('p')).not.toBeNull()
22
+ else expect(bubble.querySelector('p')).toBeNull()
23
+ expect(bubble).toHaveClass(present ? 'pb-0' : 'py-2')
24
+ })
25
+
26
+ it('maps variants, group positions, borders, and forwarded content', () => {
27
+ const { rerender } = renderWithProviders(
28
+ <Bubble
29
+ variant="dark"
30
+ groupPosition="middle"
31
+ data-testid="bubble"
32
+ className="custom"
33
+ >
34
+ child
35
+ </Bubble>
36
+ )
37
+ let bubble = screen.getByTestId('bubble')
38
+ expect(bubble).toHaveAttribute('data-group-position', 'middle')
39
+ expect(bubble).toHaveClass('custom')
40
+ expect(bubble).toHaveTextContent('child')
41
+ const darkMiddle = bubble.className
42
+
43
+ rerender(
44
+ <Bubble
45
+ variant="light"
46
+ groupPosition="middle"
47
+ data-testid="bubble"
48
+ className="custom"
49
+ >
50
+ child
51
+ </Bubble>
52
+ )
53
+ bubble = screen.getByTestId('bubble')
54
+ const lightMiddle = bubble.className
55
+ expect(lightMiddle).not.toBe(darkMiddle)
56
+
57
+ rerender(
58
+ <Bubble
59
+ variant="light"
60
+ groupPosition="first"
61
+ data-testid="bubble"
62
+ className="custom"
63
+ >
64
+ child
65
+ </Bubble>
66
+ )
67
+ bubble = screen.getByTestId('bubble')
68
+ expect(bubble.className).not.toBe(lightMiddle)
69
+ const lightFirstBordered = bubble.className
70
+
71
+ rerender(
72
+ <Bubble
73
+ variant="light"
74
+ bordered={false}
75
+ groupPosition="first"
76
+ data-testid="bubble"
77
+ className="custom"
78
+ >
79
+ child
80
+ </Bubble>
81
+ )
82
+ bubble = screen.getByTestId('bubble')
83
+ const lightFirstBorderless = bubble.className
84
+ expect(lightFirstBorderless).not.toBe(lightFirstBordered)
85
+ expect(lightFirstBordered.split(/\s+/)).toEqual(
86
+ expect.arrayContaining(lightFirstBorderless.split(/\s+/))
87
+ )
88
+ })
89
+
90
+ it('lets an explicit radius replace the group corner table', () => {
91
+ const radiusClassName = 'rounded-[20px]'
92
+ const widthClassName = 'w-fit'
93
+ const paddingClassName = 'p-0.5'
94
+ renderWithProviders(
95
+ <Bubble
96
+ variant="light"
97
+ groupPosition="middle"
98
+ radiusClassName={radiusClassName}
99
+ widthClassName={widthClassName}
100
+ paddingClassName={paddingClassName}
101
+ data-testid="bubble"
102
+ >
103
+ child
104
+ </Bubble>
105
+ )
106
+ const bubble = screen.getByTestId('bubble')
107
+ expect(bubble).toHaveClass(radiusClassName, widthClassName)
108
+ expect(bubble).toHaveClass(paddingClassName)
109
+ expect(bubble.className).not.toMatch(/rounded-tl-\[4px\]/)
110
+ })
111
+ })
@@ -0,0 +1,36 @@
1
+ import { describe, expect, it, vi } from 'vitest'
2
+
3
+ import { fireEvent, renderWithProviders, screen } from '../../../test/utils'
4
+
5
+ import CarouselNav from './CarouselNav'
6
+ import { VIEWER_NAV_CLASS } from './viewerChromeClasses'
7
+
8
+ describe('CarouselNav', () => {
9
+ it('uses default labels and independent handlers', () => {
10
+ const onPrev = vi.fn()
11
+ const onNext = vi.fn()
12
+ renderWithProviders(<CarouselNav onPrev={onPrev} onNext={onNext} />)
13
+
14
+ const prev = screen.getByRole('button', { name: 'Previous' })
15
+ const next = screen.getByRole('button', { name: 'Next' })
16
+ expect(prev).toHaveClass(VIEWER_NAV_CLASS, 'left-4')
17
+ expect(next).toHaveClass(VIEWER_NAV_CLASS, 'right-4')
18
+ fireEvent.click(prev)
19
+ fireEvent.click(next)
20
+ expect(onPrev).toHaveBeenCalledOnce()
21
+ expect(onNext).toHaveBeenCalledOnce()
22
+ })
23
+
24
+ it('supports custom accessible labels', () => {
25
+ renderWithProviders(
26
+ <CarouselNav
27
+ onPrev={vi.fn()}
28
+ onNext={vi.fn()}
29
+ prevLabel="Previous image"
30
+ nextLabel="Next image"
31
+ />
32
+ )
33
+ expect(screen.getByRole('button', { name: 'Previous image' })).toBeVisible()
34
+ expect(screen.getByRole('button', { name: 'Next image' })).toBeVisible()
35
+ })
36
+ })
@@ -0,0 +1,114 @@
1
+ import { describe, expect, it, vi } from 'vitest'
2
+
3
+ import { fireEvent, renderWithProviders, screen } from '../../../test/utils'
4
+
5
+ import CompactDocumentRow from './CompactDocumentRow'
6
+
7
+ describe('CompactDocumentRow', () => {
8
+ it('resolves title from title, filename, then File', () => {
9
+ const { rerender } = renderWithProviders(
10
+ <CompactDocumentRow variant="dark" title="Custom" filename="name.pdf" />
11
+ )
12
+ expect(screen.getByText('Custom')).toBeInTheDocument()
13
+ rerender(<CompactDocumentRow variant="dark" filename="name.pdf" />)
14
+ expect(screen.getByText('name.pdf')).toBeInTheDocument()
15
+ rerender(<CompactDocumentRow variant="dark" />)
16
+ expect(screen.getByText('File')).toBeInTheDocument()
17
+ })
18
+
19
+ it('renders metadata only when it has a value and defaults MIME type', () => {
20
+ const { container, rerender } = renderWithProviders(
21
+ <CompactDocumentRow
22
+ variant="dark"
23
+ filename="report.pdf"
24
+ fileSize={1024}
25
+ />
26
+ )
27
+ expect(screen.getByText('PDF · 1.0 KB')).toBeInTheDocument()
28
+ rerender(
29
+ <CompactDocumentRow
30
+ variant="dark"
31
+ filename="report"
32
+ mimeType="application/octet-stream"
33
+ />
34
+ )
35
+ expect(screen.queryByText(/·/)).toBeNull()
36
+ const genericIconMarkup = container.querySelector('svg')?.innerHTML
37
+ rerender(
38
+ <CompactDocumentRow
39
+ variant="dark"
40
+ filename="report.pdf"
41
+ mimeType="application/pdf"
42
+ />
43
+ )
44
+ expect(container.querySelector('svg')?.innerHTML).not.toBe(
45
+ genericIconMarkup
46
+ )
47
+ })
48
+
49
+ it('maps variant classes across metadata, icon, and activation', () => {
50
+ const onActivate = vi.fn()
51
+ const { container, rerender } = renderWithProviders(
52
+ <CompactDocumentRow
53
+ variant="dark"
54
+ filename="report.pdf"
55
+ onActivate={onActivate}
56
+ activateLabel="Open report"
57
+ />
58
+ )
59
+ const darkMetadata = screen.getByText('PDF').className
60
+ const darkIconTile = container.querySelector('div[aria-hidden]')
61
+ const darkTileClasses = darkIconTile?.className
62
+ const darkIconClasses = darkIconTile
63
+ ?.querySelector('svg')
64
+ ?.getAttribute('class')
65
+ expect(screen.getByRole('button', { name: 'Open report' })).toHaveClass(
66
+ 'hover:bg-white/[0.04]'
67
+ )
68
+
69
+ rerender(
70
+ <CompactDocumentRow
71
+ variant="light"
72
+ filename="report.pdf"
73
+ onActivate={onActivate}
74
+ activateLabel="Open report"
75
+ />
76
+ )
77
+ expect(screen.getByText('PDF').className).not.toBe(darkMetadata)
78
+ const lightIconTile = container.querySelector('div[aria-hidden]')
79
+ expect(lightIconTile?.className).not.toBe(darkTileClasses)
80
+ expect(lightIconTile?.querySelector('svg')?.getAttribute('class')).not.toBe(
81
+ darkIconClasses
82
+ )
83
+ expect(screen.getByRole('button', { name: 'Open report' })).toHaveClass(
84
+ 'hover:bg-black/[0.04]'
85
+ )
86
+ })
87
+
88
+ it('activates its body without nesting the trailing action', () => {
89
+ const onActivate = vi.fn()
90
+ renderWithProviders(
91
+ <CompactDocumentRow
92
+ variant="dark"
93
+ filename="report.pdf"
94
+ onActivate={onActivate}
95
+ activateLabel="Open report"
96
+ trailingAction={<button type="button">Download</button>}
97
+ />
98
+ )
99
+ const body = screen.getByRole('button', { name: 'Open report' })
100
+ expect(body).toBeInTheDocument()
101
+ expect(body).not.toContainElement(
102
+ screen.getByRole('button', { name: 'Download' })
103
+ )
104
+ fireEvent.click(body)
105
+ expect(onActivate).toHaveBeenCalledOnce()
106
+ })
107
+
108
+ it('renders a plain body when activation is omitted', () => {
109
+ renderWithProviders(
110
+ <CompactDocumentRow variant="dark" filename="report.pdf" />
111
+ )
112
+ expect(screen.queryByRole('button', { name: /report/ })).toBeNull()
113
+ })
114
+ })
@@ -0,0 +1,42 @@
1
+ import { describe, expect, it, vi } from 'vitest'
2
+
3
+ import { fireEvent, renderWithProviders, screen } from '../../../test/utils'
4
+
5
+ import DismissButton from './DismissButton'
6
+
7
+ describe('DismissButton', () => {
8
+ it('uses the default label, invokes the handler, and stops propagation', () => {
9
+ const onClick = vi.fn()
10
+ const outerClick = vi.fn()
11
+ renderWithProviders(
12
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
13
+ <div onClick={outerClick}>
14
+ <DismissButton onClick={onClick} />
15
+ </div>
16
+ )
17
+
18
+ fireEvent.click(screen.getByRole('button', { name: 'Dismiss attachment' }))
19
+ expect(onClick).toHaveBeenCalledOnce()
20
+ expect(outerClick).not.toHaveBeenCalled()
21
+ })
22
+
23
+ it('supports a custom label and inline styling', () => {
24
+ const { rerender } = renderWithProviders(
25
+ <DismissButton onClick={vi.fn()} ariaLabel="Remove file" />
26
+ )
27
+ const overlayClasses = screen.getByRole('button', {
28
+ name: 'Remove file',
29
+ }).className
30
+
31
+ rerender(
32
+ <DismissButton
33
+ onClick={vi.fn()}
34
+ ariaLabel="Remove file"
35
+ variant="inline"
36
+ />
37
+ )
38
+ const button = screen.getByRole('button', { name: 'Remove file' })
39
+ expect(button).toHaveClass('hover:bg-white/25')
40
+ expect(button.className).not.toBe(overlayClasses)
41
+ })
42
+ })