1
0
Fork 0
freesewing/plugins/plugin-i18n/tests/plugin.test.mjs

56 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

import { expect } from 'chai'
2022-09-07 10:57:47 +02:00
import { Design } from '@freesewing/core'
2022-09-12 17:52:55 +02:00
import { plugin } from '../src/index.mjs'
2022-08-28 12:44:22 +02:00
const content = {
en: {
testString: 'This is a test string for the i18n plugin',
2022-09-12 17:52:55 +02:00
},
2022-08-28 12:44:22 +02:00
}
const t = (key, language) => (content[language][key] ? content[language][key] : key)
describe('I18n Plugin Tests', () => {
it('Should translate text on insert (translation object)', () => {
2022-09-12 17:52:55 +02:00
const part = {
name: 'test',
draft: ({ points, Point, macro, part }) => {
points.anchor = new pattern.Point(-12, -34).attr('data-text', 'testString')
points.from = new Point(10, 20)
points.to = new Point(10, 230)
macro('grainline', {
from: points.from,
to: points.to,
})
return part
},
plugins: [[plugin, content]],
}
const Pattern = new Design({ parts: [part] })
const pattern = new Pattern()
const svg = pattern.draft().render()
expect(svg).to.contain(content.en.testString)
})
it('Should translate text on insert (translation method)', () => {
const part = {
name: 'test',
draft: ({ points, Point, macro, part }) => {
points.anchor = new pattern.Point(-12, -34).attr('data-text', 'testString')
points.from = new Point(10, 20)
points.to = new Point(10, 230)
macro('grainline', {
from: points.from,
to: points.to,
})
return part
},
plugins: [[plugin, t]],
}
const Pattern = new Design({ parts: [part] })
const pattern = new Pattern()
const svg = pattern.draft().render()
expect(svg).to.contain(content.en.testString)
})
})