From 7f2ee0a1cee965bd98ecddf2711d7f3f7d0d2abb Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 2 Nov 2023 03:15:07 +0100 Subject: [PATCH] Update tests/unit/components/NcAvatar/NcAvatar.spec.ts Co-authored-by: Grigorii K. Shartsev Signed-off-by: Ferdinand Thiessen --- .../unit/components/NcAvatar/NcAvatar.spec.ts | 109 ++++++------------ 1 file changed, 33 insertions(+), 76 deletions(-) diff --git a/tests/unit/components/NcAvatar/NcAvatar.spec.ts b/tests/unit/components/NcAvatar/NcAvatar.spec.ts index bc56e00581..1ef0290359 100644 --- a/tests/unit/components/NcAvatar/NcAvatar.spec.ts +++ b/tests/unit/components/NcAvatar/NcAvatar.spec.ts @@ -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: '',