@@ -2,6 +2,7 @@ import {render} from '@/test-utils';
22import NavbarItemLanguageSelector from './navbar-item-language-selector' ;
33import { screen } from '@testing-library/vue' ;
44import userEvent from '@testing-library/user-event' ;
5+ import { mount } from '@vue/test-utils' ;
56
67describe ( 'NavbarItemLanguageSelector' , ( ) => {
78 let wrapper ;
@@ -18,15 +19,15 @@ describe('NavbarItemLanguageSelector', () => {
1819 } ) ;
1920
2021 it ( 'should print the locale with the country for selected language/locale' , async ( ) => {
21- const buttons = await screen . findAllByRole ( 'button' , { name : 'Deutschland (de) ' } ) ;
22+ const buttons = await screen . findAllByRole ( 'button' , { name : 'Deutsch ' } ) ;
2223 expect ( buttons [ 0 ] ) . toBeDefined ( )
2324 } ) ;
2425
2526 it ( 'should print locale with the country for available language in menu' , async ( ) => {
26- const languageButton = await screen . findAllByRole ( 'button' , { name : 'Deutschland (de) ' } ) ;
27+ const languageButton = await screen . findAllByRole ( 'button' , { name : 'Deutsch ' } ) ;
2728 await userEvent . click ( languageButton [ 0 ] ) ;
2829
29- expect ( await screen . findByRole ( 'button' , { name : 'France (fr) ' } ) ) . toBeDefined ( )
30+ expect ( await screen . findByRole ( 'button' , { name : 'français ' } ) ) . toBeDefined ( )
3031 } ) ;
3132
3233 it ( 'should print the locale as label when it cannot be translated' , async ( ) => {
@@ -37,13 +38,31 @@ describe('NavbarItemLanguageSelector', () => {
3738 }
3839 } )
3940
40- const htmlElement = await screen . findAllByRole ( 'button' , { name : 'zz (zz) ' } ) ;
41+ const htmlElement = await screen . findAllByRole ( 'button' , { name : 'zz' } ) ;
4142 expect ( htmlElement [ 0 ] ) . toBeDefined ( )
4243 } ) ;
4344
4445 it ( 'should emit the selected locale' , async ( ) => {
45- await userEvent . click ( await screen . findByRole ( 'button' , { name : 'France (fr) ' } ) ) ;
46+ await userEvent . click ( await screen . findByRole ( 'button' , { name : 'français ' } ) ) ;
4647
4748 expect ( wrapper . emitted ( ) . localeChanged [ 0 ] ) . toContain ( 'fr' )
4849 } ) ;
50+
51+ it . each `
52+ locale | expected
53+ ${ 'de' } | ${ 'Deutsch' }
54+ ${ 'is' } | ${ 'íslenska' }
55+ ${ 'de-DE' } | ${ 'Deutsch (Deutschland)' }
56+ ${ 'zh-CN' } | ${ '简体中文' }
57+ ${ 'zh-TW' } | ${ '繁體中文' }
58+ ` ( 'should show \'$expected\' for given \'$locale\'' , ( { locale, expected} ) => {
59+ let wrapper = mount ( NavbarItemLanguageSelector , {
60+ propsData : {
61+ availableLocales : [ ] ,
62+ currentLocale : 'en'
63+ }
64+ } ) ;
65+
66+ expect ( wrapper . vm . mapLocale ( locale ) . label ) . toEqual ( expected ) ;
67+ } ) ;
4968} ) ;
0 commit comments