DEV: Migrate to Ember CLI (#11932)
This encompasses a lot of work done over the last year, much of which has already been merged into master. This is the final set of changes required to get Ember CLI running locally for development. From here on it will be bug fixes / enhancements. Co-authored-by: Jarek Radosz <jradosz@gmail.com> Co-authored-by: romanrizzi <rizziromanalejandro@gmail.com> Co-authored-by: Jarek Radosz <jradosz@gmail.com> Co-authored-by: romanrizzi <rizziromanalejandro@gmail.com>
This commit is contained in:
parent
8ad5284cf7
commit
61f5d501cb
|
@ -14,6 +14,7 @@ import {
|
||||||
import { getOwner, setDefaultOwner } from "discourse-common/lib/get-owner";
|
import { getOwner, setDefaultOwner } from "discourse-common/lib/get-owner";
|
||||||
import { setApplication, setResolver } from "@ember/test-helpers";
|
import { setApplication, setResolver } from "@ember/test-helpers";
|
||||||
import { setupS3CDN, setupURL } from "discourse-common/lib/get-url";
|
import { setupS3CDN, setupURL } from "discourse-common/lib/get-url";
|
||||||
|
import Application from "../app";
|
||||||
import MessageBus from "message-bus-client";
|
import MessageBus from "message-bus-client";
|
||||||
import PreloadStore from "discourse/lib/preload-store";
|
import PreloadStore from "discourse/lib/preload-store";
|
||||||
import QUnit from "qunit";
|
import QUnit from "qunit";
|
||||||
|
@ -26,6 +27,8 @@ import { clearAppEventsCache } from "discourse/services/app-events";
|
||||||
import { createHelperContext } from "discourse-common/lib/helpers";
|
import { createHelperContext } from "discourse-common/lib/helpers";
|
||||||
import deprecated from "discourse-common/lib/deprecated";
|
import deprecated from "discourse-common/lib/deprecated";
|
||||||
import { flushMap } from "discourse/models/store";
|
import { flushMap } from "discourse/models/store";
|
||||||
|
import { registerObjects } from "discourse/pre-initializers/inject-discourse-objects";
|
||||||
|
import { setupApplicationTest } from "ember-qunit";
|
||||||
import sinon from "sinon";
|
import sinon from "sinon";
|
||||||
|
|
||||||
const Plugin = $.fn.modal;
|
const Plugin = $.fn.modal;
|
||||||
|
@ -55,9 +58,33 @@ function AcceptanceModal(option, _relatedTarget) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function setupTests(app, container) {
|
let app;
|
||||||
|
let started = false;
|
||||||
|
|
||||||
|
function createApplication(config, settings) {
|
||||||
|
app = Application.create(config);
|
||||||
|
setApplication(app);
|
||||||
setResolver(buildResolver("discourse").create({ namespace: app }));
|
setResolver(buildResolver("discourse").create({ namespace: app }));
|
||||||
|
|
||||||
|
let container = app.__registry__.container();
|
||||||
|
app.__container__ = container;
|
||||||
|
setDefaultOwner(container);
|
||||||
|
|
||||||
|
if (!started) {
|
||||||
|
app.start();
|
||||||
|
started = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.SiteSettings = settings;
|
||||||
|
registerObjects(container, app);
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupTestsCommon(application, container, config) {
|
||||||
|
application.rootElement = "#ember-testing";
|
||||||
|
application.setupForTesting();
|
||||||
|
application.injectTestHelpers();
|
||||||
|
|
||||||
sinon.config = {
|
sinon.config = {
|
||||||
injectIntoThis: false,
|
injectIntoThis: false,
|
||||||
injectInto: null,
|
injectInto: null,
|
||||||
|
@ -69,13 +96,6 @@ export default function setupTests(app, container) {
|
||||||
// Stop the message bus so we don't get ajax calls
|
// Stop the message bus so we don't get ajax calls
|
||||||
MessageBus.stop();
|
MessageBus.stop();
|
||||||
|
|
||||||
app.rootElement = "#ember-testing";
|
|
||||||
app.setupForTesting();
|
|
||||||
app.SiteSettings = currentSettings();
|
|
||||||
app.start();
|
|
||||||
bootbox.$body = $("#ember-testing");
|
|
||||||
$.fn.modal = AcceptanceModal;
|
|
||||||
|
|
||||||
// disable logster error reporting
|
// disable logster error reporting
|
||||||
if (window.Logster) {
|
if (window.Logster) {
|
||||||
window.Logster.enabled = false;
|
window.Logster.enabled = false;
|
||||||
|
@ -83,6 +103,8 @@ export default function setupTests(app, container) {
|
||||||
window.Logster = { enabled: false };
|
window.Logster = { enabled: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$.fn.modal = AcceptanceModal;
|
||||||
|
|
||||||
let server;
|
let server;
|
||||||
|
|
||||||
Object.defineProperty(window, "server", {
|
Object.defineProperty(window, "server", {
|
||||||
|
@ -123,7 +145,14 @@ export default function setupTests(app, container) {
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.testStart(function (ctx) {
|
QUnit.testStart(function (ctx) {
|
||||||
|
bootbox.$body = $("#ember-testing");
|
||||||
let settings = resetSettings();
|
let settings = resetSettings();
|
||||||
|
|
||||||
|
if (config) {
|
||||||
|
// Ember CLI testing environment
|
||||||
|
app = createApplication(config, settings);
|
||||||
|
}
|
||||||
|
|
||||||
server = createPretender;
|
server = createPretender;
|
||||||
server.handlers = [];
|
server.handlers = [];
|
||||||
applyDefaultHandlers(server);
|
applyDefaultHandlers(server);
|
||||||
|
@ -190,10 +219,12 @@ export default function setupTests(app, container) {
|
||||||
$(".modal-backdrop").remove();
|
$(".modal-backdrop").remove();
|
||||||
flushMap();
|
flushMap();
|
||||||
|
|
||||||
// ensures any event not removed is not leaking between tests
|
if (!setupApplicationTest) {
|
||||||
// most likely in intialisers, other places (controller, component...)
|
// ensures any event not removed is not leaking between tests
|
||||||
// should be fixed in code
|
// most likely in intialisers, other places (controller, component...)
|
||||||
clearAppEventsCache(getOwner(this));
|
// should be fixed in code
|
||||||
|
clearAppEventsCache(getOwner(this));
|
||||||
|
}
|
||||||
|
|
||||||
MessageBus.unsubscribe("*");
|
MessageBus.unsubscribe("*");
|
||||||
server = null;
|
server = null;
|
||||||
|
@ -226,7 +257,23 @@ export default function setupTests(app, container) {
|
||||||
|
|
||||||
// forces 0 as duration for all jquery animations
|
// forces 0 as duration for all jquery animations
|
||||||
jQuery.fx.off = true;
|
jQuery.fx.off = true;
|
||||||
setApplication(app);
|
|
||||||
setDefaultOwner(container);
|
setApplication(application);
|
||||||
|
setDefaultOwner(application.__container__);
|
||||||
resetSite();
|
resetSite();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setupTestsLegacy(application) {
|
||||||
|
app = application;
|
||||||
|
setResolver(buildResolver("discourse").create({ namespace: app }));
|
||||||
|
setupTestsCommon(application, app.__container__);
|
||||||
|
|
||||||
|
app.SiteSettings = currentSettings();
|
||||||
|
app.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function setupTests(config) {
|
||||||
|
let settings = resetSettings();
|
||||||
|
app = createApplication(config, settings);
|
||||||
|
setupTestsCommon(app, app.__container__, config);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
import config from "../config/environment";
|
||||||
|
import { setEnvironment } from "discourse-common/config/environment";
|
||||||
|
import { start } from "ember-qunit";
|
||||||
|
|
||||||
|
setEnvironment("testing");
|
||||||
|
|
||||||
|
document.addEventListener("discourse-booted", () => {
|
||||||
|
let setupTests = require("discourse/tests/setup-tests").default;
|
||||||
|
Ember.ENV.LOG_STACKTRACE_ON_DEPRECATION = false;
|
||||||
|
|
||||||
|
setupTests(config.APP);
|
||||||
|
start();
|
||||||
|
});
|
|
@ -50,7 +50,5 @@ document.write(
|
||||||
"<style>#ember-testing-container { position: absolute; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; } #ember-testing { zoom: 50%; }</style>"
|
"<style>#ember-testing-container { position: absolute; background: white; bottom: 0; right: 0; width: 640px; height: 384px; overflow: auto; z-index: 9999; border: 1px solid #ccc; } #ember-testing { zoom: 50%; }</style>"
|
||||||
);
|
);
|
||||||
|
|
||||||
let app = window.Discourse;
|
let setupTestsLegacy = require("discourse/tests/setup-tests").setupTestsLegacy;
|
||||||
app.injectTestHelpers();
|
setupTestsLegacy(window.Discourse);
|
||||||
let setupTests = require("discourse/tests/setup-tests").default;
|
|
||||||
setupTests(app, app.__container__);
|
|
||||||
|
|
|
@ -9,10 +9,6 @@ discourseModule("Unit | Controller | avatar-selector", function (hooks) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("avatarTemplate", function (assert) {
|
test("avatarTemplate", function (assert) {
|
||||||
const avatarSelectorController = this.owner.lookup(
|
|
||||||
"controller:avatar-selector"
|
|
||||||
);
|
|
||||||
|
|
||||||
const user = EmberObject.create({
|
const user = EmberObject.create({
|
||||||
avatar_template: "avatar",
|
avatar_template: "avatar",
|
||||||
system_avatar_template: "system",
|
system_avatar_template: "system",
|
||||||
|
@ -22,8 +18,9 @@ discourseModule("Unit | Controller | avatar-selector", function (hooks) {
|
||||||
gravatar_avatar_upload_id: 2,
|
gravatar_avatar_upload_id: 2,
|
||||||
custom_avatar_upload_id: 3,
|
custom_avatar_upload_id: 3,
|
||||||
});
|
});
|
||||||
|
const avatarSelectorController = this.getController("avatar-selector", {
|
||||||
avatarSelectorController.setProperties({ user });
|
user,
|
||||||
|
});
|
||||||
|
|
||||||
user.set("avatar_template", "system");
|
user.set("avatar_template", "system");
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
|
|
@ -4,8 +4,8 @@ import { test } from "qunit";
|
||||||
|
|
||||||
discourseModule("Unit | Controller | create-account", function () {
|
discourseModule("Unit | Controller | create-account", function () {
|
||||||
test("basicUsernameValidation", async function (assert) {
|
test("basicUsernameValidation", async function (assert) {
|
||||||
const testInvalidUsername = async function (username, expectedReason) {
|
const testInvalidUsername = async (username, expectedReason) => {
|
||||||
const controller = await this.owner.lookup("controller:create-account");
|
const controller = this.getController("create-account");
|
||||||
controller.set("accountUsername", username);
|
controller.set("accountUsername", username);
|
||||||
|
|
||||||
let validation = controller.basicUsernameValidation(username);
|
let validation = controller.basicUsernameValidation(username);
|
||||||
|
@ -15,7 +15,7 @@ discourseModule("Unit | Controller | create-account", function () {
|
||||||
expectedReason,
|
expectedReason,
|
||||||
"username validation reason: " + username + ", " + expectedReason
|
"username validation reason: " + username + ", " + expectedReason
|
||||||
);
|
);
|
||||||
}.bind(this);
|
};
|
||||||
|
|
||||||
testInvalidUsername("", undefined);
|
testInvalidUsername("", undefined);
|
||||||
testInvalidUsername("x", I18n.t("user.username.too_short"));
|
testInvalidUsername("x", I18n.t("user.username.too_short"));
|
||||||
|
@ -40,7 +40,7 @@ discourseModule("Unit | Controller | create-account", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("passwordValidation", async function (assert) {
|
test("passwordValidation", async function (assert) {
|
||||||
const controller = await this.owner.lookup("controller:create-account");
|
const controller = this.getController("create-account");
|
||||||
|
|
||||||
controller.set("authProvider", "");
|
controller.set("authProvider", "");
|
||||||
controller.set("accountEmail", "pork@chops.com");
|
controller.set("accountEmail", "pork@chops.com");
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { test } from "qunit";
|
||||||
|
|
||||||
discourseModule("Unit | Controller | history", function () {
|
discourseModule("Unit | Controller | history", function () {
|
||||||
test("displayEdit", async function (assert) {
|
test("displayEdit", async function (assert) {
|
||||||
const HistoryController = this.owner.lookup("controller:history");
|
const HistoryController = this.getController("history");
|
||||||
|
|
||||||
HistoryController.setProperties({
|
HistoryController.setProperties({
|
||||||
model: { last_revision: 3, current_revision: 3, can_edit: false },
|
model: { last_revision: 3, current_revision: 3, can_edit: false },
|
||||||
|
|
|
@ -1,25 +1,23 @@
|
||||||
import EmberObject from "@ember/object";
|
|
||||||
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
|
|
||||||
discourseModule("Unit | Controller | preferences/account", function () {
|
discourseModule("Unit | Controller | preferences/account", function () {
|
||||||
test("updating of associated accounts", function (assert) {
|
test("updating of associated accounts", function (assert) {
|
||||||
const controller = this.owner.lookup("controller:preferences/account");
|
const controller = this.getController("preferences/account", {
|
||||||
controller.setProperties({
|
|
||||||
siteSettings: {
|
siteSettings: {
|
||||||
enable_google_oauth2_logins: true,
|
enable_google_oauth2_logins: true,
|
||||||
},
|
},
|
||||||
model: EmberObject.create({
|
model: {
|
||||||
id: 70,
|
id: 70,
|
||||||
second_factor_enabled: true,
|
second_factor_enabled: true,
|
||||||
is_anonymous: true,
|
is_anonymous: true,
|
||||||
}),
|
},
|
||||||
currentUser: EmberObject.create({
|
currentUser: {
|
||||||
id: 1234,
|
id: 1234,
|
||||||
}),
|
},
|
||||||
site: EmberObject.create({
|
site: {
|
||||||
isMobileDevice: false,
|
isMobileDevice: false,
|
||||||
}),
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(controller.get("canUpdateAssociatedAccounts"), false);
|
assert.equal(controller.get("canUpdateAssociatedAccounts"), false);
|
||||||
|
|
|
@ -3,15 +3,11 @@ import { test } from "qunit";
|
||||||
|
|
||||||
discourseModule("Unit | Controller | preferences/second-factor", function () {
|
discourseModule("Unit | Controller | preferences/second-factor", function () {
|
||||||
test("displayOAuthWarning when OAuth login methods are enabled", function (assert) {
|
test("displayOAuthWarning when OAuth login methods are enabled", function (assert) {
|
||||||
const controller = this.owner.lookup(
|
const controller = this.getController("preferences/second-factor", {
|
||||||
"controller:preferences/second-factor"
|
|
||||||
);
|
|
||||||
controller.setProperties({
|
|
||||||
siteSettings: {
|
siteSettings: {
|
||||||
enable_google_oauth2_logins: true,
|
enable_google_oauth2_logins: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(controller.get("displayOAuthWarning"), true);
|
assert.equal(controller.get("displayOAuthWarning"), true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import EmberObject from "@ember/object";
|
|
||||||
import createStore from "discourse/tests/helpers/create-store";
|
import createStore from "discourse/tests/helpers/create-store";
|
||||||
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
|
@ -12,11 +11,10 @@ discourseModule("Unit | Controller | reorder-categories", function () {
|
||||||
categories.push(store.createRecord("category", { id: i, position: 0 }));
|
categories.push(store.createRecord("category", { id: i, position: 0 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
const site = EmberObject.create({ categories: categories });
|
const reorderCategoriesController = this.getController(
|
||||||
const reorderCategoriesController = this.owner.lookup(
|
"reorder-categories",
|
||||||
"controller:reorder-categories"
|
{ site: { categories } }
|
||||||
);
|
);
|
||||||
reorderCategoriesController.setProperties({ site });
|
|
||||||
reorderCategoriesController.reorder();
|
reorderCategoriesController.reorder();
|
||||||
|
|
||||||
reorderCategoriesController
|
reorderCategoriesController
|
||||||
|
@ -52,14 +50,11 @@ discourseModule("Unit | Controller | reorder-categories", function () {
|
||||||
slug: "other",
|
slug: "other",
|
||||||
});
|
});
|
||||||
|
|
||||||
const categories = [child2, parent, other, child1];
|
|
||||||
const expectedOrderSlugs = ["parent", "child2", "child1", "other"];
|
const expectedOrderSlugs = ["parent", "child2", "child1", "other"];
|
||||||
|
const reorderCategoriesController = this.getController(
|
||||||
const site = EmberObject.create({ categories: categories });
|
"reorder-categories",
|
||||||
const reorderCategoriesController = this.owner.lookup(
|
{ site: { categories: [child2, parent, other, child1] } }
|
||||||
"controller:reorder-categories"
|
|
||||||
);
|
);
|
||||||
reorderCategoriesController.setProperties({ site });
|
|
||||||
reorderCategoriesController.reorder();
|
reorderCategoriesController.reorder();
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
|
@ -89,12 +84,10 @@ discourseModule("Unit | Controller | reorder-categories", function () {
|
||||||
slug: "test",
|
slug: "test",
|
||||||
});
|
});
|
||||||
|
|
||||||
const categories = [elem1, elem2, elem3];
|
const reorderCategoriesController = this.getController(
|
||||||
const site = EmberObject.create({ categories: categories });
|
"reorder-categories",
|
||||||
const reorderCategoriesController = this.owner.lookup(
|
{ site: { categories: [elem1, elem2, elem3] } }
|
||||||
"controller:reorder-categories"
|
|
||||||
);
|
);
|
||||||
reorderCategoriesController.setProperties({ site });
|
|
||||||
|
|
||||||
reorderCategoriesController.actions.change.call(
|
reorderCategoriesController.actions.change.call(
|
||||||
reorderCategoriesController,
|
reorderCategoriesController,
|
||||||
|
@ -136,12 +129,10 @@ discourseModule("Unit | Controller | reorder-categories", function () {
|
||||||
slug: "test",
|
slug: "test",
|
||||||
});
|
});
|
||||||
|
|
||||||
const categories = [elem1, child1, elem2, elem3];
|
const reorderCategoriesController = this.getController(
|
||||||
const site = EmberObject.create({ categories: categories });
|
"reorder-categories",
|
||||||
const reorderCategoriesController = this.owner.lookup(
|
{ site: { categories: [elem1, child1, elem2, elem3] } }
|
||||||
"controller:reorder-categories"
|
|
||||||
);
|
);
|
||||||
reorderCategoriesController.setProperties({ site });
|
|
||||||
|
|
||||||
reorderCategoriesController.actions.change.call(
|
reorderCategoriesController.actions.change.call(
|
||||||
reorderCategoriesController,
|
reorderCategoriesController,
|
||||||
|
@ -190,12 +181,10 @@ discourseModule("Unit | Controller | reorder-categories", function () {
|
||||||
slug: "test",
|
slug: "test",
|
||||||
});
|
});
|
||||||
|
|
||||||
const categories = [elem1, child1, child2, elem2, elem3];
|
const reorderCategoriesController = this.getController(
|
||||||
const site = EmberObject.create({ categories: categories });
|
"reorder-categories",
|
||||||
const reorderCategoriesController = this.owner.lookup(
|
{ site: { categories: [elem1, child1, child2, elem2, elem3] } }
|
||||||
"controller:reorder-categories"
|
|
||||||
);
|
);
|
||||||
reorderCategoriesController.setProperties({ site });
|
|
||||||
reorderCategoriesController.reorder();
|
reorderCategoriesController.reorder();
|
||||||
|
|
||||||
reorderCategoriesController.actions.moveDown.call(
|
reorderCategoriesController.actions.moveDown.call(
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,19 +0,0 @@
|
||||||
import { module, test } from "qunit";
|
|
||||||
/* global BreakString:true */
|
|
||||||
|
|
||||||
module("Unit | Utility | breakString", function () {
|
|
||||||
test("breakString", function (assert) {
|
|
||||||
const b = (s, hint) => new BreakString(s).break(hint);
|
|
||||||
|
|
||||||
assert.equal(b("hello"), "hello");
|
|
||||||
assert.equal(b("helloworld"), "helloworld");
|
|
||||||
assert.equal(b("HeMans11"), "He<wbr>​Mans<wbr>​11");
|
|
||||||
assert.equal(b("he_man"), "he_<wbr>​man");
|
|
||||||
assert.equal(b("he11111"), "he<wbr>​11111");
|
|
||||||
assert.equal(b("HRCBob"), "HRC<wbr>​Bob");
|
|
||||||
assert.equal(
|
|
||||||
b("bobmarleytoo", "Bob Marley Too"),
|
|
||||||
"bob<wbr>​marley<wbr>​too"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -2,13 +2,21 @@ import {
|
||||||
currentUser,
|
currentUser,
|
||||||
discourseModule,
|
discourseModule,
|
||||||
} from "discourse/tests/helpers/qunit-helpers";
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import DocumentTitle from "discourse/services/document-title";
|
||||||
|
import AppEvents from "discourse/services/app-events";
|
||||||
|
import Session from "discourse/models/session";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
|
|
||||||
discourseModule("Unit | Service | document-title", function (hooks) {
|
discourseModule("Unit | Service | document-title", function (hooks) {
|
||||||
hooks.beforeEach(function () {
|
hooks.beforeEach(function () {
|
||||||
this.documentTitle = this.container.lookup("service:document-title");
|
const session = Session.current();
|
||||||
|
session.hasFocus = true;
|
||||||
|
|
||||||
|
this.documentTitle = DocumentTitle.create({
|
||||||
|
session,
|
||||||
|
appEvents: AppEvents.create(),
|
||||||
|
});
|
||||||
this.documentTitle.currentUser = null;
|
this.documentTitle.currentUser = null;
|
||||||
this.container.lookup("session:main").hasFocus = true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
hooks.afterEach(function () {
|
hooks.afterEach(function () {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
import { afterRender } from "discourse-common/utils/decorators";
|
import { afterRender } from "discourse-common/utils/decorators";
|
||||||
import componentTest from "discourse/tests/helpers/component-test";
|
import componentTest, {
|
||||||
import { exists } from "discourse/tests/helpers/qunit-helpers";
|
setupRenderingTest,
|
||||||
import { moduleForComponent } from "ember-qunit";
|
} from "discourse/tests/helpers/component-test";
|
||||||
|
import { discourseModule, exists } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import hbs from "htmlbars-inline-precompile";
|
||||||
|
|
||||||
const fooComponent = Component.extend({
|
const fooComponent = Component.extend({
|
||||||
layoutName: "foo-component",
|
|
||||||
|
|
||||||
classNames: ["foo-component"],
|
classNames: ["foo-component"],
|
||||||
|
|
||||||
baz: null,
|
baz: null,
|
||||||
|
@ -29,23 +29,25 @@ const fooComponent = Component.extend({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
moduleForComponent("utils:decorators", { integration: true });
|
discourseModule("utils:decorators", function (hooks) {
|
||||||
|
setupRenderingTest(hooks);
|
||||||
|
|
||||||
componentTest("afterRender", {
|
componentTest("afterRender", {
|
||||||
template: "{{foo-component baz=baz}}",
|
template: hbs`{{foo-component baz=baz}}`,
|
||||||
|
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
this.registry.register("component:foo-component", fooComponent);
|
this.registry.register("component:foo-component", fooComponent);
|
||||||
this.set("baz", 0);
|
this.set("baz", 0);
|
||||||
},
|
},
|
||||||
|
|
||||||
test(assert) {
|
async test(assert) {
|
||||||
assert.ok(exists(document.querySelector(".foo-component")));
|
assert.ok(exists(document.querySelector(".foo-component")));
|
||||||
assert.equal(this.baz, 1);
|
assert.equal(this.baz, 1);
|
||||||
|
|
||||||
this.clearRender();
|
await this.clearRender();
|
||||||
|
|
||||||
assert.ok(!exists(document.querySelector(".foo-component")));
|
assert.ok(!exists(document.querySelector(".foo-component")));
|
||||||
assert.equal(this.baz, 1);
|
assert.equal(this.baz, 1);
|
||||||
},
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"workspaces": [
|
||||||
|
"discourse",
|
||||||
|
"admin",
|
||||||
|
"discourse-common",
|
||||||
|
"discourse-hbr",
|
||||||
|
"discourse-widget-hbs",
|
||||||
|
"pretty-text",
|
||||||
|
"select-kit"
|
||||||
|
]
|
||||||
|
}
|
|
@ -15,9 +15,10 @@
|
||||||
"start": "ember serve"
|
"start": "ember serve"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"ember-auto-import": "^1.5.3",
|
||||||
"ember-cli-babel": "^7.13.0",
|
"ember-cli-babel": "^7.13.0",
|
||||||
"ember-cli-htmlbars": "^4.2.0",
|
"ember-cli-htmlbars": "^4.2.0",
|
||||||
"ember-auto-import": "^1.5.3"
|
"xss": "^1.0.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ember/optional-features": "^1.1.0",
|
"@ember/optional-features": "^1.1.0",
|
||||||
|
|
|
@ -52,7 +52,9 @@ define("@ember/test-helpers", () => {
|
||||||
return window[attr](...arguments);
|
return window[attr](...arguments);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
helpers.triggerKeyEvent = window.keyEvent;
|
helpers.triggerKeyEvent = function () {
|
||||||
|
return window.keyEvent(...arguments);
|
||||||
|
};
|
||||||
return helpers;
|
return helpers;
|
||||||
});
|
});
|
||||||
define("pretender", () => {
|
define("pretender", () => {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -279,9 +279,13 @@ class Compiler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function compile(template) {
|
const loader = typeof Ember !== "undefined" ? Ember.__loader.require : require;
|
||||||
const preprocessor = Ember.__loader.require("@glimmer/syntax");
|
|
||||||
const compiled = preprocessor.preprocess(template);
|
function compile(template, glimmer) {
|
||||||
|
if (!glimmer) {
|
||||||
|
glimmer = loader("@glimmer/syntax");
|
||||||
|
}
|
||||||
|
const compiled = glimmer.preprocess(template);
|
||||||
const compiler = new Compiler(compiled);
|
const compiler = new Compiler(compiled);
|
||||||
|
|
||||||
let code = compiler.compile();
|
let code = compiler.compile();
|
||||||
|
@ -305,7 +309,7 @@ function error(path, state, msg) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.WidgetHbsCompiler = function (babel) {
|
const WidgetHbsCompiler = function (babel) {
|
||||||
let t = babel.types;
|
let t = babel.types;
|
||||||
return {
|
return {
|
||||||
visitor: {
|
visitor: {
|
||||||
|
@ -353,11 +357,16 @@ exports.WidgetHbsCompiler = function (babel) {
|
||||||
.join("");
|
.join("");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
path.replaceWithSourceString(compile(template));
|
path.replaceWithSourceString(
|
||||||
|
compile(template, WidgetHbsCompiler.glimmer)
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error("widget hbs error", e.toString());
|
||||||
return error(path, state, e.toString());
|
return error(path, state, e.toString());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.WidgetHbsCompiler = WidgetHbsCompiler;
|
||||||
|
|
|
@ -66,7 +66,7 @@ acceptance("Poll breakdown", function (needs) {
|
||||||
"shows the breakdown button when poll_groupable_user_fields is non-empty"
|
"shows the breakdown button when poll_groupable_user_fields is non-empty"
|
||||||
);
|
);
|
||||||
|
|
||||||
await click(".poll-show-breakdown:first");
|
await click(".poll-show-breakdown");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-breakdown-total-votes")[0].textContent.trim(),
|
queryAll(".poll-breakdown-total-votes")[0].textContent.trim(),
|
||||||
|
@ -88,10 +88,10 @@ acceptance("Poll breakdown", function (needs) {
|
||||||
|
|
||||||
test("Changing the display mode from percentage to count", async function (assert) {
|
test("Changing the display mode from percentage to count", async function (assert) {
|
||||||
await visit("/t/-/topic_with_pie_chart_poll");
|
await visit("/t/-/topic_with_pie_chart_poll");
|
||||||
await click(".poll-show-breakdown:first");
|
await click(".poll-show-breakdown");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-breakdown-option-count:first")[0].textContent.trim(),
|
queryAll(".poll-breakdown-option-count")[0].textContent.trim(),
|
||||||
"40.0%",
|
"40.0%",
|
||||||
"displays the correct vote percentage"
|
"displays the correct vote percentage"
|
||||||
);
|
);
|
||||||
|
@ -99,7 +99,7 @@ acceptance("Poll breakdown", function (needs) {
|
||||||
await click(".modal-tabs .count");
|
await click(".modal-tabs .count");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-breakdown-option-count:first")[0].textContent.trim(),
|
queryAll(".poll-breakdown-option-count")[0].textContent.trim(),
|
||||||
"2",
|
"2",
|
||||||
"displays the correct vote count"
|
"displays the correct vote count"
|
||||||
);
|
);
|
||||||
|
|
|
@ -68,15 +68,15 @@ acceptance("Rendering polls with bar charts - desktop", function (needs) {
|
||||||
await click("button.toggle-results");
|
await click("button.toggle-results");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-voters:first li").length,
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
||||||
25,
|
25,
|
||||||
"it should display the right number of voters"
|
"it should display the right number of voters"
|
||||||
);
|
);
|
||||||
|
|
||||||
await click(".poll-voters-toggle-expand:first a");
|
await click(".poll-voters-toggle-expand:nth-of-type(1) a");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-voters:first li").length,
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
||||||
26,
|
26,
|
||||||
"it should display the right number of voters"
|
"it should display the right number of voters"
|
||||||
);
|
);
|
||||||
|
@ -91,20 +91,20 @@ acceptance("Rendering polls with bar charts - desktop", function (needs) {
|
||||||
await click("button.toggle-results");
|
await click("button.toggle-results");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-voters:first li").length,
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
||||||
25,
|
25,
|
||||||
"it should display the right number of voters"
|
"it should display the right number of voters"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.notOk(
|
assert.notOk(
|
||||||
queryAll(".poll-voters:first li:first a").attr("href"),
|
queryAll(".poll-voters:nth-of-type(1) li:nth-of-type(1) a").attr("href"),
|
||||||
"user URL does not exist"
|
"user URL does not exist"
|
||||||
);
|
);
|
||||||
|
|
||||||
await click(".poll-voters-toggle-expand:first a");
|
await click(".poll-voters-toggle-expand:nth-of-type(1) a");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-voters:first li").length,
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
||||||
30,
|
30,
|
||||||
"it should display the right number of voters"
|
"it should display the right number of voters"
|
||||||
);
|
);
|
||||||
|
|
|
@ -30,20 +30,20 @@ acceptance("Rendering polls with bar charts - mobile", function (needs) {
|
||||||
await click("button.toggle-results");
|
await click("button.toggle-results");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-voters:first li").length,
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
||||||
25,
|
25,
|
||||||
"it should display the right number of voters"
|
"it should display the right number of voters"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.notOk(
|
assert.notOk(
|
||||||
queryAll(".poll-voters:first li:first a").attr("href"),
|
queryAll(".poll-voters:nth-of-type(1) li:nth-of-type(1) a").attr("href"),
|
||||||
"user URL does not exist"
|
"user URL does not exist"
|
||||||
);
|
);
|
||||||
|
|
||||||
await click(".poll-voters-toggle-expand:first a");
|
await click(".poll-voters-toggle-expand:nth-of-type(1) a");
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".poll-voters:first li").length,
|
queryAll(".poll-voters:nth-of-type(1) li").length,
|
||||||
35,
|
35,
|
||||||
"it should display the right number of voters"
|
"it should display the right number of voters"
|
||||||
);
|
);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2494,12 +2494,7 @@ pretender@^1.6:
|
||||||
fake-xml-http-request "^1.6.0"
|
fake-xml-http-request "^1.6.0"
|
||||||
route-recognizer "^0.3.3"
|
route-recognizer "^0.3.3"
|
||||||
|
|
||||||
prettier@2.2.1:
|
prettier@2.2.1, prettier@^2.0.4:
|
||||||
version "2.2.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
|
|
||||||
integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==
|
|
||||||
|
|
||||||
prettier@^2.0.4:
|
|
||||||
version "2.2.1"
|
version "2.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
|
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
|
||||||
integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==
|
integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==
|
||||||
|
|
Loading…
Reference in New Issue