diff --git a/app/assets/javascripts/discourse/helpers/custom-html.js.es6 b/app/assets/javascripts/discourse/helpers/custom-html.js.es6 index 5a389ea49c2..4828ae057ec 100644 --- a/app/assets/javascripts/discourse/helpers/custom-html.js.es6 +++ b/app/assets/javascripts/discourse/helpers/custom-html.js.es6 @@ -1,7 +1,7 @@ import { registerHelper } from 'discourse-common/lib/helpers'; import PreloadStore from 'preload-store'; -const _customizations = {}; +let _customizations = {}; export function getCustomHTML(key) { const c = _customizations[key]; @@ -15,6 +15,10 @@ export function getCustomHTML(key) { } } +export function clearHTMLCache() { + _customizations = {}; +} + // Set a fragment of HTML by key. It can then be looked up with `getCustomHTML(key)`. export function setCustomHTML(key, html) { _customizations[key] = html; diff --git a/test/javascripts/acceptance/custom-html-set-test.js.es6 b/test/javascripts/acceptance/custom-html-set-test.js.es6 new file mode 100644 index 00000000000..3ae0bd63737 --- /dev/null +++ b/test/javascripts/acceptance/custom-html-set-test.js.es6 @@ -0,0 +1,30 @@ +import { acceptance } from "helpers/qunit-helpers"; +import { setCustomHTML } from 'discourse/helpers/custom-html'; +import PreloadStore from 'preload-store'; + +acceptance("CustomHTML set"); + +test("has no custom HTML in the top", assert => { + visit("/static/faq"); + andThen(() => { + assert.ok(!exists('span.custom-html-test'), 'it has no markup'); + }); +}); + +test("renders set HTML", assert => { + setCustomHTML('top', 'HTML'); + + visit("/static/faq"); + andThen(() => { + assert.equal(find('span.custom-html-test').text(), 'HTML', 'it inserted the markup'); + }); +}); + +test("renders preloaded HTML", assert => { + PreloadStore.store('customHTML', {top: "monster"}); + + visit("/static/faq"); + andThen(() => { + assert.equal(find('span.cookie').text(), 'monster', 'it inserted the markup'); + }); +}); diff --git a/test/javascripts/acceptance/custom-html-template-test.js.es6 b/test/javascripts/acceptance/custom-html-template-test.js.es6 new file mode 100644 index 00000000000..d125236ebbc --- /dev/null +++ b/test/javascripts/acceptance/custom-html-template-test.js.es6 @@ -0,0 +1,18 @@ +import { acceptance } from "helpers/qunit-helpers"; + +acceptance("CustomHTML template", { + setup() { + Ember.TEMPLATES['top'] = Ember.HTMLBars.compile(`TOP`); + }, + + teardown() { + delete Ember.TEMPLATES['top']; + } +}); + +test("renders custom template", assert => { + visit("/static/faq"); + andThen(() => { + assert.equal(find('span.top-span').text(), 'TOP', 'it inserted the template'); + }); +}); diff --git a/test/javascripts/acceptance/plugin-outlet-single-template-test.js.es6 b/test/javascripts/acceptance/plugin-outlet-single-template-test.js.es6 index df63e013114..228506e27c9 100644 --- a/test/javascripts/acceptance/plugin-outlet-single-template-test.js.es6 +++ b/test/javascripts/acceptance/plugin-outlet-single-template-test.js.es6 @@ -1,22 +1,17 @@ import { acceptance } from "helpers/qunit-helpers"; -import { clearCache } from 'discourse/helpers/plugin-outlet'; const CONNECTOR = 'javascripts/single-test/connectors/user-profile-primary/hello'; acceptance("Plugin Outlet - Single Template", { setup() { - clearCache(); Ember.TEMPLATES[CONNECTOR] = Ember.HTMLBars.compile( - ` - {{model.username}} + `{{model.username}} - {{model.email}} - ` + {{model.email}}` ); }, teardown() { delete Ember.TEMPLATES[CONNECTOR]; - clearCache(); } }); diff --git a/test/javascripts/helpers/custom-html-test.js.es6 b/test/javascripts/helpers/custom-html-test.js.es6 deleted file mode 100644 index 4c7f765e606..00000000000 --- a/test/javascripts/helpers/custom-html-test.js.es6 +++ /dev/null @@ -1,16 +0,0 @@ -import { blank } from 'helpers/qunit-helpers'; -import PreloadStore from 'preload-store'; - -module("helper:custom-html"); - -import { getCustomHTML, setCustomHTML } from 'discourse/helpers/custom-html'; - -test("customHTML", function() { - blank(getCustomHTML('evil'), "there is no custom HTML for a key by default"); - - setCustomHTML('evil', 'trout'); - equal(getCustomHTML('evil'), 'trout', 'it retrieves the custom html'); - - PreloadStore.store('customHTML', {cookie: 'monster'}); - equal(getCustomHTML('cookie'), 'monster', 'it returns HTML fragments from the PreloadStore'); -}); diff --git a/test/javascripts/helpers/qunit-helpers.js.es6 b/test/javascripts/helpers/qunit-helpers.js.es6 index 4a822c1266c..d8351405f0c 100644 --- a/test/javascripts/helpers/qunit-helpers.js.es6 +++ b/test/javascripts/helpers/qunit-helpers.js.es6 @@ -5,6 +5,8 @@ import siteFixtures from 'fixtures/site-fixtures'; import HeaderComponent from 'discourse/components/site-header'; import { forceMobile, resetMobile } from 'discourse/lib/mobile'; import { resetPluginApi } from 'discourse/lib/plugin-api'; +import { clearCache as clearOutletCache } from 'discourse/helpers/plugin-outlet'; +import { clearHTMLCache } from 'discourse/helpers/custom-html'; function currentUser() { return Discourse.User.create(sessionFixtures['/session/current.json'].current_user); @@ -65,6 +67,8 @@ function acceptance(name, options) { } } + clearOutletCache(); + clearHTMLCache(); resetPluginApi(); Discourse.reset(); }, @@ -76,6 +80,8 @@ function acceptance(name, options) { Discourse.User.resetCurrent(); Discourse.Site.resetCurrent(Discourse.Site.create(jQuery.extend(true, {}, fixtures['site.json'].site))); + clearOutletCache(); + clearHTMLCache(); resetPluginApi(); Discourse.reset(); }