diff --git a/src/components/ErrorPopup.test.ts b/src/components/ErrorPopup.test.ts new file mode 100644 index 0000000..7e2cd7a --- /dev/null +++ b/src/components/ErrorPopup.test.ts @@ -0,0 +1,37 @@ +import { describe, it, expect } from "vitest"; +import { mount } from "@vue/test-utils"; +import ErrorPopup from "./ErrorPopup.vue"; + +describe("ErrorPopup", () => { + it("renders nothing when show is false", () => { + const w = mount(ErrorPopup, { props: { show: false, message: "error" } }); + expect(w.find("[class*=fixed]").exists()).toBe(false); + }); + + it("renders nothing when message is null even if show is true", () => { + const w = mount(ErrorPopup, { props: { show: true, message: null } }); + expect(w.find("[class*=fixed]").exists()).toBe(false); + }); + + it("renders popup when show is true and message is set", () => { + const w = mount(ErrorPopup, { props: { show: true, message: "Verbindung fehlgeschlagen" } }); + expect(w.text()).toContain("Verbindung fehlgeschlagen"); + }); + + it("emits close when backdrop is clicked", async () => { + const w = mount(ErrorPopup, { props: { show: true, message: "err" } }); + await w.find(".absolute.inset-0").trigger("click"); + expect(w.emitted("close")).toHaveLength(1); + }); + + it("emits close when OK button is clicked", async () => { + const w = mount(ErrorPopup, { props: { show: true, message: "err" } }); + await w.find("button").trigger("click"); + expect(w.emitted("close")).toHaveLength(1); + }); + + it("displays Verbindungsfehler heading", () => { + const w = mount(ErrorPopup, { props: { show: true, message: "x" } }); + expect(w.text()).toContain("Verbindungsfehler"); + }); +}); diff --git a/src/components/ErrorPopup.vue b/src/components/ErrorPopup.vue new file mode 100644 index 0000000..7088eb8 --- /dev/null +++ b/src/components/ErrorPopup.vue @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + {{ title ?? "Verbindungsfehler" }} + + + + {{ message }} + + + + OK + + + + diff --git a/src/index.ts b/src/index.ts index ae144a9..1e84313 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,3 @@ export { default as LimelightButton } from './components/LimelightButton.vue' +export { default as ErrorPopup } from './components/ErrorPopup.vue' export * from './utils/webviewer'
{{ title ?? "Verbindungsfehler" }}
+ {{ message }} +