@linktr.ee/messaging-react 4.1.7-rc-1787202545 → 4.1.7-rc-1787205384
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 +4 -4
- package/src/components/MessageAttachment/_shared/fileMeta.test.ts +0 -44
- package/src/components/MessageAttachment/MessageAttachment.behavior.test.tsx +0 -182
- package/src/components/MessageAttachment/_shared/Bubble.test.tsx +0 -77
- package/src/components/MessageAttachment/_shared/CarouselNav.test.tsx +0 -36
- package/src/components/MessageAttachment/_shared/CompactDocumentRow.test.tsx +0 -116
- package/src/components/MessageAttachment/_shared/DismissButton.test.tsx +0 -35
- package/src/components/MessageAttachment/_shared/DownloadAction.test.tsx +0 -170
- package/src/components/MessageAttachment/_shared/ImageViewer.test.tsx +0 -52
- package/src/components/MessageAttachment/_shared/MediaStackGrid.test.tsx +0 -69
- package/src/components/MessageAttachment/_shared/PdfViewer.test.tsx +0 -45
- package/src/components/MessageAttachment/_shared/VideoViewer.test.tsx +0 -55
- package/src/components/MessageAttachment/_shared/ViewerShell.test.tsx +0 -246
- package/src/components/MessageAttachment/_shared/triggerDownload.test.ts +0 -113
- package/src/components/MessageAttachment/_shared/useCarousel.test.tsx +0 -68
- package/src/components/MessageAttachment/_shared/viewerChromeClasses.test.ts +0 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linktr.ee/messaging-react",
|
|
3
|
-
"version": "4.1.7-rc-
|
|
3
|
+
"version": "4.1.7-rc-1787205384",
|
|
4
4
|
"description": "React messaging components built on messaging-core for web applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"test:ci": "vitest run",
|
|
41
41
|
"test:ui": "vitest --ui",
|
|
42
42
|
"test:coverage": "vitest --coverage",
|
|
43
|
-
"lint": "npx --no-install eslint
|
|
44
|
-
"lint:fix": "npx --no-install eslint
|
|
43
|
+
"lint": "cd \"$PROJECT_CWD\" && npx --no-install eslint packages/messaging-react",
|
|
44
|
+
"lint:fix": "cd \"$PROJECT_CWD\" && npx --no-install eslint packages/messaging-react --fix",
|
|
45
45
|
"verify": "yarn type-check && yarn lint && yarn test:ci && yarn build",
|
|
46
46
|
"storybook": "storybook dev -p 6006",
|
|
47
47
|
"storybook:build": "storybook build --stats-json",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"chromatic:local": "yarn storybook:build && chromatic"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@linktr.ee/messaging-core": "2.5.0-rc-
|
|
53
|
+
"@linktr.ee/messaging-core": "2.5.0-rc-1787205384",
|
|
54
54
|
"@linktr.ee/messaging-taxonomy": "^0.10.0",
|
|
55
55
|
"@phosphor-icons/react": "^2.1.10"
|
|
56
56
|
},
|
|
@@ -25,14 +25,6 @@ describe('formatFileSize', () => {
|
|
|
25
25
|
expect(formatFileSize(Infinity)).toBe('')
|
|
26
26
|
expect(formatFileSize(-1)).toBe('')
|
|
27
27
|
})
|
|
28
|
-
|
|
29
|
-
it('handles unit boundaries without crossing into the next unit early', () => {
|
|
30
|
-
expect(formatFileSize(1023)).toBe('1023 B')
|
|
31
|
-
expect(formatFileSize(1024 * 1024 - 1)).toBe('1024.0 KB')
|
|
32
|
-
expect(formatFileSize(1024 * 1024)).toBe('1.00 MB')
|
|
33
|
-
expect(formatFileSize(1024 ** 3 - 1)).toBe('1024.00 MB')
|
|
34
|
-
expect(formatFileSize(1024 ** 3)).toBe('1.00 GB')
|
|
35
|
-
})
|
|
36
28
|
})
|
|
37
29
|
|
|
38
30
|
describe('getFileExtensionLabel', () => {
|
|
@@ -51,18 +43,6 @@ describe('getFileExtensionLabel', () => {
|
|
|
51
43
|
expect(getFileExtensionLabel('application/octet-stream')).toBeUndefined()
|
|
52
44
|
expect(getFileExtensionLabel()).toBeUndefined()
|
|
53
45
|
})
|
|
54
|
-
|
|
55
|
-
it('handles dot boundaries, extension length, and MIME fallbacks', () => {
|
|
56
|
-
expect(getFileExtensionLabel('text/plain', '.gitignore')).toBe('TXT')
|
|
57
|
-
expect(getFileExtensionLabel('text/plain', 'notes.')).toBe('TXT')
|
|
58
|
-
expect(getFileExtensionLabel('image/webp', 'photo.webp')).toBe('WEBP')
|
|
59
|
-
expect(getFileExtensionLabel('image/webp', 'photo.abcdef')).toBe('WEBP')
|
|
60
|
-
expect(getFileExtensionLabel('application/json', 'data.12345')).toBe(
|
|
61
|
-
'12345'
|
|
62
|
-
)
|
|
63
|
-
expect(getFileExtensionLabel('image/*')).toBeUndefined()
|
|
64
|
-
expect(getFileExtensionLabel('application/octet-stream')).toBeUndefined()
|
|
65
|
-
})
|
|
66
46
|
})
|
|
67
47
|
|
|
68
48
|
describe('buildCompactMetaLabel', () => {
|
|
@@ -79,23 +59,6 @@ describe('buildCompactMetaLabel', () => {
|
|
|
79
59
|
it('returns undefined when nothing is renderable', () => {
|
|
80
60
|
expect(buildCompactMetaLabel()).toBeUndefined()
|
|
81
61
|
})
|
|
82
|
-
|
|
83
|
-
it('drops non-positive and non-number sizes while retaining size-only labels', () => {
|
|
84
|
-
expect(buildCompactMetaLabel('application/pdf', 'report.pdf', 0)).toBe(
|
|
85
|
-
'PDF'
|
|
86
|
-
)
|
|
87
|
-
expect(buildCompactMetaLabel('application/pdf', 'report.pdf', -1)).toBe(
|
|
88
|
-
'PDF'
|
|
89
|
-
)
|
|
90
|
-
expect(buildCompactMetaLabel(undefined, undefined, 1024)).toBe('1.0 KB')
|
|
91
|
-
expect(
|
|
92
|
-
buildCompactMetaLabel(
|
|
93
|
-
'application/octet-stream',
|
|
94
|
-
undefined,
|
|
95
|
-
'1024' as never
|
|
96
|
-
)
|
|
97
|
-
).toBeUndefined()
|
|
98
|
-
})
|
|
99
62
|
})
|
|
100
63
|
|
|
101
64
|
describe('filenameFromUrl', () => {
|
|
@@ -114,11 +77,4 @@ describe('filenameFromUrl', () => {
|
|
|
114
77
|
it('falls back to a default when the URL cannot be parsed', () => {
|
|
115
78
|
expect(filenameFromUrl('not a url at all')).toBe('download')
|
|
116
79
|
})
|
|
117
|
-
|
|
118
|
-
it('handles trailing slashes, deep paths, and query strings', () => {
|
|
119
|
-
expect(filenameFromUrl('https://cdn.example.com/folder/')).toBe('download')
|
|
120
|
-
expect(
|
|
121
|
-
filenameFromUrl('https://cdn.example.com/a/b/c/report.pdf?download=1')
|
|
122
|
-
).toBe('report.pdf')
|
|
123
|
-
})
|
|
124
80
|
})
|
|
@@ -1,182 +0,0 @@
|
|
|
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
|
-
})
|
|
@@ -1,77 +0,0 @@
|
|
|
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).toHaveClass('bg-[#1e2330]', 'text-white', 'border')
|
|
39
|
-
expect(bubble).toHaveClass('rounded-tr-[4px]', 'rounded-br-[4px]')
|
|
40
|
-
expect(bubble).toHaveAttribute('data-group-position', 'middle')
|
|
41
|
-
expect(bubble).toHaveClass('custom')
|
|
42
|
-
expect(bubble).toHaveTextContent('child')
|
|
43
|
-
|
|
44
|
-
rerender(
|
|
45
|
-
<Bubble
|
|
46
|
-
variant="light"
|
|
47
|
-
bordered={false}
|
|
48
|
-
groupPosition="first"
|
|
49
|
-
data-testid="bubble"
|
|
50
|
-
>
|
|
51
|
-
child
|
|
52
|
-
</Bubble>
|
|
53
|
-
)
|
|
54
|
-
bubble = screen.getByTestId('bubble')
|
|
55
|
-
expect(bubble).toHaveClass('bg-[#f2f1ef]', 'text-[#000000]')
|
|
56
|
-
expect(bubble).not.toHaveClass('border', 'border-black/[0.08]')
|
|
57
|
-
expect(bubble).toHaveClass('rounded-bl-[4px]')
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('lets an explicit radius replace the group corner table', () => {
|
|
61
|
-
renderWithProviders(
|
|
62
|
-
<Bubble
|
|
63
|
-
variant="light"
|
|
64
|
-
groupPosition="middle"
|
|
65
|
-
radiusClassName="rounded-[20px]"
|
|
66
|
-
widthClassName="w-fit"
|
|
67
|
-
paddingClassName="p-0.5"
|
|
68
|
-
data-testid="bubble"
|
|
69
|
-
>
|
|
70
|
-
child
|
|
71
|
-
</Bubble>
|
|
72
|
-
)
|
|
73
|
-
const bubble = screen.getByTestId('bubble')
|
|
74
|
-
expect(bubble).toHaveClass('rounded-[20px]', 'w-fit', 'p-0.5')
|
|
75
|
-
expect(bubble).not.toHaveClass('rounded-tl-[4px]')
|
|
76
|
-
})
|
|
77
|
-
})
|
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
})
|
|
@@ -1,116 +0,0 @@
|
|
|
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
|
-
expect(screen.getByText('PDF')).toHaveClass('text-white/55')
|
|
60
|
-
const darkIconTile = container.querySelector('div[aria-hidden]')
|
|
61
|
-
expect(darkIconTile).toHaveClass('bg-white/10')
|
|
62
|
-
expect(darkIconTile?.querySelector('svg')).toHaveClass(
|
|
63
|
-
'size-6',
|
|
64
|
-
'text-white/85'
|
|
65
|
-
)
|
|
66
|
-
expect(screen.getByRole('button', { name: 'Open report' })).toHaveClass(
|
|
67
|
-
'hover:bg-white/[0.04]'
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
rerender(
|
|
71
|
-
<CompactDocumentRow
|
|
72
|
-
variant="light"
|
|
73
|
-
filename="report.pdf"
|
|
74
|
-
onActivate={onActivate}
|
|
75
|
-
activateLabel="Open report"
|
|
76
|
-
/>
|
|
77
|
-
)
|
|
78
|
-
expect(screen.getByText('PDF')).toHaveClass('text-black/65')
|
|
79
|
-
const lightIconTile = container.querySelector('div[aria-hidden]')
|
|
80
|
-
expect(lightIconTile).toHaveClass('bg-black/5')
|
|
81
|
-
expect(lightIconTile?.querySelector('svg')).toHaveClass(
|
|
82
|
-
'size-6',
|
|
83
|
-
'text-black/85'
|
|
84
|
-
)
|
|
85
|
-
expect(screen.getByRole('button', { name: 'Open report' })).toHaveClass(
|
|
86
|
-
'hover:bg-black/[0.04]'
|
|
87
|
-
)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it('activates its body without nesting the trailing action', () => {
|
|
91
|
-
const onActivate = vi.fn()
|
|
92
|
-
renderWithProviders(
|
|
93
|
-
<CompactDocumentRow
|
|
94
|
-
variant="dark"
|
|
95
|
-
filename="report.pdf"
|
|
96
|
-
onActivate={onActivate}
|
|
97
|
-
activateLabel="Open report"
|
|
98
|
-
trailingAction={<button type="button">Download</button>}
|
|
99
|
-
/>
|
|
100
|
-
)
|
|
101
|
-
const body = screen.getByRole('button', { name: 'Open report' })
|
|
102
|
-
expect(body).toBeInTheDocument()
|
|
103
|
-
expect(body).not.toContainElement(
|
|
104
|
-
screen.getByRole('button', { name: 'Download' })
|
|
105
|
-
)
|
|
106
|
-
fireEvent.click(body)
|
|
107
|
-
expect(onActivate).toHaveBeenCalledOnce()
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
it('renders a plain body when activation is omitted', () => {
|
|
111
|
-
renderWithProviders(
|
|
112
|
-
<CompactDocumentRow variant="dark" filename="report.pdf" />
|
|
113
|
-
)
|
|
114
|
-
expect(screen.queryByRole('button', { name: /report/ })).toBeNull()
|
|
115
|
-
})
|
|
116
|
-
})
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
renderWithProviders(
|
|
25
|
-
<DismissButton
|
|
26
|
-
onClick={vi.fn()}
|
|
27
|
-
ariaLabel="Remove file"
|
|
28
|
-
variant="inline"
|
|
29
|
-
/>
|
|
30
|
-
)
|
|
31
|
-
const button = screen.getByRole('button', { name: 'Remove file' })
|
|
32
|
-
expect(button).toHaveClass('bg-white/15')
|
|
33
|
-
expect(button).not.toHaveClass('bg-[#121110]/85')
|
|
34
|
-
})
|
|
35
|
-
})
|