|
| 1 | +import { normalizeHtml } from '../../testHelpers/html/htmlNormalizer' |
| 2 | +import { |
| 3 | + CONTENT_FIELD_WITH_ALL_TAGS, |
| 4 | + SERVER_FORMATTED_CONTENT_FIELD_WITH_ALL_TAGS |
| 5 | +} from '../../testHelpers/collections/collectionHelper' |
| 6 | + |
| 7 | +describe('normalizeHtml', () => { |
| 8 | + describe('differences the server may introduce', () => { |
| 9 | + test('should ignore the order of attributes', () => { |
| 10 | + expect( |
| 11 | + normalizeHtml('<a target="_blank" rel="nofollow" class="x" href="https://a.b">t</a>') |
| 12 | + ).toEqual( |
| 13 | + normalizeHtml('<a class="x" href="https://a.b" rel="nofollow" target="_blank">t</a>') |
| 14 | + ) |
| 15 | + }) |
| 16 | + |
| 17 | + test('should ignore indentation introduced between block elements', () => { |
| 18 | + expect(normalizeHtml('<ul><li><p>Item</p></li></ul>')).toEqual( |
| 19 | + normalizeHtml('<ul>\n <li>\n <p>Item</p>\n </li>\n</ul>') |
| 20 | + ) |
| 21 | + }) |
| 22 | + |
| 23 | + test('should ignore indentation around the content of a block element', () => { |
| 24 | + expect(normalizeHtml('<p>Item</p>')).toEqual(normalizeHtml('<p>\n Item\n</p>')) |
| 25 | + }) |
| 26 | + |
| 27 | + test('should ignore the case of tag and attribute names', () => { |
| 28 | + expect(normalizeHtml('<P CLASS="x">t</P>')).toEqual(normalizeHtml('<p class="x">t</p>')) |
| 29 | + }) |
| 30 | + |
| 31 | + test('should ignore the order of attributes whose values contain angle brackets', () => { |
| 32 | + expect(normalizeHtml('<a title="A > B" href="/example">link</a>')).toEqual( |
| 33 | + normalizeHtml('<a href="/example" title="A > B">link</a>') |
| 34 | + ) |
| 35 | + }) |
| 36 | + |
| 37 | + test('should ignore the order of attributes quoted with single quotes', () => { |
| 38 | + expect(normalizeHtml("<a title='A > B' href='/example'>link</a>")).toEqual( |
| 39 | + normalizeHtml('<a href="/example" title="A > B">link</a>') |
| 40 | + ) |
| 41 | + }) |
| 42 | + |
| 43 | + test('should ignore equivalent spellings of a void element', () => { |
| 44 | + expect(normalizeHtml('<p>a<br>b</p>')).toEqual(normalizeHtml('<p>a<br/>b</p>')) |
| 45 | + }) |
| 46 | + |
| 47 | + test('should ignore equivalent spellings of an escaped character', () => { |
| 48 | + expect(normalizeHtml('<p>a & b</p>')).toEqual(normalizeHtml('<p>a & b</p>')) |
| 49 | + }) |
| 50 | + |
| 51 | + test('should treat the sent and server-returned forms of the featured item fixture as equal', () => { |
| 52 | + expect(normalizeHtml(CONTENT_FIELD_WITH_ALL_TAGS)).toEqual( |
| 53 | + normalizeHtml(SERVER_FORMATTED_CONTENT_FIELD_WITH_ALL_TAGS) |
| 54 | + ) |
| 55 | + }) |
| 56 | + }) |
| 57 | + |
| 58 | + describe('differences that must still be detected', () => { |
| 59 | + test('should not ignore differing text content', () => { |
| 60 | + expect(normalizeHtml('<p>Item</p>')).not.toEqual(normalizeHtml('<p>Other</p>')) |
| 61 | + }) |
| 62 | + |
| 63 | + test('should not ignore differing attribute values', () => { |
| 64 | + expect(normalizeHtml('<a href="https://a.b">t</a>')).not.toEqual( |
| 65 | + normalizeHtml('<a href="https://evil.example">t</a>') |
| 66 | + ) |
| 67 | + }) |
| 68 | + |
| 69 | + test('should not ignore a dropped attribute', () => { |
| 70 | + expect(normalizeHtml('<a rel="nofollow" href="https://a.b">t</a>')).not.toEqual( |
| 71 | + normalizeHtml('<a href="https://a.b">t</a>') |
| 72 | + ) |
| 73 | + }) |
| 74 | + |
| 75 | + test('should not ignore a differing attribute value that contains angle brackets', () => { |
| 76 | + expect(normalizeHtml('<a title="A > B" href="/example">link</a>')).not.toEqual( |
| 77 | + normalizeHtml('<a title="A > C" href="/example">link</a>') |
| 78 | + ) |
| 79 | + }) |
| 80 | + |
| 81 | + test('should not ignore differing structure', () => { |
| 82 | + expect(normalizeHtml('<ul><li>a</li><li>b</li></ul>')).not.toEqual( |
| 83 | + normalizeHtml('<ul><li>a</li></ul>') |
| 84 | + ) |
| 85 | + }) |
| 86 | + |
| 87 | + test('should not ignore a changed tag', () => { |
| 88 | + expect(normalizeHtml('<strong>t</strong>')).not.toEqual(normalizeHtml('<em>t</em>')) |
| 89 | + }) |
| 90 | + |
| 91 | + test('should preserve whitespace inside a preformatted block', () => { |
| 92 | + expect(normalizeHtml('<pre><code> indented\n lines</code></pre>')).not.toEqual( |
| 93 | + normalizeHtml('<pre><code>indented lines</code></pre>') |
| 94 | + ) |
| 95 | + }) |
| 96 | + |
| 97 | + test('should preserve the whitespace that separates inline elements in the featured item fixture', () => { |
| 98 | + expect(normalizeHtml(CONTENT_FIELD_WITH_ALL_TAGS)).not.toEqual( |
| 99 | + normalizeHtml(CONTENT_FIELD_WITH_ALL_TAGS.replace('</strong> <em', '</strong><em')) |
| 100 | + ) |
| 101 | + }) |
| 102 | + |
| 103 | + test('should preserve whitespace that separates inline elements', () => { |
| 104 | + expect(normalizeHtml('<p><em>a</em> <em>b</em></p>')).not.toEqual( |
| 105 | + normalizeHtml('<p><em>a</em><em>b</em></p>') |
| 106 | + ) |
| 107 | + }) |
| 108 | + }) |
| 109 | +}) |
0 commit comments