|
| 1 | +import * as React from "react"; |
| 2 | +import { render, cleanup } from "@testing-library/react"; |
| 3 | +import { Bottom } from "../Anchored"; |
| 4 | +import "@testing-library/jest-dom/extend-expect"; |
| 5 | +import { ViewPort } from "../ViewPort"; |
| 6 | + |
| 7 | +afterEach(cleanup); |
| 8 | + |
| 9 | +test("Bottom default has correct styles", async () => { |
| 10 | + const { container } = render( |
| 11 | + <ViewPort> |
| 12 | + <Bottom id="test" size={10} /> |
| 13 | + </ViewPort>, |
| 14 | + ); |
| 15 | + const sut = container.querySelector("#test")!; |
| 16 | + const style = window.getComputedStyle(sut); |
| 17 | + |
| 18 | + expect(style.display).toBe("block"); |
| 19 | + expect(style.position).toBe("absolute"); |
| 20 | + expect(style.left).toBe("0px"); |
| 21 | + expect(style.top).toBe(""); |
| 22 | + expect(style.right).toBe("0px"); |
| 23 | + expect(style.bottom).toBe("0px"); |
| 24 | + expect(style.width).toBe(""); |
| 25 | + expect(style.height).toBe("10px"); |
| 26 | + expect(sut.nodeName).toBe("DIV"); |
| 27 | +}); |
| 28 | + |
| 29 | +test("Bottom with class applied", async () => { |
| 30 | + const { container } = render( |
| 31 | + <ViewPort> |
| 32 | + <Bottom id="test" size={10} className={"custom-class"} /> |
| 33 | + </ViewPort>, |
| 34 | + ); |
| 35 | + const sut = container.querySelector("#test"); |
| 36 | + |
| 37 | + expect(sut!.className).toBe("spaces-space custom-class"); |
| 38 | +}); |
| 39 | + |
| 40 | +test("Bottom with style applied", async () => { |
| 41 | + const { container } = render( |
| 42 | + <ViewPort> |
| 43 | + <Bottom id="test" size={10} style={{ backgroundColor: "red" }} /> |
| 44 | + </ViewPort>, |
| 45 | + ); |
| 46 | + const sut = container.querySelector("#test"); |
| 47 | + const style = window.getComputedStyle(sut!); |
| 48 | + |
| 49 | + expect(style.backgroundColor).toBe("red"); |
| 50 | +}); |
| 51 | + |
| 52 | +test("Bottom scrollable applied", async () => { |
| 53 | + const { container } = render( |
| 54 | + <ViewPort> |
| 55 | + <Bottom id="test" size={10} scrollable={true} /> |
| 56 | + </ViewPort>, |
| 57 | + ); |
| 58 | + const sut = container.querySelector("#test"); |
| 59 | + const style = window.getComputedStyle(sut!); |
| 60 | + |
| 61 | + expect(style.overflow).toBe("auto"); |
| 62 | +}); |
| 63 | + |
| 64 | +test("Bottom as applied", async () => { |
| 65 | + const { container } = render( |
| 66 | + <ViewPort> |
| 67 | + <Bottom id="test" size={10} as="main" /> |
| 68 | + </ViewPort>, |
| 69 | + ); |
| 70 | + const sut = container.querySelector("#test")!; |
| 71 | + |
| 72 | + expect(sut.nodeName).toBe("MAIN"); |
| 73 | +}); |
| 74 | + |
| 75 | +test("Bottom stacked has correct styles", async () => { |
| 76 | + const { container } = render( |
| 77 | + <ViewPort> |
| 78 | + <Bottom id="test" size={10} order={0} /> |
| 79 | + <Bottom id="test1" size={10} order={1} /> |
| 80 | + </ViewPort>, |
| 81 | + ); |
| 82 | + const sut = container.querySelector("#test")!; |
| 83 | + const style = window.getComputedStyle(sut); |
| 84 | + |
| 85 | + expect(style.left).toBe("0px"); |
| 86 | + expect(style.top).toBe(""); |
| 87 | + expect(style.right).toBe("0px"); |
| 88 | + expect(style.bottom).toBe("0px"); |
| 89 | + expect(style.width).toBe(""); |
| 90 | + expect(style.height).toBe("10px"); |
| 91 | + |
| 92 | + const sut1 = container.querySelector("#test1")!; |
| 93 | + const style1 = window.getComputedStyle(sut1); |
| 94 | + |
| 95 | + expect(style1.left).toBe("0px"); |
| 96 | + expect(style1.top).toBe(""); |
| 97 | + expect(style1.right).toBe("0px"); |
| 98 | + expect(style1.bottom).toBe("calc(10px + 0px)"); |
| 99 | + expect(style1.width).toBe(""); |
| 100 | + expect(style1.height).toBe("10px"); |
| 101 | +}); |
| 102 | + |
| 103 | +test("Bottom stacked reversed has correct styles", async () => { |
| 104 | + const { container } = render( |
| 105 | + <ViewPort> |
| 106 | + <Bottom id="test1" size={10} order={1} /> |
| 107 | + <Bottom id="test" size={10} order={0} /> |
| 108 | + </ViewPort>, |
| 109 | + ); |
| 110 | + const sut = container.querySelector("#test")!; |
| 111 | + const style = window.getComputedStyle(sut); |
| 112 | + |
| 113 | + expect(style.left).toBe("0px"); |
| 114 | + expect(style.top).toBe(""); |
| 115 | + expect(style.right).toBe("0px"); |
| 116 | + expect(style.bottom).toBe("0px"); |
| 117 | + expect(style.width).toBe(""); |
| 118 | + expect(style.height).toBe("10px"); |
| 119 | + |
| 120 | + const sut1 = container.querySelector("#test1")!; |
| 121 | + const style1 = window.getComputedStyle(sut1); |
| 122 | + |
| 123 | + expect(style1.left).toBe("0px"); |
| 124 | + expect(style1.top).toBe(""); |
| 125 | + expect(style1.right).toBe("0px"); |
| 126 | + expect(style1.bottom).toBe("calc(10px + 0px)"); |
| 127 | + expect(style1.width).toBe(""); |
| 128 | + expect(style1.height).toBe("10px"); |
| 129 | +}); |
0 commit comments