|
| 1 | +import React from "react"; |
| 2 | +import { expect } from "@storybook/test"; |
| 3 | +import { render } from "@testing-library/react"; |
| 4 | + |
| 5 | +import "@testing-library/jest-dom"; |
| 6 | + |
| 7 | +import { ApplicationViewability, ApplicationViewabilityProps, CLASSPREFIX as eccgui } from "../../../index"; |
| 8 | + |
| 9 | +import { Default as ApplicationViewabilityStory } from "./../stories/ApplicationViewability.stories"; |
| 10 | + |
| 11 | +const applyViewabilityAndCheckClass = (props: Omit<ApplicationViewabilityProps, "children">) => { |
| 12 | + const { container } = render(<ApplicationViewability {...ApplicationViewabilityStory.args} {...props} />); |
| 13 | + const element = container.getElementsByClassName( |
| 14 | + props.hide ? `${eccgui}-application__hide--${props.hide}` : `${eccgui}-application__show--${props.show}` |
| 15 | + ); |
| 16 | + expect(element.length).toBe(1); |
| 17 | + return element; |
| 18 | +}; |
| 19 | + |
| 20 | +describe("ApplicationViewability", () => { |
| 21 | + it("should be visible on `show=screen`", () => { |
| 22 | + applyViewabilityAndCheckClass({ show: "screen" }); |
| 23 | + /** |
| 24 | + * Currently we cannot really test visibility via jest if it is defined by S/CSS rules because those styles are not known. |
| 25 | + * Looks like it is not too easy to include and test them. |
| 26 | + * So we only test for the correct CSS class. |
| 27 | + */ |
| 28 | + // console.log(window.getComputedStyle(element.item(0)??new Element).getPropertyValue("display")); |
| 29 | + // waitFor(() => expect(element).toBeVisible()); |
| 30 | + }); |
| 31 | + it("should not be visible on `hide=screen`", () => { |
| 32 | + applyViewabilityAndCheckClass({ hide: "screen" }); |
| 33 | + // waitFor(() => expect(element).not.toBeVisible()); |
| 34 | + }); |
| 35 | + it("should be visible on `hide=print`", () => { |
| 36 | + applyViewabilityAndCheckClass({ hide: "print" }); |
| 37 | + // waitFor(() => expect(element).toBeVisible()); |
| 38 | + }); |
| 39 | + it("should not be visible on `show=print`", () => { |
| 40 | + applyViewabilityAndCheckClass({ show: "print" }); |
| 41 | + // waitFor(() => expect(element).not.toBeVisible()); |
| 42 | + }); |
| 43 | +}); |
0 commit comments