diff --git a/app/assets/javascripts/discourse/app/instance-initializers/banner.js b/app/assets/javascripts/discourse/app/instance-initializers/banner.js index 7b73db43a4c..b15e8097d03 100644 --- a/app/assets/javascripts/discourse/app/instance-initializers/banner.js +++ b/app/assets/javascripts/discourse/app/instance-initializers/banner.js @@ -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); + } }, }; diff --git a/app/assets/javascripts/discourse/tests/acceptance/banner-test.js b/app/assets/javascripts/discourse/tests/acceptance/banner-test.js new file mode 100644 index 00000000000..7b743a40a28 --- /dev/null +++ b/app/assets/javascripts/discourse/tests/acceptance/banner-test.js @@ -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(); + }); +});