import highlightSyntax from "discourse/lib/highlight-syntax"; import { module, test } from "qunit"; import { fixture } from "discourse/tests/helpers/qunit-helpers"; let siteSettings = { autohighlight_all_code: true }, session = { highlightJsPath: "/assets/highlightjs/highlight-test-bundle.min.js", }; module("Unit | Utility | highlight-syntax", function () { test("highlighting code", async function (assert) { fixture().innerHTML = `
        
          def code
            puts 1 + 2
          end
        
      
`; await highlightSyntax(fixture(), siteSettings, session); assert.strictEqual( document .querySelector("code.language-ruby.hljs .hljs-keyword") .innerText.trim(), "def" ); }); test("highlighting code with HTML intermingled", async function (assert) { fixture().innerHTML = `
        
          
  1. def code
  2. puts 1 + 2
  3. end
`; await highlightSyntax(fixture(), siteSettings, session); assert.strictEqual( document .querySelector("code.language-ruby.hljs .hljs-keyword") .innerText.trim(), "def" ); // Checks if HTML structure was preserved assert.strictEqual( document.querySelectorAll("code.language-ruby.hljs ol li").length, 3 ); }); });