mirror of
https://github.com/discourse/discourse.git
synced 2026-03-05 15:27:34 +08:00
This upgrade does not include any breaking changes for Discourse themes/plugins. Two of the three deprecations in Ember 6 (array prototype extensions, component-template resolution) have already been polyfilled in Discourse. The third (action helper/modifier) is polyfilled in this commit. Performance testing shows a 2-3% improvement in Discourse rendering time, thanks to upstream performance fixes in the glimmer-vm since the regressions in the Ember 5.x series. --------- Co-authored-by: David Taylor <david@taylorhq.com>
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
// eslint-disable-next-line ember/no-classic-components
|
|
import Component from "@ember/component";
|
|
import { action } from "@ember/object";
|
|
import { click, render } from "@ember/test-helpers";
|
|
import { hbs } from "ember-cli-htmlbars";
|
|
import { module, test } from "qunit";
|
|
import { withSilencedDeprecationsAsync } from "discourse/lib/deprecated";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
|
|
class FooString extends Component {
|
|
layout = hbs`<button {{on "click" (action "bar" 123)}}>test</button>`;
|
|
|
|
@action
|
|
bar(value) {
|
|
this.callback(value);
|
|
}
|
|
}
|
|
|
|
class FooReference extends Component {
|
|
layout = hbs`<button {{on "click" (action this.bar)}}>test</button>`;
|
|
|
|
@action
|
|
bar() {
|
|
this.callback();
|
|
}
|
|
}
|
|
|
|
// This is a core test but has to be in a theme since the transform
|
|
// (that injects `this` into actions' params) is applied only to
|
|
// themes and plugins
|
|
module("Integration | Helper | action", function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test("string argument", async function (assert) {
|
|
this.registry.register("component:foo", FooString);
|
|
this.callback = (value) => {
|
|
assert.step("called");
|
|
assert.strictEqual(value, 123);
|
|
};
|
|
|
|
await withSilencedDeprecationsAsync(
|
|
"discourse.template-action",
|
|
async () => {
|
|
await render(hbs`<Foo @callback={{this.callback}} />`);
|
|
}
|
|
);
|
|
|
|
await click("button");
|
|
assert.verifySteps(["called"]);
|
|
});
|
|
|
|
test("reference argument", async function (assert) {
|
|
this.registry.register("component:foo", FooReference);
|
|
this.callback = () => assert.step("called");
|
|
|
|
await withSilencedDeprecationsAsync(
|
|
"discourse.template-action",
|
|
async () => {
|
|
await render(hbs`<Foo @callback={{this.callback}} />`);
|
|
}
|
|
);
|
|
|
|
await click("button");
|
|
assert.verifySteps(["called"]);
|
|
});
|
|
});
|