Skip to content

Commit

Permalink
Update tests/unit/components/NcAvatar/NcAvatar.spec.ts
Browse files Browse the repository at this point in the history
Co-authored-by: Grigorii K. Shartsev <me@shgk.me>
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux and ShGKme committed Nov 2, 2023
1 parent 8392347 commit 7f2ee0a
Showing 1 changed file with 33 additions and 76 deletions.
109 changes: 33 additions & 76 deletions tests/unit/components/NcAvatar/NcAvatar.spec.ts
Expand Up @@ -32,90 +32,47 @@ interface ITestCase {

describe('NcAvatar.vue', () => {
describe('Initials', () => {
const testCases: ITestCase[] = [
{
name: 'empty user',
expected: '?',
props: {},
},
{
name: 'user property',
expected: 'JD',
props: {
it.each`
displayName | initials | case
${''} | ${'?'} | ${'empty user'}
${'Jane Doe'} | ${'JD'} | ${'display name property'}
${'Jane (Doe)'} | ${'JD'} | ${'special characters in name'}
${'jane doe'} | ${'JD'} | ${'lower case name'}
${'Jane Some Name Doe'} | ${'JD'} | ${'middle names'}
${'Ümit Öçal'} | ${'ÜÖ'} | ${'non ascii characters'}
${'ジェーン ドー'} | ${'ジド'} | ${'non latin characters'}
`('should display initials for $case ("$displayName" -> "$initials")', async ({ displayName, initials }) => {
const wrapper = shallowMount(NcAvatar, {
propsData: {
displayName,
},
})
await nextTick()
expect(wrapper.text()).toBe(initials)
})

it('should display initials for user id', async () => {
const wrapper = shallowMount(NcAvatar, {
propsData: {
user: 'Jane Doe',
isNoUser: true,
},
},
{
name: 'display name property',
expected: 'JD',
props: {
displayName: 'Jane Doe',
},
},
{
name: 'display name property over user property',
expected: 'NU',
props: {
})
await nextTick()
expect(wrapper.text()).toBe('JD')
})

it('should display initials for display name property over user id', async () => {
const wrapper = shallowMount(NcAvatar, {
propsData: {
displayName: 'No User',
user: 'I am a group',
isNoUser: true,
},
},
{
name: 'special characters in name',
expected: 'JD',
props: {
displayName: 'Jane (Doe)',
},
},
{
name: 'lower case name',
expected: 'JD',
props: {
displayName: 'jane doe',
},
},
{
name: 'middle names',
expected: 'JD',
props: {
displayName: 'Jane Some Name Doe',
},
},
{
name: 'non ascii characters',
expected: 'ÜÖ',
props: {
displayName: 'Ümit Öçal',
},
},
{
name: 'non latin characters',
expected: 'ジド',
props: {
displayName: 'ジェーン ドー',
},
},
]

for (const { name, props, expected } of testCases) {
it(`can handle ${name}`, async () => {
const wrapper = shallowMount(NcAvatar, {
propsData: {
...props,
},
})
expect(wrapper.exists()).toBe(true)

await nextTick()
const initials = wrapper.find('.avatardiv__initials')
expect(initials.exists()).toBe(true)
expect(initials.text()).toBe(expected)
})
}
})

await nextTick()
expect(wrapper.text()).toBe('NU')
})
it('aria label is set to include status if status is shown visually', async () => {
const status = {
icon: '',
Expand Down

0 comments on commit 7f2ee0a

Please sign in to comment.