@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
119 lines (105 loc) • 4.18 kB
JavaScript
import {describe, expect, it} from 'vitest'
import {trimPunctuation, getTrimmedPunctuation} from '../punctuation'
describe('Punctuation Helpers', () => {
describe('trimPunctuation', () => {
const stemItems = [1, 2, 3]
it('trims start/end punctuation correctly', () => {
const stemItem = {
position: 2,
value: ', test "',
}
expect(trimPunctuation(stemItem, stemItems)).toBe('test')
})
it('does not trim punctuation if no whitespace', () => {
const stemItem = {
position: 2,
value: '"test stuff"',
}
expect(trimPunctuation(stemItem, stemItems)).toBe('"test stuff"')
})
it('trims multiple punctuation symbols', () => {
const stemItem = {
position: 2,
value: '...!?!?") New Sentence.',
}
expect(trimPunctuation(stemItem, stemItems)).toBe('New Sentence.')
})
it('trims non-standard (i18n) punctuation symbols', () => {
const stemItem = {
position: 2,
value: ',,、.::;;!!??%‰]]】))}>»›」﹂』…⋯᠁ฯ》〉。 привет [[【(({<«‹「﹁『《〈¿¡ ',
}
expect(trimPunctuation(stemItem, stemItems)).toBe('привет')
})
it('does not trim ending punctuation from the first item', () => {
const stemItem = {
position: 1,
value: '! First Sentence (',
}
expect(trimPunctuation(stemItem, stemItems)).toBe('! First Sentence')
})
it('does not trim starting punctuation from the last item', () => {
const stemItem = {
position: 3,
value: '! Last Sentence (',
}
expect(trimPunctuation(stemItem, stemItems)).toBe('Last Sentence (')
})
})
describe('getTrimmedPunctuation', () => {
it('gets start/end punctuation correctly', () => {
const stemItems = [
{position: 1, type: 'text', value: 'This is the "'},
{position: 2, type: 'blank', blankId: '12345'},
{position: 3, type: 'text', value: '" value.'},
]
expect(getTrimmedPunctuation(stemItems[1], stemItems)).toEqual({start: ' "', end: '" '})
})
it('gets start/end punctuation correctly with null text values', () => {
const stemItems = [
{position: 1, type: 'text', value: null},
{position: 2, type: 'blank', blankId: '12345'},
{position: 3, type: 'text', value: null},
]
expect(getTrimmedPunctuation(stemItems[1], stemItems)).toEqual({start: '', end: ''})
})
it('does not get start/end punctuation for first/last stemItem', () => {
const stemItems = [{position: 1, type: 'blank', blankId: '12345'}]
expect(getTrimmedPunctuation(stemItems[0], stemItems)).toEqual({start: '', end: ''})
})
it('does not get punctuation if no whitespace', () => {
const stemItems = [
{position: 1, type: 'text', value: '"quoted"'},
{position: 2, type: 'blank', blankId: '12345'},
{position: 3, type: 'text', value: '...stuff...'},
]
expect(getTrimmedPunctuation(stemItems[1], stemItems)).toEqual({start: '', end: ''})
})
it('gets multiple punctuation symbols', () => {
const stemItems = [
{position: 1, type: 'text', value: '{foo (`'},
{position: 2, type: 'blank', blankId: '12345'},
{position: 3, type: 'text', value: '`) bar}'},
]
expect(getTrimmedPunctuation(stemItems[1], stemItems)).toEqual({
start: ' (`',
end: '`) ',
})
})
it('gets non-standard (i18n) punctuation symbols', () => {
const stemItems = [
{position: 1, type: 'text', value: 'привет [[【(({<«‹「﹁『《〈¿¡ '},
{position: 2, type: 'blank', blankId: '12345'},
{
position: 3,
type: 'text',
value: ',,、.::;;!!??%‰]]】))}>»›」﹂』…⋯᠁ฯ》〉。 привет',
},
]
expect(getTrimmedPunctuation(stemItems[1], stemItems)).toEqual({
start: ' [[【(({<«‹「﹁『《〈¿¡',
end: ',,、.::;;!!??%‰]]】))}>»›」﹂』…⋯᠁ฯ》〉。 ',
})
})
})
})