|
| 1 | +import * as assert from 'assert'; |
| 2 | + |
| 3 | +import { getTitle } from '../../lib/htmlHelper'; |
| 4 | + |
| 5 | +const plainTitle = 'test'; |
| 6 | +const toHtmlContent = (title: string) => `<html><head><title>${title}</title></head><body></body></html>`; |
| 7 | + |
| 8 | +suite('htmlHelper Test Suite', () => { |
| 9 | + |
| 10 | + test('Given no title element, getTitle returns null', () => { |
| 11 | + const input = ''; |
| 12 | + const result = getTitle(input); |
| 13 | + assert.strictEqual(result, null); |
| 14 | + }); |
| 15 | + |
| 16 | + test('Given a title element with plain title, getTitle returns the plain title', () => { |
| 17 | + const input = toHtmlContent(plainTitle); |
| 18 | + const result = getTitle(input); |
| 19 | + assert.strictEqual(result, plainTitle); |
| 20 | + }); |
| 21 | + |
| 22 | + test('Given a title element with leading whitespace, getTitle returns the plain title', () => { |
| 23 | + const input = toHtmlContent(' \n\t ' + plainTitle); |
| 24 | + const result = getTitle(input); |
| 25 | + assert.strictEqual(result, plainTitle); |
| 26 | + }); |
| 27 | + |
| 28 | + test('Given a title element with trailing whitespace, getTitle returns the plain title', () => { |
| 29 | + const input = toHtmlContent(plainTitle + ' \n\t '); |
| 30 | + const result = getTitle(input); |
| 31 | + assert.strictEqual(result, plainTitle); |
| 32 | + }); |
| 33 | + |
| 34 | + test('Given a title element with named entity, getTitle returns the title with resolved entity', () => { |
| 35 | + const input = toHtmlContent('ü'); |
| 36 | + const expected = 'ü'; |
| 37 | + const result = getTitle(input); |
| 38 | + assert.strictEqual(result, expected); |
| 39 | + }); |
| 40 | + |
| 41 | + test('Given a title element with decimal code point entity, getTitle returns the title with resolved entity', () => { |
| 42 | + const input = toHtmlContent('ü'); |
| 43 | + const expected = 'ü'; |
| 44 | + const result = getTitle(input); |
| 45 | + assert.strictEqual(result, expected); |
| 46 | + }); |
| 47 | + |
| 48 | + test('Given a title element with hexadecimal code point entity, getTitle returns the title with resolved entity', () => { |
| 49 | + const input = toHtmlContent('ü'); |
| 50 | + const expected = 'ü'; |
| 51 | + const result = getTitle(input); |
| 52 | + assert.strictEqual(result, expected); |
| 53 | + }); |
| 54 | + |
| 55 | + test('Given a title element with unknown entity, getTitle returns the title with unresolved entity', () => { |
| 56 | + const input = toHtmlContent('&unknown;'); |
| 57 | + const expected = '&unknown;'; |
| 58 | + const result = getTitle(input); |
| 59 | + assert.strictEqual(result, expected); |
| 60 | + }); |
| 61 | +}); |
0 commit comments