diff --git a/package.json b/package.json index a14368f15..6782ff132 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "test:mustache-syntax:block": "jest \".*(mustache-syntax).*\" -t '^Block:.*' --verbose --noStackTrace", "test:mustache-syntax:injection": "jest \".*(mustache-syntax).*\" -t '^Injection:.*' --verbose --noStackTrace", "test:definition-lists": "jest tests/markdown/definition-lists.test.js --verbose --noStackTrace", + "test:emojis": "jest tests/markdown/emojis.test.js --verbose --noStackTrace", "test:route": "jest tests/routes/static-pages.test.js --verbose", "phb": "node scripts/phb.js", "prod": "set NODE_ENV=production && npm run build", diff --git a/tests/markdown/emojis.test.js b/tests/markdown/emojis.test.js new file mode 100644 index 000000000..a4abbc6a4 --- /dev/null +++ b/tests/markdown/emojis.test.js @@ -0,0 +1,58 @@ +const Markdown = require('naturalcrit/markdown.js'); +const dedent = require('dedent-tabs').default; + +// Marked.js adds line returns after closing tags on some default tokens. +// This removes those line returns for comparison sake. +String.prototype.trimReturns = function(){ + return this.replace(/\r?\n|\r/g, ''); +}; + +const emoji = 'df_d12_2'; + +describe(`When emojis/icons are active`, ()=>{ + it('when a word is between two colons (:word:), and a matching emoji exists, it is rendered as an emoji', function() { + const source = `:${emoji}:`; + const rendered = Markdown.render(source).trimReturns(); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`

`); + }); + + it('when a word is between two colons (:word:), and no matching emoji exists, it is not parsed', function() { + const source = `:invalid:`; + const rendered = Markdown.render(source).trimReturns(); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`

:invalid:

`); + }); + + it('two valid emojis with no whitespace are prioritized over definition lists', function() { + const source = `:${emoji}::${emoji}:`; + const rendered = Markdown.render(source).trimReturns(); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`

`); + }); + + it('definition lists that are not also part of an emoji can coexist with normal emojis', function() { + const source = `definition :: term ${emoji}::${emoji}:`; + const rendered = Markdown.render(source).trimReturns(); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`
definition
term df_d12_2:
`); + }); + + it('A valid emoji is compatible with curly injectors', function() { + const source = `:${emoji}:{color:blue,myClass}`; + const rendered = Markdown.render(source).trimReturns(); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`

`); + }); + + it('Emojis are not parsed inside of curly span CSS blocks', function() { + const source = `{{color:${emoji} text}}`; + const rendered = Markdown.render(source).trimReturns(); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`text`); + }); + + it('Emojis are not parsed inside of curly div CSS blocks', function() { + const source = dedent`{{color:${emoji} + text + }}`; + const rendered = Markdown.render(source).trimReturns(); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`

text

`); + }); + + // another test of the editor to confirm an autocomplete menu opens +}); \ No newline at end of file