From fad8bbaeb1e558a4409b2948621b603f9ca544ed Mon Sep 17 00:00:00 2001 From: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Thu, 28 Aug 2025 23:17:44 +0200 Subject: [PATCH] test: add alert module tests for different `welcome_message` configurations (#3867) In this way, all options for `welcome_message` are tested. --- CHANGELOG.md | 1 + tests/configs/modules/alert/welcome_false.js | 18 +++++++ tests/configs/modules/alert/welcome_string.js | 18 +++++++ .../alert/{default.js => welcome_true.js} | 0 tests/e2e/modules/alert_spec.js | 51 ++++++++++++++++--- 5 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 tests/configs/modules/alert/welcome_false.js create mode 100644 tests/configs/modules/alert/welcome_string.js rename tests/configs/modules/alert/{default.js => welcome_true.js} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9da03d9c..f0916153 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ Thanks to: @dathbe. - Simplify DOM setup by removing unnecessary Promise/async patterns - Avoid potential port conflicts by using port 3001 for translator unit tests - Improve test reliability and maintainability +- [tests] add alert module tests for different welcome_message configurations (#3867) ### Updated diff --git a/tests/configs/modules/alert/welcome_false.js b/tests/configs/modules/alert/welcome_false.js new file mode 100644 index 00000000..1513904f --- /dev/null +++ b/tests/configs/modules/alert/welcome_false.js @@ -0,0 +1,18 @@ +let config = { + address: "0.0.0.0", + ipWhitelist: [], + modules: [ + { + module: "alert", + config: { + display_time: 1000000, + welcome_message: false + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") { + module.exports = config; +} diff --git a/tests/configs/modules/alert/welcome_string.js b/tests/configs/modules/alert/welcome_string.js new file mode 100644 index 00000000..6b7b690c --- /dev/null +++ b/tests/configs/modules/alert/welcome_string.js @@ -0,0 +1,18 @@ +let config = { + address: "0.0.0.0", + ipWhitelist: [], + modules: [ + { + module: "alert", + config: { + display_time: 1000000, + welcome_message: "Custom welcome message!" + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") { + module.exports = config; +} diff --git a/tests/configs/modules/alert/default.js b/tests/configs/modules/alert/welcome_true.js similarity index 100% rename from tests/configs/modules/alert/default.js rename to tests/configs/modules/alert/welcome_true.js diff --git a/tests/e2e/modules/alert_spec.js b/tests/e2e/modules/alert_spec.js index f3c95a6c..a8125b8a 100644 --- a/tests/e2e/modules/alert_spec.js +++ b/tests/e2e/modules/alert_spec.js @@ -1,17 +1,52 @@ const helpers = require("../helpers/global-setup"); describe("Alert module", () => { - beforeAll(async () => { - await helpers.startApplication("tests/configs/modules/alert/default.js"); - await helpers.getDocument(); - }); afterAll(async () => { await helpers.stopApplication(); }); - it("should show the welcome message", async () => { - const elem = await helpers.waitForElement(".ns-box .ns-box-inner .light.bright.small"); - expect(elem).not.toBeNull(); - expect(elem.textContent).toContain("Welcome, start was successful!"); + describe("with welcome_message set to false", () => { + beforeAll(async () => { + await helpers.startApplication("tests/configs/modules/alert/welcome_false.js"); + await helpers.getDocument(); + }); + + it("should not show any welcome message", async () => { + // Wait a bit to ensure no message appears + await new Promise((resolve) => setTimeout(resolve, 1000)); + + // Check that no alert/notification elements are present + const alertElements = document.querySelectorAll(".ns-box .ns-box-inner .light.bright.small"); + expect(alertElements).toHaveLength(0); + }); + }); + + describe("with welcome_message set to true", () => { + beforeAll(async () => { + await helpers.startApplication("tests/configs/modules/alert/welcome_true.js"); + await helpers.getDocument(); + + // Wait for the application to initialize + await new Promise((resolve) => setTimeout(resolve, 1000)); + }); + + it("should show the translated welcome message", async () => { + const elem = await helpers.waitForElement(".ns-box .ns-box-inner .light.bright.small"); + expect(elem).not.toBeNull(); + expect(elem.textContent).toContain("Welcome, start was successful!"); + }); + }); + + describe("with welcome_message set to custom string", () => { + beforeAll(async () => { + await helpers.startApplication("tests/configs/modules/alert/welcome_string.js"); + await helpers.getDocument(); + }); + + it("should show the custom welcome message", async () => { + const elem = await helpers.waitForElement(".ns-box .ns-box-inner .light.bright.small"); + expect(elem).not.toBeNull(); + expect(elem.textContent).toContain("Custom welcome message!"); + }); }); });