-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
94 additions
and
0 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
packages/blocks/src/api/raw-handling/test/html-formatting-remover.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import filter from '../html-formatting-remover'; | ||
import { deepFilterHTML } from '../utils'; | ||
|
||
describe( 'HTMLFormattingRemover', () => { | ||
it( 'should remove formatting space', () => { | ||
const input = ` | ||
<div> | ||
a | ||
b | ||
</div> | ||
`; | ||
const output = '<div>a b</div>'; | ||
expect( deepFilterHTML( input, [ filter ] ) ).toEqual( output ); | ||
} ); | ||
|
||
it( 'should remove nested formatting space', () => { | ||
const input = ` | ||
<div> | ||
<strong> | ||
a | ||
b | ||
</strong> | ||
</div> | ||
`; | ||
const output = '<div><strong>a b</strong></div>'; | ||
expect( deepFilterHTML( input, [ filter ] ) ).toEqual( output ); | ||
} ); | ||
|
||
it( 'should not remove leading or trailing space if previous or next element has no space', () => { | ||
const input = ` | ||
<div> | ||
a | ||
<strong>b</strong> | ||
c | ||
</div> | ||
`; | ||
const output = '<div>a <strong>b</strong> c</div>'; | ||
expect( deepFilterHTML( input, [ filter ] ) ).toEqual( output ); | ||
} ); | ||
|
||
it( 'should remove formatting space (empty)', () => { | ||
const input = ` | ||
<div> | ||
</div> | ||
`; | ||
const output = '<div></div>'; | ||
expect( deepFilterHTML( input, [ filter ] ) ).toEqual( output ); | ||
} ); | ||
|
||
it( 'should remove block level formatting space', () => { | ||
const input = ` | ||
<div> | ||
<div> | ||
a | ||
</div> | ||
<div> | ||
b | ||
</div> | ||
</div> | ||
`; | ||
const output = '<div><div>a</div><div>b</div></div>'; | ||
expect( deepFilterHTML( input, [ filter ] ) ).toEqual( output ); | ||
} ); | ||
|
||
it( 'should remove formatting space around br', () => { | ||
const input = ` | ||
<div> | ||
a | ||
<br> | ||
b | ||
</div> | ||
`; | ||
const output = '<div>a<br>b</div>'; | ||
expect( deepFilterHTML( input, [ filter ] ) ).toEqual( output ); | ||
} ); | ||
|
||
it( 'should remove formatting space around phasing content elements', () => { | ||
const input = ` | ||
<div> | ||
<strong> | ||
a | ||
</strong> | ||
<strong> | ||
b | ||
</strong> | ||
</div> | ||
`; | ||
const output = '<div><strong>a</strong><strong> b</strong></div>'; | ||
expect( deepFilterHTML( input, [ filter ] ) ).toEqual( output ); | ||
} ); | ||
} ); |