UNPKG

@bigfishtv/cockpit

Version:

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