11import { expect } from 'chai' ;
22
3+ import { CARRIAGE_RETURN_PLACEHOLDER } from '../../src/client/constants' ;
34import { formatDOM } from '../../src/client/utilities' ;
45import { revertEscapedCharacters } from '../../src/client/utilities' ;
56import { escapeSpecialCharacters } from '../../src/client/utilities' ;
@@ -15,59 +16,67 @@ describe('client utilities', () => {
1516
1617 describe ( 'escapeSpecialCharacters' , ( ) => {
1718 it ( 'escapes carriage return characters' , ( ) => {
18- const input = 'Hello\rWorld' ;
19- const expected = ' Hello\\rWorld' ;
20- expect ( escapeSpecialCharacters ( input ) ) . to . equal ( expected ) ;
19+ expect ( escapeSpecialCharacters ( 'Hello\rWorld' ) ) . to . equal (
20+ ` Hello${ CARRIAGE_RETURN_PLACEHOLDER } World` ,
21+ ) ;
2122 } ) ;
2223
2324 it ( 'does not modify strings without special characters' , ( ) => {
24- const input = 'Hello World' ;
25- expect ( escapeSpecialCharacters ( input ) ) . to . equal ( input ) ;
25+ const text = 'Hello World' ;
26+ expect ( escapeSpecialCharacters ( text ) ) . to . equal ( text ) ;
2627 } ) ;
2728
2829 it ( 'handles empty strings' , ( ) => {
29- expect ( escapeSpecialCharacters ( '' ) ) . to . equal ( '' ) ;
30+ const text = '' ;
31+ expect ( escapeSpecialCharacters ( text ) ) . to . equal ( text ) ;
3032 } ) ;
3133
3234 it ( 'handles multiple carriage returns' , ( ) => {
33- const input = 'Hello\rDear\rWorld' ;
34- const expected = ' Hello\\rDear\\rWorld' ;
35- expect ( escapeSpecialCharacters ( input ) ) . to . equal ( expected ) ;
35+ expect ( escapeSpecialCharacters ( 'Hello\rDear\rWorld' ) ) . to . equal (
36+ ` Hello${ CARRIAGE_RETURN_PLACEHOLDER } Dear ${ CARRIAGE_RETURN_PLACEHOLDER } World` ,
37+ ) ;
3638 } ) ;
3739
3840 it ( 'only escapes carriage returns' , ( ) => {
39- const input = 'Hello\rWorld\n' ; // \n should not be affected
40- const expected = 'Hello\\rWorld\n' ;
41- expect ( escapeSpecialCharacters ( input ) ) . to . equal ( expected ) ;
41+ // `\n` and `\right` should not be affected
42+ expect ( escapeSpecialCharacters ( 'Hello\rWorld\n\right' ) ) . to . equal (
43+ `Hello${ CARRIAGE_RETURN_PLACEHOLDER } World\n${ CARRIAGE_RETURN_PLACEHOLDER } ight` ,
44+ ) ;
4245 } ) ;
4346 } ) ;
4447
4548 describe ( 'revertEscapedCharacters' , ( ) => {
4649 it ( 'reverts escaped carriage return characters' , ( ) => {
47- const input = 'Hello\\rWorld' ;
48- const expected = ' Hello\rWorld' ;
49- expect ( revertEscapedCharacters ( input ) ) . to . equal ( expected ) ;
50+ expect (
51+ revertEscapedCharacters ( ` Hello${ CARRIAGE_RETURN_PLACEHOLDER } World` ) ,
52+ ) . to . equal ( 'Hello\rWorld' ) ;
5053 } ) ;
5154
5255 it ( 'does not modify strings without escaped characters' , ( ) => {
53- const input = 'Hello World' ;
54- expect ( revertEscapedCharacters ( input ) ) . to . equal ( input ) ;
56+ const text = 'Hello World' ;
57+ expect ( revertEscapedCharacters ( text ) ) . to . equal ( text ) ;
5558 } ) ;
5659
5760 it ( 'handles empty strings' , ( ) => {
58- expect ( revertEscapedCharacters ( '' ) ) . to . equal ( '' ) ;
61+ const text = '' ;
62+ expect ( revertEscapedCharacters ( text ) ) . to . equal ( text ) ;
5963 } ) ;
6064
6165 it ( 'handles multiple escaped carriage returns' , ( ) => {
62- const input = 'Hello\\rDear\\rWorld' ;
63- const expected = 'Hello\rDear\rWorld' ;
64- expect ( revertEscapedCharacters ( input ) ) . to . equal ( expected ) ;
66+ expect (
67+ revertEscapedCharacters (
68+ `Hello${ CARRIAGE_RETURN_PLACEHOLDER } Dear${ CARRIAGE_RETURN_PLACEHOLDER } World` ,
69+ ) ,
70+ ) . to . equal ( 'Hello\rDear\rWorld' ) ;
6571 } ) ;
6672
6773 it ( 'only reverts escaped carriage returns' , ( ) => {
68- const input = 'Hello\\rWorld\\n' ; // \n should not be affected
69- const expected = 'Hello\rWorld\\n' ;
70- expect ( revertEscapedCharacters ( input ) ) . to . equal ( expected ) ;
74+ // `\n` and `\right` should not be affected
75+ expect (
76+ revertEscapedCharacters (
77+ `Hello${ CARRIAGE_RETURN_PLACEHOLDER } World\\n\\right` ,
78+ ) ,
79+ ) . to . equal ( 'Hello\rWorld\\n\\right' ) ;
7180 } ) ;
7281 } ) ;
7382} ) ;
0 commit comments