Skip to content

Commit 71cb5bb

Browse files
committed
test: add checkers pattern tests
1 parent d6be9ef commit 71cb5bb

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

tests/config.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
LINE_WIDTHS,
66
OFFSETS,
77
SPACING,
8+
SQUARE_SIZES,
89
} from "../src/consts";
910
import { css, expectCssToBe, generateTwCss } from "./utils";
1011

@@ -55,6 +56,31 @@ describe("dot sizes", () => {
5556
});
5657
});
5758

59+
describe("square sizes", () => {
60+
test(`square sizes ${SQUARE_SIZES[0]}-${SQUARE_SIZES[SQUARE_SIZES.length - 1]}`, async () => {
61+
const expected: string[] = [];
62+
const classes: string[] = [];
63+
for (const value of SQUARE_SIZES) {
64+
classes.push(`${DEFAULT_OPTS.prefix}pattern-square-${value}`);
65+
expected.push(
66+
css`.${DEFAULT_OPTS.prefix}pattern-square-${value} {
67+
--tw-square-size: ${value} /* px */
68+
}`,
69+
);
70+
}
71+
expectCssToBe(await generateTwCss(classes.join(" ")), expected.join(""));
72+
});
73+
74+
test("custom square size", async () => {
75+
expectCssToBe(
76+
await generateTwCss(`${DEFAULT_OPTS.prefix}pattern-square-[321]`),
77+
css`.${DEFAULT_OPTS.prefix}pattern-square-[321] {
78+
--tw-square-size: 321 /* px */
79+
}`,
80+
);
81+
});
82+
});
83+
5884
describe("spacing", () => {
5985
test(`spacing ${SPACING[0]}-${SPACING[SPACING.length - 1]}`, async () => {
6086
const expected: string[] = [];
@@ -174,3 +200,32 @@ describe("dot colors", () => {
174200
);
175201
});
176202
});
203+
204+
describe("square colors", () => {
205+
test("custom color", async () => {
206+
expectCssToBe(
207+
await generateTwCss(`${DEFAULT_OPTS.prefix}pattern-square-[#f8f8f8]`),
208+
css`.${DEFAULT_OPTS.prefix}pattern-square-[#f8f8f8] {
209+
--tw-square-color: #f8f8f8
210+
}`,
211+
);
212+
});
213+
214+
test("color with variant", async () => {
215+
expectCssToBe(
216+
await generateTwCss(`${DEFAULT_OPTS.prefix}pattern-square-red-300`),
217+
css`.${DEFAULT_OPTS.prefix}pattern-square-red-300 {
218+
--tw-square-color: #fca5a5
219+
}`,
220+
);
221+
});
222+
223+
test("color without variant", async () => {
224+
expectCssToBe(
225+
await generateTwCss(`${DEFAULT_OPTS.prefix}pattern-square-white`),
226+
css`.${DEFAULT_OPTS.prefix}pattern-square-white {
227+
--tw-square-color: #fff
228+
}`,
229+
);
230+
});
231+
});

tests/consts.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
LINE_WIDTHS,
66
OFFSETS,
77
SPACING,
8+
SQUARE_SIZES,
89
} from "../src/consts";
910

1011
describe("default production values", () => {
@@ -23,6 +24,10 @@ describe("default production values", () => {
2324
expect(DOT_SIZES).toEqual([...Array(96)].map((_, i) => i + 1));
2425
});
2526

27+
test("square sizes", () => {
28+
expect(SQUARE_SIZES).toEqual([...Array(96)].map((_, i) => i + 1));
29+
});
30+
2631
test("offsets", () => {
2732
expect(OFFSETS).toEqual([...Array(128 + 17)].map((_, i) => i));
2833
});

tests/patterns/checkers.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { test } from "vitest";
2+
import { DEFAULT_OPTS } from "../../src/consts";
3+
import { css, expectCssToBe, generateTwCss } from "../utils";
4+
5+
test("checkers pattern", async () => {
6+
expectCssToBe(
7+
await generateTwCss(`${DEFAULT_OPTS.prefix}pattern-checkers`),
8+
css`.${DEFAULT_OPTS.prefix}pattern-checkers {
9+
--tw-square-size: 32;
10+
--tw-offset-x: 0px;
11+
--tw-offset-y: 0px;
12+
--tw-square-color: #ffffff;
13+
--tw-unit: calc(var(--tw-square-size)* 1px);
14+
--tw-total-size: calc(var(--tw-unit)* 2);
15+
background-image: linear-gradient(45deg, var(--tw-square-color) 25%, transparent 25%), linear-gradient(-45deg, var(--tw-square-color) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--tw-square-color) 75%), linear-gradient(-45deg, transparent 75%, var(--tw-square-color) 75%);
16+
background-size: var(--tw-total-size) var(--tw-total-size);
17+
background-position: var(--tw-offset-x) var(--tw-offset-y), var(--tw-offset-x) calc(var(--tw-offset-y) + var(--tw-unit)), calc(var(--tw-offset-x) + var(--tw-unit)) calc(var(--tw-offset-y) - var(--tw-unit)), calc(var(--tw-offset-x) - var(--tw-unit)) var(--tw-offset-y)
18+
}`,
19+
);
20+
});

0 commit comments

Comments
 (0)