-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add i18n texts for BigCalendar and panel options
- Loading branch information
Showing
12 changed files
with
310 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
// Jest setup provided by Grafana scaffolding | ||
import './.config/jest-setup'; | ||
|
||
/** | ||
* Setup i18n | ||
*/ | ||
import './src/i18n'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from './default'; | ||
export * from './messages'; | ||
export * from './options'; | ||
export * from './tests'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,48 @@ | ||
import dayjs from 'dayjs'; | ||
import { config } from '@grafana/runtime'; | ||
import { renderHook } from '@testing-library/react'; | ||
import { LanguageMessages } from '../constants'; | ||
import { t } from 'i18next'; | ||
import { getUserLanguage } from '../utils'; | ||
import { useLocalizer } from './useLocalizer'; | ||
|
||
/** | ||
* Mock @grafana/runtime | ||
* Mock utils | ||
*/ | ||
jest.mock('@grafana/runtime', () => ({ | ||
config: { | ||
bootData: { | ||
user: { | ||
language: 'en-US', | ||
}, | ||
}, | ||
}, | ||
jest.mock('../utils', () => ({ | ||
...jest.requireActual('../utils'), | ||
getUserLanguage: jest.fn(() => 'en'), | ||
})); | ||
|
||
describe('Use Localizer', () => { | ||
it('Should set dayjs locale', () => { | ||
config.bootData = { | ||
user: { | ||
language: 'fr-EN', | ||
}, | ||
} as any; | ||
jest.mocked(getUserLanguage).mockReturnValue('fr'); | ||
renderHook(() => useLocalizer()); | ||
|
||
expect(dayjs.locale()).toEqual('fr'); | ||
}); | ||
|
||
it('Should set dayjs locale', () => { | ||
config.bootData = { | ||
user: {}, | ||
} as any; | ||
jest.mocked(getUserLanguage).mockReturnValue('en'); | ||
renderHook(() => useLocalizer()); | ||
|
||
expect(dayjs.locale()).toEqual('en'); | ||
}); | ||
|
||
it('Should set default dayjs locale', () => { | ||
config.bootData = { | ||
user: { | ||
language: '123', | ||
}, | ||
} as any; | ||
jest.mocked(getUserLanguage).mockReturnValue('123' as any); | ||
renderHook(() => useLocalizer()); | ||
|
||
expect(dayjs.locale()).toEqual('en'); | ||
}); | ||
|
||
['es-SP', 'fr-EN', 'de-GE', 'zh-CH'].forEach((locale) => { | ||
it(`Should set messages for ${locale}`, () => { | ||
config.bootData = { | ||
user: { | ||
language: locale, | ||
}, | ||
} as any; | ||
['es', 'fr', 'de', 'zh'].forEach((lang) => { | ||
it(`Should set messages for ${lang}`, () => { | ||
jest.mocked(getUserLanguage).mockReturnValue(lang as any); | ||
const { result } = renderHook(() => useLocalizer()); | ||
|
||
const lang = locale.split('-')[0] | ||
const expectedMessages = LanguageMessages[lang]; | ||
expect(result.current.messages).toEqual(expectedMessages) | ||
if (result.current.messages.showMore && expectedMessages.showMore) { | ||
expect(result.current.messages.showMore(10)).toEqual(expectedMessages.showMore(10)) | ||
expect(result.current.messages.noEventsInRange).toEqual(t('localizerMessages.noEventsInRange')); | ||
if (result.current.messages.showMore) { | ||
expect(result.current.messages.showMore(10)).toEqual(t('localizerMessages.showMore', { total: 10 })); | ||
} | ||
}); | ||
}) | ||
|
||
}); | ||
}); |
Oops, something went wrong.