Skip to content

Commit 0a1539f

Browse files
committedApr 11, 2025··
test: adds more tests to account for special characters
1 parent 601797f commit 0a1539f

File tree

1 file changed

+68
-25
lines changed

1 file changed

+68
-25
lines changed
 

‎packages/uui-avatar/lib/uui-avatar.test.ts

+68-25
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,77 @@ describe('UuiAvatar', () => {
4141
});
4242
});
4343

44-
it('renders an image when imgSrc is set', async () => {
45-
const avatar = await fixture(
46-
html`<uui-avatar img-src="${avatarSrc}" name="My Avatar"></uui-avatar>`,
47-
);
48-
expect(avatar).shadowDom.to.equal(
49-
`<img alt="MA" src="${avatarSrc}" srcset="" title="My Avatar" /><slot></<slot>`,
50-
);
51-
});
44+
describe('initials', () => {
45+
it('renders an image when imgSrc is set', async () => {
46+
const avatar = await fixture(
47+
html`<uui-avatar img-src="${avatarSrc}" name="My Avatar"></uui-avatar>`,
48+
);
49+
expect(avatar).shadowDom.to.equal(
50+
`<img alt="MA" src="${avatarSrc}" srcset="" title="My Avatar" /><slot></<slot>`,
51+
);
52+
});
5253

53-
it('renders an image with alt text when imgSrc and text is set', async () => {
54-
const avatar = await fixture(
55-
html`<uui-avatar img-src="${avatarSrc}" name="alt text"></uui-avatar>`,
56-
);
57-
expect(avatar).shadowDom.to.equal(
58-
`<img alt="AT" src="${avatarSrc}" srcset="" title="alt text" /><slot></<slot>`,
59-
);
60-
});
54+
it('renders an image with alt text when imgSrc and text is set', async () => {
55+
const avatar = await fixture(
56+
html`<uui-avatar img-src="${avatarSrc}" name="alt text"></uui-avatar>`,
57+
);
58+
expect(avatar).shadowDom.to.equal(
59+
`<img alt="AT" src="${avatarSrc}" srcset="" title="alt text" /><slot></<slot>`,
60+
);
61+
});
6162

62-
it('shows the first initial when text is used and there is no image', async () => {
63-
const avatar = await fixture(html`<uui-avatar name="First"></uui-avatar>`);
64-
expect(avatar).shadowDom.to.equal('F<slot></<slot>');
65-
});
63+
it('shows the first initial when text is used and there is no image', async () => {
64+
const avatar = await fixture(
65+
html`<uui-avatar name="First"></uui-avatar>`,
66+
);
67+
expect(avatar).shadowDom.to.equal('F<slot></<slot>');
68+
});
69+
70+
it('shows the first and last initial when text is used and there is no image', async () => {
71+
element.name = 'First Second Last';
72+
await element.updateComplete;
73+
expect(element).shadowDom.to.equal('FL<slot></<slot>');
74+
});
6675

67-
it('shows the first and last initial when text is used and there is no image', async () => {
68-
const avatar = await fixture(
69-
html`<uui-avatar name="First Second Last"></uui-avatar>`,
70-
);
71-
expect(avatar).shadowDom.to.equal('FL<slot></<slot>');
76+
it('supports unicode characters', async () => {
77+
element.name = '👩‍💻';
78+
await element.updateComplete;
79+
expect(element).shadowDom.to.equal('\ud83d<slot></<slot>');
80+
81+
element.name = '👩‍💻 👨‍💻';
82+
await element.updateComplete;
83+
expect(element).shadowDom.to.equal('\ud83d\ud83d<slot></<slot>');
84+
});
85+
86+
it('supports non-latin characters', async () => {
87+
element.name = 'Привет Ša';
88+
await element.updateComplete;
89+
expect(element).shadowDom.to.equal('ПŠ<slot></<slot>');
90+
91+
element.name = 'Привет';
92+
await element.updateComplete;
93+
expect(element).shadowDom.to.equal('П<slot></<slot>');
94+
95+
element.name = 'UlŠa Mya';
96+
await element.updateComplete;
97+
expect(element).shadowDom.to.equal('UM<slot></<slot>');
98+
99+
element.name = 'åse hylle';
100+
await element.updateComplete;
101+
expect(element).shadowDom.to.equal('ÅH<slot></<slot>');
102+
});
103+
104+
it('supports overriding initials', async () => {
105+
element.initials = 'AB';
106+
await element.updateComplete;
107+
expect(element).shadowDom.to.equal('AB<slot></<slot>');
108+
});
109+
110+
it('shows a maximum of 3 characters', async () => {
111+
element.initials = '1234';
112+
await element.updateComplete;
113+
expect(element).shadowDom.to.equal('123<slot></<slot>');
114+
});
72115
});
73116

74117
it('passes the a11y audit', async () => {

0 commit comments

Comments
 (0)
Please sign in to comment.