mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Rendering playlist icon collage of 3x3 (#35)
This commit is contained in:
35
tests/utils.test.ts
Normal file
35
tests/utils.test.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { takeWithRepeats } from "../src/utils";
|
||||
|
||||
describe("takeWithRepeat", () => {
|
||||
describe("when there is nothing in the input", () => {
|
||||
it("should return an array of undefineds", () => {
|
||||
expect(takeWithRepeats([], 3)).toEqual([undefined, undefined, undefined]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there are exactly the amount required", () => {
|
||||
it("should return them all", () => {
|
||||
expect(takeWithRepeats(["a", undefined, "c"], 3)).toEqual([
|
||||
"a",
|
||||
undefined,
|
||||
"c",
|
||||
]);
|
||||
expect(takeWithRepeats(["a"], 1)).toEqual(["a"]);
|
||||
expect(takeWithRepeats([undefined], 1)).toEqual([undefined]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there are less than the amount required", () => {
|
||||
it("should cycle through the ones available", () => {
|
||||
expect(takeWithRepeats(["a", "b"], 3)).toEqual(["a", "b", "a"]);
|
||||
expect(takeWithRepeats(["a", "b"], 5)).toEqual(["a", "b", "a", "b", "a"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there more than the amount required", () => {
|
||||
it("should return the first n items", () => {
|
||||
expect(takeWithRepeats(["a", "b", "c"], 2)).toEqual(["a", "b"]);
|
||||
expect(takeWithRepeats(["a", undefined, "c"], 2)).toEqual(["a", undefined]);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user