diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ee045bd..26a6b268 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ Lines marked **Upgrade step** need you to act after updating. ## [Unreleased] +### Changed + +- In the form editor, the Preview button is white while the side preview is open, so you can see the preview is on. (#301) + ### Fixed - Clicking "Log in" on the two-factor code screen now sends the code. Before, only Enter worked. (#299) diff --git a/resources/js/components/Factory/Preview/PreviewToggle.test.ts b/resources/js/components/Factory/Preview/PreviewToggle.test.ts new file mode 100644 index 00000000..a24b323f --- /dev/null +++ b/resources/js/components/Factory/Preview/PreviewToggle.test.ts @@ -0,0 +1,37 @@ +import { mount } from "@vue/test-utils"; +import { describe, expect, it } from "vitest"; +import PreviewToggle from "./PreviewToggle.vue"; + +const mountToggle = (open: boolean) => + mount(PreviewToggle, { + props: { modelValue: open, "onUpdate:modelValue": () => {} }, + }); + +describe("preview toggle", () => { + it("is a light, pressed button while the preview is open", () => { + const button = mountToggle(true).get("button"); + + expect(button.attributes("aria-pressed")).toBe("true"); + expect(button.classes()).toEqual( + expect.arrayContaining(["bg-white", "text-grey-900", "hover:bg-grey-100"]), + ); + expect(button.classes()).not.toContain("text-white"); + }); + + it("stays dark with a thin border while it is closed", () => { + const button = mountToggle(false).get("button"); + + expect(button.attributes("aria-pressed")).toBe("false"); + expect(button.classes()).toEqual( + expect.arrayContaining(["border-grey-600", "text-white", "hover:bg-grey-700"]), + ); + expect(button.classes()).not.toContain("bg-white"); + }); + + it("flips the state on click", async () => { + const wrapper = mount(PreviewToggle, { props: { modelValue: false } }); + await wrapper.get("button").trigger("click"); + + expect(wrapper.emitted("update:modelValue")).toEqual([[true]]); + }); +}); diff --git a/resources/js/components/Factory/Preview/PreviewToggle.vue b/resources/js/components/Factory/Preview/PreviewToggle.vue index d71073c6..a34e28ea 100644 --- a/resources/js/components/Factory/Preview/PreviewToggle.vue +++ b/resources/js/components/Factory/Preview/PreviewToggle.vue @@ -3,8 +3,12 @@