|
|
@@ -1,28 +1,19 @@
|
|
|
import { describe, test, it, expect } from 'vitest'
|
|
|
import {createI18n, VueI18n} from 'vue-i18n'
|
|
|
import I18nUtils from "~/services/utils/i18nUtils";
|
|
|
-import { config } from "@vue/test-utils"
|
|
|
import {EnumChoices} from "~/types/interfaces";
|
|
|
|
|
|
-// config.global.mocks = {
|
|
|
-// $t: (tKey: string) => tKey // just return translation key
|
|
|
-// };
|
|
|
-
|
|
|
-// const i18n = createI18n({})
|
|
|
-// config.global.plugins = [i18n]
|
|
|
-//
|
|
|
-// config.global.mocks["t"] = (msg: string) => 'test'
|
|
|
-
|
|
|
describe('translateEnum', () => {
|
|
|
- test('with simple enum', () => {
|
|
|
+ let i18nUtils: I18nUtils
|
|
|
+
|
|
|
+ beforeEach(() => {
|
|
|
// @ts-ignore
|
|
|
const i18n = vi.fn() as VueI18n;
|
|
|
-
|
|
|
+ i18nUtils = new I18nUtils(i18n)
|
|
|
i18n.t = vi.fn((msg: string) => msg.replace('This is the letter', 'C\'est la lettre'))
|
|
|
+ })
|
|
|
|
|
|
- // @ts-ignore
|
|
|
- const i18nUtils = new I18nUtils(i18n)
|
|
|
-
|
|
|
+ test('with simple enum', () => {
|
|
|
const input: EnumChoices = [
|
|
|
{ value: 'Alpha', label: 'This is the letter A' },
|
|
|
{ value: 'Beta', label: 'This is the letter B' },
|
|
|
@@ -39,14 +30,6 @@ describe('translateEnum', () => {
|
|
|
})
|
|
|
|
|
|
test('with simple enum and sorting enabled', () => {
|
|
|
- // @ts-ignore
|
|
|
- const i18n = vi.fn() as VueI18n;
|
|
|
-
|
|
|
- i18n.t = vi.fn((msg: string) => msg.replace('This is the letter', 'C\'est la lettre'))
|
|
|
-
|
|
|
- // @ts-ignore
|
|
|
- const i18nUtils = new I18nUtils(i18n)
|
|
|
-
|
|
|
const input: EnumChoices = [
|
|
|
{ value: 'Epsilon', label: 'This is the letter E' },
|
|
|
{ value: 'Alpha', label: 'This is the letter A' },
|
|
|
@@ -64,24 +47,23 @@ describe('translateEnum', () => {
|
|
|
})
|
|
|
|
|
|
describe('formatPhoneNumber', () => {
|
|
|
- test('with valid international phone number', () => {
|
|
|
+ let i18nUtils: I18nUtils
|
|
|
+
|
|
|
+ beforeEach(() => {
|
|
|
// @ts-ignore
|
|
|
- const i18nUtils = new I18nUtils(i18n)
|
|
|
+ const i18n = vi.fn() as VueI18n;
|
|
|
+ i18nUtils = new I18nUtils(i18n)
|
|
|
+ })
|
|
|
+ test('with valid international phone number', () => {
|
|
|
expect(i18nUtils.formatPhoneNumber('+33611223344')).toEqual('06 11 22 33 44')
|
|
|
})
|
|
|
test('with valid non-formatted phone number', () => {
|
|
|
- // @ts-ignore
|
|
|
- const i18nUtils = new I18nUtils(i18n)
|
|
|
expect(i18nUtils.formatPhoneNumber('0611223344', 'FR')).toEqual('06 11 22 33 44')
|
|
|
})
|
|
|
test('with empty string', () => {
|
|
|
- // @ts-ignore
|
|
|
- const i18nUtils = new I18nUtils(i18n)
|
|
|
expect(() => i18nUtils.formatPhoneNumber('', 'FR')).toThrowError('NOT_A_NUMBER')
|
|
|
})
|
|
|
test('with invalid string', () => {
|
|
|
- // @ts-ignore
|
|
|
- const i18nUtils = new I18nUtils(i18n)
|
|
|
expect(() => i18nUtils.formatPhoneNumber('abcd', 'FR')).toThrowError('NOT_A_NUMBER')
|
|
|
})
|
|
|
})
|