UNPKG

@condenast/flyway-schema-validator

Version:
136 lines (122 loc) 4.15 kB
/* eslint-env jest */ const escapeUnwantedBlockMarkdown = require('./escapeUnwantedBlockMarkdown'); describe('escapeUnwantedBlockMarkdown', () => { it('should not invalidate inline HTML', () => { const stringsToEscape = [ 'test <em>test</em> test', '<em>test</em>', 'test <a href="https://www.marksandspencer.com/de/sizeguides/?cid=sizeguidewomens-tops&test#Returns-Policy">Welcome to Marks &amp; Spencer</a> test', '<a href="https://www.marksandspencer.com/de/sizeguides/?cid=sizeguidewomens-tops&test#Returns-Policy">Welcome to Marks &amp; Spencer</a>' ]; const result = stringsToEscape.map(escapeUnwantedBlockMarkdown); const expectedResult = [...stringsToEscape]; // expect no changes expect(result).toEqual(expectedResult); }); it('should not escape markdown links', () => { const stringsToEscape = [ 'test [test](https://www.marksandspencer.com/de/sizeguides/?cid=sizeguidewomens-tops&test#Returns-Policy) test', '[test](https://www.marksandspencer.com/de/sizeguides/?cid=sizeguidewomens-tops&test#Returns-Policy)' ]; const result = stringsToEscape.map(escapeUnwantedBlockMarkdown); const expectedResult = [...stringsToEscape]; // expect no changes expect(result).toEqual(expectedResult); }); describe('markdown that should never be parsed anywhere in the string', () => { const stringsToEscape = ['test`test', '`test', 'test[#embed:url]test', '[#embed:url]test']; const expectedResult = ['test\\`test', '\\`test', 'test\\[#embed:url]test', '\\[#embed:url]test']; it('should escape unwanted markdown entities', () => { const result = stringsToEscape.map(escapeUnwantedBlockMarkdown); expect(result).toEqual(expectedResult); }); it('should not escape markdown entities that are already escaped', () => { const result = expectedResult.map(escapeUnwantedBlockMarkdown); expect(result).toEqual(expectedResult); }); }); describe('markdown chars that should not be parsed if they appear at the beginning', () => { const stringsToEscape = [ '>#test', '#>test', 'test>#test', '>test', '> test', 'test>test', '#test', '# test', 'test#test' ]; const expectedResult = [ '\\>#test', '\\#>test', 'test>#test', '\\>test', '\\> test', 'test>test', '\\#test', '\\# test', 'test#test' ]; it('should escape unwanted markdown entities', () => { const result = stringsToEscape.map(escapeUnwantedBlockMarkdown); expect(result).toEqual(expectedResult); }); it('should not escape markdown entities that are already escaped', () => { const result = expectedResult.map(escapeUnwantedBlockMarkdown); expect(result).toEqual(expectedResult); }); }); describe('markdown list markers that should not be parsed', () => { const stringsToEscape = [ '* test', '*test', 'test*test', '- test', '-test', 'test-test', '3. test', '3.test', 'test3.test', '99. test', '99.test', 'test99.test', '3) test', '3)test', 'test3)test', '99) test', '99)test', 'test99)test', '3a test', '99a test' ]; const expectedResult = [ '\\* test', '*test', 'test*test', '\\- test', '-test', 'test-test', '3\\. test', '3.test', 'test3.test', '99\\. test', '99.test', 'test99.test', '3\\) test', '3)test', 'test3)test', '99\\) test', '99)test', 'test99)test', '3a test', '99a test' // expect no change as this is not a list marker ]; it('should escape unwanted markdown entities', () => { const result = stringsToEscape.map(escapeUnwantedBlockMarkdown); expect(result).toEqual(expectedResult); }); it('should not escape markdown entities that are already escaped', () => { const result = expectedResult.map(escapeUnwantedBlockMarkdown); expect(result).toEqual(expectedResult); }); }); });