hack the i18n for tests

This commit is contained in:
Moriz Wahl 2022-03-08 04:37:34 +01:00
parent 09de529443
commit aa8432384e
5 changed files with 18 additions and 7 deletions

View File

@ -1,6 +1,6 @@
<template>
<div class="decayinformation-short">
<span v-if="decay.decay">{{ decay.decay | amount}}</span>
<span v-if="decay.decay">{{ decay.decay | amount }}</span>
</div>
</template>
<script>

View File

@ -1,6 +1,11 @@
import i18n from '@/i18n.js'
let i18n
export const amount = (value) => {
export const loadFilters = (_i18n) => {
i18n = _i18n
return { amount }
}
const amount = (value) => {
if (!value) return ''
return i18n.n(value.toString(), 'decimal').replace('-', ' ')
}

View File

@ -4,7 +4,7 @@ import App from './App.vue'
import i18n from './i18n.js'
import { loadAllRules } from './validation-rules'
import { toasters } from './mixins/toaster'
import { amount } from './filters/amount'
import { loadFilters } from './filters/amount'
import 'regenerator-runtime'
@ -21,7 +21,8 @@ Vue.use(DashboardPlugin)
Vue.config.productionTip = false
Vue.mixin(toasters)
Vue.filter('amount', amount)
const filters = loadFilters(i18n)
Vue.filter('amount', filters.amount)
loadAllRules(i18n)

View File

@ -270,7 +270,7 @@ describe('GddTransactionList', () => {
it('shows the decay calculation', () => {
expect(transaction.findAll('div.gdd-transaction-list-item-decay').at(0).text()).toContain(
' 0.20383140554826432',
' 0.2038314055482643084',
)
})
})

View File

@ -17,7 +17,9 @@ import { focus } from 'vue-focus'
import { loadAllRules } from '../src/validation-rules'
import { toasters } from '../src/mixins/toaster'
import { loadFilters } from '@/filters/amount'
import { toasters } from '@/mixins/toaster'
export const toastErrorSpy = jest.spyOn(toasters.methods, 'toastError')
export const toastSuccessSpy = jest.spyOn(toasters.methods, 'toastSuccess')
@ -53,6 +55,9 @@ global.localVue.directive('focus', focus)
global.localVue.mixin(toasters)
const filters = loadFilters(i18nMock)
global.localVue.filter('amount', filters.amount)
// Filter the warnings for portal vue
// https://github.com/BeniRupp/bug_portal-vue-target-already-exists
const consoleWarn = global.console.warn