|
| 1 | +import { describe, it } from "mocha"; |
| 2 | +import { expect, browser } from "@wdio/globals"; |
| 3 | + |
| 4 | +describe("Red Box", () => { |
| 5 | + const redBox = () => $("#aspect-ratio-helper"); |
| 6 | + const redBoxButton = () => $("#turn-off-red-box"); |
| 7 | + |
| 8 | + beforeEach(async () => { |
| 9 | + await browser.url("/hello-world.html"); |
| 10 | + await browser.execute(() => sessionStorage.clear()); |
| 11 | + // Clear any lingering state (like inline styles) from previous |
| 12 | + // tests. Reading https://webdriver.io/docs/api/browser/url, |
| 13 | + // this should not be necessary, but tests fail without it. |
| 14 | + await browser.refresh(); |
| 15 | + }); |
| 16 | + |
| 17 | + it("should be hidden by default", async () => { |
| 18 | + await expect(redBox()).not.toBeDisplayed(); |
| 19 | + }); |
| 20 | + |
| 21 | + describe("Keyboard Shortcut", () => { |
| 22 | + it("should show the red box when toggled on", async () => { |
| 23 | + await browser.toggleRedBox(); |
| 24 | + await expect(redBox()).toBeDisplayed(); |
| 25 | + await expect(redBoxButton()).toBeDisplayed(); |
| 26 | + }); |
| 27 | + |
| 28 | + it("should hide the red box when toggled off", async () => { |
| 29 | + // Toggle on first |
| 30 | + await browser.toggleRedBox(); |
| 31 | + await expect(redBox()).toBeDisplayed(); |
| 32 | + |
| 33 | + // Then toggle off |
| 34 | + await browser.toggleRedBox(); |
| 35 | + await expect(redBox()).not.toBeDisplayed(); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + describe("URL Parameter", () => { |
| 40 | + it("should show red box", async () => { |
| 41 | + await browser.url("/hello-world.html?show-red-box=true"); |
| 42 | + await expect(redBox()).toBeDisplayed(); |
| 43 | + }); |
| 44 | + |
| 45 | + it("should override session storage", async () => { |
| 46 | + // Set session storage first to ensure the URL parameter takes precedence. |
| 47 | + await browser.execute(() => sessionStorage.setItem("showRedBox", "true")); |
| 48 | + await browser.url("/hello-world.html?show-red-box=false"); |
| 49 | + await expect(redBox()).not.toBeDisplayed(); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + describe("Hide Button", () => { |
| 54 | + it("should hide the red box when clicked", async () => { |
| 55 | + await browser.toggleRedBox(); |
| 56 | + await expect(redBox()).toBeDisplayed(); |
| 57 | + |
| 58 | + await (await redBoxButton()).click(); |
| 59 | + await expect(redBox()).not.toBeDisplayed(); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + describe("Session Storage", () => { |
| 64 | + it("should persist being shown after a reload", async () => { |
| 65 | + await browser.toggleRedBox(); |
| 66 | + await expect(redBox()).toBeDisplayed(); |
| 67 | + |
| 68 | + await browser.refresh(); |
| 69 | + |
| 70 | + await expect(redBox()).toBeDisplayed(); |
| 71 | + }); |
| 72 | + |
| 73 | + it("should persist being hidden after a reload", async () => { |
| 74 | + await browser.toggleRedBox(); // turn on |
| 75 | + await browser.toggleRedBox(); // turn off |
| 76 | + await expect(redBox()).not.toBeDisplayed(); |
| 77 | + |
| 78 | + // Explicitly check that storage is cleared before reloading |
| 79 | + const storage = await browser.execute(() => |
| 80 | + sessionStorage.getItem("showRedBox"), |
| 81 | + ); |
| 82 | + expect(storage).toBeNull(); |
| 83 | + |
| 84 | + await browser.refresh(); |
| 85 | + await expect(redBox()).not.toBeDisplayed(); |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
| 89 | + describe("Interactions", () => { |
| 90 | + it("should be able to be hidden with the keyboard after being shown with the URL", async () => { |
| 91 | + await browser.url("/hello-world.html?show-red-box=true"); |
| 92 | + await expect(redBox()).toBeDisplayed(); |
| 93 | + |
| 94 | + await browser.toggleRedBox(); |
| 95 | + await expect(redBox()).not.toBeDisplayed(); |
| 96 | + }); |
| 97 | + }); |
| 98 | +}); |
0 commit comments