FIX: banners not removing when unset (#22678)

Initializing an EmberObject with a null object leads to an exception. This commit stops that from happening, and introduces an acceptance test for adding/removing banner topics via message-bus.

Co-authored-by: David Taylor <david@taylorhq.com>
This commit is contained in:
Sam 2023-07-19 20:57:52 +10:00 committed by GitHub
parent 125903f682
commit e5bb4bbd59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View File

@ -20,7 +20,11 @@ export default {
},
@bind
onMessage(data = {}) {
this.site.set("banner", EmberObject.create(data));
onMessage(data) {
if (data) {
this.site.set("banner", EmberObject.create(data));
} else {
this.site.set("banner", null);
}
},
};

View File

@ -0,0 +1,26 @@
import {
acceptance,
publishToMessageBus,
} from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { visit } from "@ember/test-helpers";
acceptance("Site Banner", function () {
test("shows and hides correctly", async function (assert) {
await visit("/");
assert.dom("#banner").doesNotExist();
await publishToMessageBus("/site/banner", {
html: "hello world",
key: 12,
url: "/t/12",
});
assert.dom("#banner #banner-content").hasText("hello world");
await publishToMessageBus("/site/banner", null);
assert.dom("#banner").doesNotExist();
});
});