@linktr.ee/messaging-react 4.1.6-rc-1787176721 → 4.1.6-rc-1787179587

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-1787176721",
3
+ "version": "4.1.6-rc-1787179587",
4
4
  "description": "React messaging components built on messaging-core for web applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -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-1787176721",
53
+ "@linktr.ee/messaging-core": "2.5.0-rc-1787179587",
54
54
  "@linktr.ee/messaging-taxonomy": "^0.10.0",
55
55
  "@phosphor-icons/react": "^2.1.10"
56
56
  },
@@ -27,4 +27,130 @@ describe('Avatar', () => {
27
27
  it('keeps fixed emoji sizes for larger avatars', () => {
28
28
  expect(emojiFontSize(40)).toHaveStyle({ fontSize: '14px' })
29
29
  })
30
+
31
+ it.each([
32
+ [32, '14px'],
33
+ [55, '14px'],
34
+ [56, '18px'],
35
+ [119, '18px'],
36
+ [120, '36px'],
37
+ ])(
38
+ 'uses the exact fixed font size at the %spx boundary',
39
+ (size, fontSize) => {
40
+ expect(emojiFontSize(size)).toHaveStyle({ fontSize })
41
+ }
42
+ )
43
+
44
+ it('does not show a star by default but shows one when starred', () => {
45
+ const defaultAvatar = renderWithProviders(
46
+ <Avatar id="user-1" name="Alice" />
47
+ )
48
+ expect(defaultAvatar.container.querySelector('svg')).not.toBeInTheDocument()
49
+
50
+ const starredAvatar = renderWithProviders(
51
+ <Avatar id="user-1" name="Alice" starred />
52
+ )
53
+ expect(starredAvatar.container.querySelector('svg')).toBeInTheDocument()
54
+ })
55
+
56
+ it('uses a squircle by default and a circle when explicitly requested', () => {
57
+ const squircleAvatar = renderWithProviders(
58
+ <Avatar id="user-1" name="Alice" />
59
+ )
60
+ const squircleElements = squircleAvatar.container.querySelectorAll(
61
+ '[style*="border-radius"]'
62
+ )
63
+ expect(squircleElements).toHaveLength(3)
64
+ squircleElements.forEach((element) =>
65
+ expect(element).toHaveStyle({ borderRadius: '1rem' })
66
+ )
67
+
68
+ const circleAvatar = renderWithProviders(
69
+ <Avatar id="user-1" name="Alice" shape="circle" />
70
+ )
71
+ const circleElements = circleAvatar.container.querySelectorAll(
72
+ '[style*="border-radius"]'
73
+ )
74
+ expect(circleElements).toHaveLength(3)
75
+ circleElements.forEach((element) =>
76
+ expect(element).toHaveStyle({ borderRadius: '50%' })
77
+ )
78
+ })
79
+
80
+ it('only applies the AI ring when dmAgentEnabled is true', () => {
81
+ const defaultAvatar = renderWithProviders(
82
+ <Avatar id="user-1" name="Alice" size={40} />
83
+ )
84
+ expect(
85
+ defaultAvatar.container.querySelector('[data-testid="avatar-ring"]')
86
+ ).not.toHaveStyle({
87
+ borderWidth: '2px',
88
+ borderStyle: 'solid',
89
+ })
90
+
91
+ const enabledAvatar = renderWithProviders(
92
+ <Avatar id="user-1" name="Alice" size={40} dmAgentEnabled />
93
+ )
94
+ expect(
95
+ enabledAvatar.container.querySelector('[data-testid="avatar-ring"]')
96
+ ).toHaveStyle({
97
+ borderWidth: '2px',
98
+ borderStyle: 'solid',
99
+ borderColor: 'var(--AI-Gradient, #7F22FE)',
100
+ boxShadow: 'inset 0 1px 2px 0 rgba(255, 255, 255, 0.5)',
101
+ })
102
+
103
+ const smallEnabledAvatar = renderWithProviders(
104
+ <Avatar id="user-1" name="Alice" size={20} dmAgentEnabled />
105
+ )
106
+ expect(
107
+ smallEnabledAvatar.container.querySelector('[data-testid="avatar-ring"]')
108
+ ).toHaveStyle({ borderWidth: '1px' })
109
+ })
110
+
111
+ it('renders an image instead of the emoji fallback when image is provided', () => {
112
+ const fallbackAvatar = renderWithProviders(<Avatar id="" name="Alice" />)
113
+ expect(
114
+ fallbackAvatar.container.querySelector('img')
115
+ ).not.toBeInTheDocument()
116
+ expect(fallbackAvatar.container).toHaveTextContent('🍎')
117
+ expect(
118
+ fallbackAvatar.container.querySelector('.avatar-fallback')
119
+ ).toHaveClass(
120
+ 'avatar-fallback',
121
+ 'flex',
122
+ 'h-full',
123
+ 'w-full',
124
+ 'items-center',
125
+ 'justify-center',
126
+ 'font-semibold',
127
+ 'select-none',
128
+ 'transition-colors'
129
+ )
130
+
131
+ const imageAvatar = renderWithProviders(
132
+ <Avatar id="" name="Alice" image="https://example.com/avatar.png" />
133
+ )
134
+ expect(imageAvatar.container.querySelector('img')).toHaveAttribute(
135
+ 'src',
136
+ 'https://example.com/avatar.png'
137
+ )
138
+ expect(imageAvatar.container).not.toHaveTextContent('🍎')
139
+ })
140
+
141
+ it('applies the fallback background color and forwards custom classes', () => {
142
+ const { container } = renderWithProviders(
143
+ <Avatar id="" name="Alice" className="custom-avatar" />
144
+ )
145
+ const root = container.firstElementChild
146
+ const ring = container.querySelector('[data-testid="avatar-ring"]')
147
+
148
+ expect(root).toHaveClass('relative', 'flex-shrink-0', 'custom-avatar')
149
+ expect(ring).toHaveClass('h-full', 'w-full', 'bg-transparent')
150
+ expect(root).toHaveStyle({
151
+ backgroundColor: '#FFD1DD',
152
+ width: '40px',
153
+ height: '40px',
154
+ })
155
+ })
30
156
  })
@@ -29,4 +29,43 @@ describe('getAvatarBgColor', () => {
29
29
  expect(color).toBe(emojiBgColors[emoji])
30
30
  expect(getAvatarBgColor(id)).toBe(color)
31
31
  })
32
+
33
+ it.each([
34
+ ['', '🍎', '#FFD1DD'],
35
+ ['id-2', '🍌', '#FFF1C9'],
36
+ ['id-3', '🍇', '#E6D9FF'],
37
+ ['id-4', '🍊', '#D6F4FF'],
38
+ ['id-5', '🍓', '#FFE0AE'],
39
+ ['id-6', '🥥', '#F7E7D8'],
40
+ ['id-7', '🍒', '#DFF4D8'],
41
+ ['id-8', '🥭', '#FFD8C2'],
42
+ ['id-9', '🍉', '#D6EBFF'],
43
+ ['id-10', '🍋', '#CAEEB5'],
44
+ ['id-11', '🥝', '#FFE7C7'],
45
+ ['id-12', '🫒', '#F6E3B4'],
46
+ ['id-13', '🍈', '#D9F7E1'],
47
+ ])('returns the exact fruit pair for %j', (id, emoji, bgColor) => {
48
+ expect(getAvatarEmoji(id)).toBe(emoji)
49
+ expect(getAvatarBgColor(id)).toBe(bgColor)
50
+ })
51
+
52
+ it('uses the absolute hash value for ids with a negative raw hash', () => {
53
+ const id = 'id-100'
54
+
55
+ expect(getAvatarEmoji(id)).toBe('🥭')
56
+ expect(getAvatarBgColor(id)).toBe('#FFD8C2')
57
+ })
58
+
59
+ it('is deterministic and keeps emoji and background color paired', () => {
60
+ const ids = ['', 'id-2', 'id-7', 'id-13', 'id-100']
61
+
62
+ ids.forEach((id) => {
63
+ const emoji = getAvatarEmoji(id)
64
+ const color = getAvatarBgColor(id)
65
+
66
+ expect(getAvatarEmoji(id)).toBe(emoji)
67
+ expect(getAvatarBgColor(id)).toBe(color)
68
+ expect(emojiBgColors[emoji]).toBe(color)
69
+ })
70
+ })
32
71
  })