@linktr.ee/messaging-react 4.1.6-rc-1787162010 → 4.1.6-rc-1787162048

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.6-rc-1787162010",
3
+ "version": "4.1.6-rc-1787162048",
4
4
  "description": "React messaging components built on messaging-core for web applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -50,17 +50,19 @@
50
50
  "chromatic:local": "yarn storybook:build && chromatic"
51
51
  },
52
52
  "dependencies": {
53
- "@linktr.ee/messaging-core": "2.4.0-rc-1787162010",
53
+ "@linktr.ee/messaging-core": "2.5.0-rc-1787162048",
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-docs": "10.5.7",
61
- "@storybook/addon-links": "10.5.7",
62
- "@storybook/react": "10.5.7",
63
- "@storybook/react-vite": "10.5.7",
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",
64
66
  "@tailwindcss/container-queries": "^0.1.1",
65
67
  "@testing-library/dom": "^10.0.0",
66
68
  "@testing-library/jest-dom": "^6.1.5",
@@ -77,7 +79,7 @@
77
79
  "postcss": "^8.4.49",
78
80
  "react": "^18.3.1",
79
81
  "react-dom": "^18.3.1",
80
- "storybook": "10.5.7",
82
+ "storybook": "^8.5.0",
81
83
  "stream-chat": "^9.41.1",
82
84
  "stream-chat-react": "^13.14.5",
83
85
  "tailwindcss": "^3.4.17",
@@ -0,0 +1,197 @@
1
+ import React from 'react'
2
+ import { describe, expect, it, vi } from 'vitest'
3
+
4
+ import { fireEvent, renderWithProviders, screen } from '../../test/utils'
5
+
6
+ import { FaqListItem } from './FaqListItem'
7
+
8
+ import { FaqList } from './index'
9
+
10
+ const faqs = [
11
+ {
12
+ id: 'second',
13
+ question: 'What payment methods do you accept?',
14
+ answer: 'Cards and bank transfers.',
15
+ enabled: true,
16
+ order: 2,
17
+ },
18
+ {
19
+ id: 'disabled',
20
+ question: 'What is your phone number?',
21
+ answer: 'This FAQ is disabled.',
22
+ enabled: false,
23
+ order: 0,
24
+ },
25
+ {
26
+ id: 'first',
27
+ question: 'How do I get started?',
28
+ answer: 'Create an account.',
29
+ enabled: true,
30
+ order: 1,
31
+ },
32
+ ]
33
+
34
+ const baseItemClasses = [
35
+ 'w-full',
36
+ 'text-center',
37
+ 'p-4',
38
+ 'rounded-xl',
39
+ 'text-charcoal',
40
+ 'font-medium',
41
+ 'transition-colors',
42
+ 'focus-ring',
43
+ ]
44
+
45
+ describe('FaqListItem', () => {
46
+ it('renders its question and defaults to an enabled button', () => {
47
+ renderWithProviders(
48
+ <FaqListItem question="How do I get started?" onClick={vi.fn()} />
49
+ )
50
+
51
+ const button = screen.getByRole('button', {
52
+ name: 'How do I get started?',
53
+ })
54
+ expect(button).toBeEnabled()
55
+ expect(button.className.split(/\s+/)).toEqual([
56
+ ...baseItemClasses,
57
+ 'hover:brightness-95',
58
+ 'active:brightness-90',
59
+ ])
60
+ })
61
+
62
+ it('renders the FAQ surface color', () => {
63
+ renderWithProviders(
64
+ <FaqListItem question="How do I get started?" onClick={vi.fn()} />
65
+ )
66
+
67
+ expect(
68
+ screen.getByRole('button', { name: 'How do I get started?' })
69
+ ).toHaveStyle({ backgroundColor: '#E6E5E3' })
70
+ })
71
+
72
+ it('uses loading-only classes and blocks clicks while loading', () => {
73
+ const onClick = vi.fn()
74
+ renderWithProviders(
75
+ <FaqListItem question="How do I get started?" onClick={onClick} loading />
76
+ )
77
+
78
+ const button = screen.getByRole('button', {
79
+ name: 'How do I get started?',
80
+ })
81
+ expect(button).toBeDisabled()
82
+ expect(button.className.split(/\s+/)).toEqual([
83
+ ...baseItemClasses,
84
+ 'opacity-50',
85
+ 'cursor-not-allowed',
86
+ ])
87
+
88
+ fireEvent.click(button)
89
+ expect(onClick).not.toHaveBeenCalled()
90
+ })
91
+
92
+ it('calls the click handler once when enabled', () => {
93
+ const onClick = vi.fn()
94
+ renderWithProviders(
95
+ <FaqListItem question="How do I get started?" onClick={onClick} />
96
+ )
97
+
98
+ fireEvent.click(screen.getByRole('button'))
99
+ expect(onClick).toHaveBeenCalledTimes(1)
100
+ })
101
+ })
102
+
103
+ describe('FaqList', () => {
104
+ it('returns nothing when no FAQ is enabled', () => {
105
+ const { container } = renderWithProviders(
106
+ <FaqList
107
+ faqs={faqs.map((faq) => ({ ...faq, enabled: false }))}
108
+ onFaqClick={vi.fn()}
109
+ />
110
+ )
111
+
112
+ expect(container.firstChild).toBeNull()
113
+ })
114
+
115
+ it('renders enabled FAQs in ascending order and filters disabled FAQs', () => {
116
+ renderWithProviders(<FaqList faqs={faqs} onFaqClick={vi.fn()} />)
117
+
118
+ expect(
119
+ screen.getAllByRole('button').map((button) => button.textContent)
120
+ ).toEqual(['How do I get started?', 'What payment methods do you accept?'])
121
+ expect(
122
+ screen.queryByRole('button', { name: 'What is your phone number?' })
123
+ ).toBeNull()
124
+ })
125
+
126
+ it('renders the header only when headerText is provided', () => {
127
+ const { rerender } = renderWithProviders(
128
+ <FaqList faqs={faqs} onFaqClick={vi.fn()} />
129
+ )
130
+ expect(screen.queryByText('Frequently asked questions')).toBeNull()
131
+
132
+ rerender(
133
+ <FaqList
134
+ faqs={faqs}
135
+ onFaqClick={vi.fn()}
136
+ headerText="Frequently asked questions"
137
+ />
138
+ )
139
+ expect(screen.getByText('Frequently asked questions')).toBeInTheDocument()
140
+ })
141
+
142
+ it('passes className to the list root', () => {
143
+ const { container } = renderWithProviders(
144
+ <FaqList
145
+ faqs={faqs}
146
+ onFaqClick={vi.fn()}
147
+ className="faq-list-custom-class"
148
+ />
149
+ )
150
+
151
+ expect(container.firstElementChild).toHaveClass('faq-list-custom-class')
152
+ })
153
+
154
+ it('renders an avatar only when avatar data is provided', () => {
155
+ const { rerender } = renderWithProviders(
156
+ <FaqList faqs={faqs} onFaqClick={vi.fn()} />
157
+ )
158
+ expect(screen.queryAllByTestId('avatar-ring')).toHaveLength(0)
159
+
160
+ rerender(
161
+ <FaqList faqs={faqs} onFaqClick={vi.fn()} avatarName="Brie Nala" />
162
+ )
163
+ expect(screen.queryAllByTestId('avatar-ring')).toHaveLength(1)
164
+
165
+ rerender(
166
+ <FaqList
167
+ faqs={faqs}
168
+ onFaqClick={vi.fn()}
169
+ avatarImage="https://cdn.example.com/avatar.jpg"
170
+ />
171
+ )
172
+ expect(screen.queryAllByTestId('avatar-ring')).toHaveLength(1)
173
+ })
174
+
175
+ it('passes the clicked FAQ id and marks only its matching row as loading', () => {
176
+ const onFaqClick = vi.fn()
177
+ renderWithProviders(
178
+ <FaqList faqs={faqs} onFaqClick={onFaqClick} loadingFaqId="second" />
179
+ )
180
+
181
+ const firstButton = screen.getByRole('button', {
182
+ name: 'How do I get started?',
183
+ })
184
+ const secondButton = screen.getByRole('button', {
185
+ name: 'What payment methods do you accept?',
186
+ })
187
+ expect(firstButton).toBeEnabled()
188
+ expect(secondButton).toBeDisabled()
189
+ expect(firstButton).not.toHaveClass('opacity-50', 'cursor-not-allowed')
190
+ expect(secondButton).toHaveClass('opacity-50', 'cursor-not-allowed')
191
+
192
+ fireEvent.click(firstButton)
193
+ fireEvent.click(secondButton)
194
+ expect(onFaqClick).toHaveBeenCalledTimes(1)
195
+ expect(onFaqClick).toHaveBeenCalledWith('first')
196
+ })
197
+ })