@bigfishtv/cockpit
Version:
58 lines (48 loc) • 2.13 kB
JavaScript
import { simplifyNonBreakingSpaces } from './stringUtils'
describe('simplifyNonBreakingSpaces', () => {
it('single space', () => {
const input = '<p>Hello there</p>'
const expected = '<p>Hello there</p>'
expect(simplifyNonBreakingSpaces(input)).toEqual(expected)
})
it('single space (multiple)', () => {
const input = '<p>Hello there buddy</p>'
const expected = '<p>Hello there buddy</p>'
expect(simplifyNonBreakingSpaces(input)).toEqual(expected)
})
it('double should convert to single space and ', () => {
const input = '<p>Hello there</p>'
const expected = '<p>Hello there</p>'
expect(simplifyNonBreakingSpaces(input)).toEqual(expected)
})
it('triple should convert to single space and 2 ', () => {
const input = '<p>Hello there</p>'
const expected = '<p>Hello there</p>'
expect(simplifyNonBreakingSpaces(input)).toEqual(expected)
})
it(' at the end of paragraph should remain (required for consistent editing)', () => {
const input = '<p>Hello there </p>'
const expected = input
expect(simplifyNonBreakingSpaces(input)).toEqual(expected)
})
it('replace before opening html tag', () => {
const input = '<p>Hello there <strong>hi there</strong></p>'
const expected = '<p>Hello there <strong>hi there</strong></p>'
expect(simplifyNonBreakingSpaces(input)).toEqual(expected)
})
it('replace after opening html tag', () => {
const input = '<p>Hello there<strong> hi there</strong></p>'
const expected = '<p>Hello there<strong> hi there</strong></p>'
expect(simplifyNonBreakingSpaces(input)).toEqual(expected)
})
it(' before closing html tags should remain (required for consistent editing)', () => {
const input = '<p>Hello <strong>there </strong></p>'
const expected = input
expect(simplifyNonBreakingSpaces(input)).toEqual(expected)
})
it('potential edge case', () => {
const input = '<p>© 2017</p>'
const expected = '<p>© 2017</p>'
expect(simplifyNonBreakingSpaces(input)).toEqual(expected)
})
})