Skip to content

Commit c0eeff1

Browse files
committed
Added more Fixed and ViewPort tests
1 parent 4ade646 commit c0eeff1

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as React from "react";
2+
import { render, cleanup } from "@testing-library/react";
3+
import { Fixed } from "../Fixed";
4+
import "@testing-library/jest-dom/extend-expect";
5+
6+
afterEach(cleanup);
7+
8+
test("Fixed default has correct styles", async () => {
9+
const { container } = render(<Fixed id="test" height={10} />);
10+
const sut = container.querySelector("#test");
11+
const style = window.getComputedStyle(sut!);
12+
13+
expect(style.display).toBe("block");
14+
expect(style.position).toBe("relative");
15+
expect(style.left).toBe("");
16+
expect(style.top).toBe("");
17+
expect(style.right).toBe("");
18+
expect(style.bottom).toBe("");
19+
expect(style.width).toBe("");
20+
expect(style.height).toBe("10px");
21+
});
22+
23+
test("Fixed with width and height has correct styles", async () => {
24+
const { container } = render(<Fixed id="test" width={10} height={20} />);
25+
const sut = container.querySelector("#test");
26+
const style = window.getComputedStyle(sut!);
27+
28+
expect(style.left).toBe("");
29+
expect(style.top).toBe("");
30+
expect(style.right).toBe("");
31+
expect(style.bottom).toBe("");
32+
expect(style.width).toBe("10px");
33+
expect(style.height).toBe("20px");
34+
});
35+
36+
test("Fixed with class applied", async () => {
37+
const { container } = render(<Fixed id="test" height={20} className={"custom-class"} />);
38+
const sut = container.querySelector("#test");
39+
40+
expect(sut!.className).toBe("spaces-space custom-class");
41+
});
42+
43+
test("Fixed with style applied", async () => {
44+
const { container } = render(<Fixed id="test" height={20} style={{ backgroundColor: "red" }} />);
45+
const sut = container.querySelector("#test");
46+
const style = window.getComputedStyle(sut!);
47+
48+
expect(style.backgroundColor).toBe("red");
49+
});
50+
51+
test("Fixed scrollable applied", async () => {
52+
const { container } = render(<Fixed id="test" height={20} scrollable={true} />);
53+
const sut = container.querySelector("#test");
54+
const style = window.getComputedStyle(sut!);
55+
56+
expect(style.overflow).toBe("auto");
57+
});

src/components/__tests__/ViewPort.test.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,25 @@ test("ViewPort with offsets has correct styles", async () => {
3131
expect(style.bottom).toBe("40px");
3232
});
3333

34-
test("ViewPort with class has correct class", async () => {
34+
test("ViewPort with class applied", async () => {
3535
const { container } = render(<ViewPort id="test" className={"custom-class"} />);
3636
const sut = container.querySelector("#test");
3737

3838
expect(sut!.className).toBe("spaces-space custom-class");
3939
});
40+
41+
test("ViewPort with style applied", async () => {
42+
const { container } = render(<ViewPort id="test" style={{ backgroundColor: "red" }} />);
43+
const sut = container.querySelector("#test");
44+
const style = window.getComputedStyle(sut!);
45+
46+
expect(style.backgroundColor).toBe("red");
47+
});
48+
49+
test("ViewPort scrollable applied", async () => {
50+
const { container } = render(<ViewPort id="test" scrollable={true} />);
51+
const sut = container.querySelector("#test");
52+
const style = window.getComputedStyle(sut!);
53+
54+
expect(style.overflow).toBe("auto");
55+
});

0 commit comments

Comments
 (0)