Skip to content

Commit

Permalink
Streamline tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeyer2115 committed Sep 21, 2023
1 parent 258a98f commit 5445ad4
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions packages/studio-ui/tests/components/OpenLivePreviewButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ import mockActivePage from "../__utils__/mockActivePage";
import { PageState, PropValueKind } from "@yext/studio-plugin";
import mockStore from "../__utils__/mockStore";

const ensureButtonAppearance = (
button: HTMLElement,
shouldBeEnabled: boolean
) => {
expect(button).toBeDefined();
expect(button.textContent).toBe("Live Preview");
shouldBeEnabled
? expect(button).toBeEnabled()
: expect(button).toBeDisabled();
};

describe("button is disabled properly", () => {
it("disables the button when not a PagesJS page", () => {
const pageState: PageState = {
Expand All @@ -17,9 +28,7 @@ describe("button is disabled properly", () => {

render(<OpenLivePreviewButton />);
const button = screen.getByRole("button");
expect(button).toBeDefined();
expect(button.textContent).toBe("Live Preview");
expect(button).toBeDisabled();
ensureButtonAppearance(button, false);
});

it("disables the button for Static page without a valid GetPathVal", () => {
Expand All @@ -35,9 +44,7 @@ describe("button is disabled properly", () => {

render(<OpenLivePreviewButton />);
const button = screen.getByRole("button");
expect(button).toBeDefined();
expect(button.textContent).toBe("Live Preview");
expect(button).toBeDisabled();
ensureButtonAppearance(button, false);
});

it("when an Entity's localData doesn't contain an id, the button is disabled", () => {
Expand Down Expand Up @@ -67,9 +74,7 @@ describe("button is disabled properly", () => {

render(<OpenLivePreviewButton />);
const button = screen.getByRole("button");
expect(button).toBeDefined();
expect(button.textContent).toBe("Live Preview");
expect(button).toBeDisabled();
ensureButtonAppearance(button, false);
});
});

Expand All @@ -92,7 +97,7 @@ describe("button links to correct preview url", () => {

render(<OpenLivePreviewButton />);
const button = screen.getByRole("button");
expect(button).toBeEnabled();
ensureButtonAppearance(button, true);
button.click();
expect(window.open).toBeCalledWith(
`${PAGES_JS_LANDING_PAGE}/static-page`,
Expand Down Expand Up @@ -127,7 +132,7 @@ describe("button links to correct preview url", () => {

render(<OpenLivePreviewButton />);
const button = screen.getByRole("button");
expect(button).toBeEnabled();
ensureButtonAppearance(button, true);
button.click();
expect(window.open).toBeCalledWith(
`${PAGES_JS_LANDING_PAGE}/testpage/123`,
Expand Down

0 comments on commit 5445ad4

Please sign in to comment.