gitlab-org--gitlab-foss/spec/javascripts/vue_shared/translate_spec.js

91 lines
1.6 KiB
JavaScript
Raw Normal View History

import Vue from 'vue';
import Translate from '~/vue_shared/translate';
Vue.use(Translate);
describe('Vue translate filter', () => {
let el;
beforeEach(() => {
el = document.createElement('div');
document.body.appendChild(el);
});
it('translate single text', (done) => {
const comp = new Vue({
el,
template: `
<span>
2017-04-26 12:20:13 -04:00
{{ __('testing') }}
</span>
`,
}).$mount();
Vue.nextTick(() => {
expect(
comp.$el.textContent.trim(),
).toBe('testing');
done();
});
});
it('translate plural text with single count', (done) => {
const comp = new Vue({
el,
template: `
<span>
2017-04-26 12:20:13 -04:00
{{ n__('%d day', '%d days', 1) }}
</span>
`,
}).$mount();
Vue.nextTick(() => {
expect(
comp.$el.textContent.trim(),
).toBe('1 day');
done();
});
});
it('translate plural text with multiple count', (done) => {
const comp = new Vue({
el,
template: `
<span>
2017-04-26 12:20:13 -04:00
{{ n__('%d day', '%d days', 2) }}
</span>
`,
}).$mount();
Vue.nextTick(() => {
expect(
comp.$el.textContent.trim(),
).toBe('2 days');
done();
});
});
it('translate plural without replacing any text', (done) => {
const comp = new Vue({
el,
template: `
<span>
2017-04-26 12:20:13 -04:00
{{ n__('day', 'days', 2) }}
</span>
`,
}).$mount();
Vue.nextTick(() => {
expect(
comp.$el.textContent.trim(),
).toBe('days');
done();
});
});
});