Add acceptance tests for custom-html

This commit is contained in:
Robin Ward
2016-11-23 12:57:50 -05:00
parent 79dc0518c9
commit ae4fd06444
6 changed files with 61 additions and 24 deletions

View File

@ -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;

View File

@ -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', '<span class="custom-html-test">HTML</span>');
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: "<span class='cookie'>monster</span>"});
visit("/static/faq");
andThen(() => {
assert.equal(find('span.cookie').text(), 'monster', 'it inserted the markup');
});
});

View File

@ -0,0 +1,18 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("CustomHTML template", {
setup() {
Ember.TEMPLATES['top'] = Ember.HTMLBars.compile(`<span class='top-span'>TOP</span>`);
},
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');
});
});

View File

@ -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(
`
<span class='hello-username'>{{model.username}}</span>
`<span class='hello-username'>{{model.username}}</span>
<button class='hello-check-email' {{action "checkEmail" model}}></button>
<span class='hello-email'>{{model.email}}</span>
`
<span class='hello-email'>{{model.email}}</span>`
);
},
teardown() {
delete Ember.TEMPLATES[CONNECTOR];
clearCache();
}
});

View File

@ -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');
});

View File

@ -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();
}