Skip to content

Commit 86f811d

Browse files
committed
VIDSOL-10: VERA does not display special characters properly in Participant List, Muted Video Publisher (#210)
1 parent 1dc3860 commit 86f811d

File tree

2 files changed

+141
-5
lines changed

2 files changed

+141
-5
lines changed

frontend/src/utils/getInitials/getInitials.spec.tsx

Lines changed: 137 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,161 @@ describe('getInitials', () => {
7474
});
7575
});
7676

77-
it('returns initials for a simgle character first name', () => {
77+
it('returns initials for a single character first name', () => {
7878
const username = 'l';
7979

8080
const initials = getInitials(username);
8181

8282
expect(initials).toBe('L');
8383
});
8484

85-
it('returns initials for a simgle character last name', () => {
85+
it('returns initials for a single character last name', () => {
8686
const username = 'Daniel Michael B';
8787

8888
const initials = getInitials(username);
8989

9090
expect(initials).toBe('DB');
9191
});
9292

93-
it('returns initials for a simgle character first and last name', () => {
93+
it('returns initials for a single character first and last name', () => {
9494
const username = 's d';
9595

9696
const initials = getInitials(username);
9797

9898
expect(initials).toBe('SD');
9999
});
100+
101+
it('handles Unicode characters with accents', () => {
102+
const username = 'Òscar';
103+
104+
const initials = getInitials(username);
105+
106+
expect(initials).toBe('Ò');
107+
});
108+
109+
it('handles Unicode characters in multiple names', () => {
110+
const username = 'José María';
111+
112+
const initials = getInitials(username);
113+
114+
expect(initials).toBe('JM');
115+
});
116+
117+
it('handles various accented characters', () => {
118+
const testCases = [
119+
{ username: 'François Müller', expected: 'FM' },
120+
{ username: 'Åse Björk', expected: 'ÅB' },
121+
{ username: 'Zürich', expected: 'Z' },
122+
{ username: 'Naïve Café', expected: 'NC' },
123+
{ username: 'Señor López', expected: 'SL' },
124+
];
125+
126+
testCases.forEach(({ username, expected }) => {
127+
const initials = getInitials(username);
128+
expect(initials).toBe(expected);
129+
});
130+
});
131+
132+
it('handles hyphenated names with accents', () => {
133+
const username = 'José-María González';
134+
135+
const initials = getInitials(username);
136+
137+
expect(initials).toBe('JG');
138+
});
139+
140+
it('handles combining diacritical marks', () => {
141+
const username = 'André Müller';
142+
const initials = getInitials(username);
143+
144+
expect(initials).toBe('AM');
145+
});
146+
147+
it('handles Cyrillic characters', () => {
148+
const username = 'Андрій Шевченко';
149+
150+
const initials = getInitials(username);
151+
152+
expect(initials).toBe('АШ');
153+
});
154+
155+
it('handles names with emojis at the beginning', () => {
156+
const username = '😊 John Doe';
157+
158+
const initials = getInitials(username);
159+
160+
expect(initials).toBe('JD');
161+
});
162+
163+
it('handles names with emojis at the end', () => {
164+
const username = 'Jane Smith 🎉';
165+
166+
const initials = getInitials(username);
167+
168+
expect(initials).toBe('JS');
169+
});
170+
171+
it('handles names with emojis in between', () => {
172+
const username = 'Bob 🚀 Wilson';
173+
174+
const initials = getInitials(username);
175+
176+
expect(initials).toBe('BW');
177+
});
178+
179+
it('handles names with multiple emojis', () => {
180+
const username = '🌟 Alice 💫 Cooper 🎭';
181+
182+
const initials = getInitials(username);
183+
184+
expect(initials).toBe('AC');
185+
});
186+
187+
it('handles names that are only emojis', () => {
188+
const username = '😊 🎉';
189+
190+
const initials = getInitials(username);
191+
192+
expect(initials).toBe('');
193+
});
194+
195+
it('handles mixed emoji and unicode text', () => {
196+
const username = '🇫🇷 François 🎨 García';
197+
198+
const initials = getInitials(username);
199+
200+
expect(initials).toBe('FG');
201+
});
202+
203+
it('handles Arabic characters', () => {
204+
const username = 'أحمد محمد';
205+
206+
const initials = getInitials(username);
207+
208+
expect(initials).toBe('أم');
209+
});
210+
211+
it('handles Chinese characters', () => {
212+
const username = '张三 李四';
213+
214+
const initials = getInitials(username);
215+
216+
expect(initials).toBe('张李');
217+
});
218+
219+
it('handles Japanese characters', () => {
220+
const username = 'たなか はなこ';
221+
222+
const initials = getInitials(username);
223+
224+
expect(initials).toBe('たは');
225+
});
226+
227+
it('handles Korean characters', () => {
228+
const username = '김민수 박영희';
229+
230+
const initials = getInitials(username);
231+
232+
expect(initials).toBe('김박');
233+
});
100234
});

frontend/src/utils/getInitials/getInitials.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ const getInitialFromName = (name: string): string => {
88
* @returns {string} The initials for the given username.
99
*/
1010
export default (username: string): string => {
11-
// Matches any names, including hyphenated names.
12-
const names = username.match(/(\w+(-\w+)?)/gm);
11+
// Matches Unicode names including accented characters, Cyrillic,
12+
// Arabic, Chinese, and other alphabets, plus hyphenated names (Jean-Pierre).
13+
// \p{L} = Unicode letters, \p{M} = combining marks, 'gu' = global + Unicode flags
14+
const names = username.match(/[\p{L}\p{M}]+(-[\p{L}\p{M}]+)*/gu);
1315
let lastInitial = '';
1416

1517
if (!names) {

0 commit comments

Comments
 (0)