Skip to content

Commit

Permalink
refactor: move root test file extractColors
Browse files Browse the repository at this point in the history
  • Loading branch information
tooooo1 committed Sep 22, 2023
1 parent f5e26ac commit 71c1f87
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { describe, expect, it } from "vitest";
import { extractColors } from "..";
import { extractColors } from ".";

describe("extractColors function", () => {
it("should return an array of colors", async () => {
const result = await extractColors("src/__test__/images/test.png", {
const result = await extractColors("src/images/test.png", {
quality: 10,
});
expect(result.length).toBeGreaterThan(0);
});

it("should return limited number of colors when colorCount is provided", async () => {
const colorCount = 5;
const result = await extractColors("src/__test__/images/test.png", {
const result = await extractColors("src/images/test.png", {
quality: 10,
colorCount,
});
Expand All @@ -20,21 +20,21 @@ describe("extractColors function", () => {

it("should throw an error if quality is out of range", async () => {
await expect(
extractColors("src/__test__/images/test.png", { quality: 101 }),
extractColors("src/images/test.png", { quality: 101 }),
).rejects.toThrow("Quality should be between 1 and 100");
await expect(
extractColors("src/__test__/images/test.png", { quality: 0 }),
extractColors("src/images/test.png", { quality: 0 }),
).rejects.toThrow("Quality should be between 1 and 100");
});

it("should filter out pixels with opacity less than 125", async () => {
const result = await extractColors("src/__test__/images/test.png");
const result = await extractColors("src/images/test.png");
const hasTransparentPixel = result.some(([, , , a]) => a < 125);
expect(hasTransparentPixel).toBe(false);
});

it("should filter out almost white pixels", async () => {
const result = await extractColors("src/__test__/images/test.png");
const result = await extractColors("src/images/test.png");
const hasWhitePixel = result.some(
([r, g, b]) => r > 250 && g > 250 && b > 250,
);
Expand Down

0 comments on commit 71c1f87

Please sign in to comment.