adding monkeytype
Some checks failed
Mark Stale PRs / stale (push) Has been cancelled

This commit is contained in:
Benjamin Falch
2026-04-23 13:53:44 +02:00
parent e214a2fd35
commit 2bc741fb78
1930 changed files with 7590652 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
{
"extends": "@monkeytype/typescript-config/base.json",
"compilerOptions": {
"noEmit": true
},
"include": ["./**/*.ts", "./**/*.spec.ts", "./setup-tests.ts"]
}

View File

@@ -0,0 +1,160 @@
import { describe, it, expect, beforeEach, vi } from "vitest";
import * as List from "../src/list";
import * as Validation from "../src/validation";
import { FunboxMetadata } from "../src/types";
describe("validation", () => {
describe("checkCompatibility", () => {
const getFunboxMock = vi.spyOn(List, "getFunbox");
beforeEach(() => {
getFunboxMock.mockClear();
});
it("should pass without funboxNames", () => {
//WHEN / THEN
expect(Validation.checkCompatibility([])).toBe(true);
});
it("should fail for undefined funboxNames", () => {
//GIVEN
getFunboxMock.mockReturnValueOnce([
{
name: "plus_one",
} as FunboxMetadata,
undefined as unknown as FunboxMetadata,
]);
//WHEN / THEN
expect(Validation.checkCompatibility(["plus_one", "plus_two"])).toBe(
false,
);
});
it("should fail for undefined withFunbox param", () => {
//GIVEN
getFunboxMock
.mockReturnValueOnce([])
.mockReturnValue([undefined as unknown as FunboxMetadata]);
//WHEN / THEN
expect(
Validation.checkCompatibility(["plus_one", "plus_two"], "plus_three"),
).toBe(false);
});
it("should check for optional withFunbox param ", () => {
//GIVEN
getFunboxMock
.mockReturnValueOnce([
{
name: "plus_one",
cssModifications: ["body", "main"],
} as FunboxMetadata,
{
name: "plus_two",
} as FunboxMetadata,
])
.mockReturnValueOnce([
{
name: "plus_three",
cssModifications: ["main", "typingTest"],
} as FunboxMetadata,
]);
//WHEN
const result = Validation.checkCompatibility(
["plus_one", "plus_two"],
"plus_three",
);
//THEN
expect(result).toBe(false);
expect(getFunboxMock).toHaveBeenNthCalledWith(1, [
"plus_one",
"plus_two",
]);
expect(getFunboxMock).toHaveBeenNthCalledWith(2, "plus_three");
});
it("should reject two funboxes modifying the same css element", () => {
//GIVEN
getFunboxMock.mockReturnValueOnce([
{
name: "plus_one",
cssModifications: ["body", "main"],
} as FunboxMetadata,
{
name: "plus_two",
cssModifications: ["main", "typingTest"],
} as FunboxMetadata,
]);
//WHEN / THEN
expect(Validation.checkCompatibility(["plus_one", "plus_two"])).toBe(
false,
);
});
it("should allow two funboxes modifying different css elements", () => {
//GIVEN
getFunboxMock.mockReturnValueOnce([
{
name: "plus_one",
cssModifications: ["body", "main"],
} as FunboxMetadata,
{
name: "plus_two",
cssModifications: ["words"],
} as FunboxMetadata,
]);
//WHEN / THEN
expect(Validation.checkCompatibility(["plus_one", "plus_two"])).toBe(
true,
);
});
describe("should validate two funboxes modifying the wordset", () => {
const testCases = [
{
firstFunction: "withWords",
secondFunction: "withWords",
compatible: false,
},
{
firstFunction: "withWords",
secondFunction: "getWord",
compatible: false,
},
{
firstFunction: "getWord",
secondFunction: "pullSection",
compatible: false,
},
];
it.for(testCases)(
`expect $firstFunction and $secondFunction to be compatible $compatible`,
({ firstFunction, secondFunction, compatible }) => {
//GIVEN
getFunboxMock.mockReturnValueOnce([
{
name: "plus_one",
frontendFunctions: [firstFunction],
} as FunboxMetadata,
{
name: "plus_two",
frontendFunctions: [secondFunction],
} as FunboxMetadata,
]);
//WHEN / THEN
expect(Validation.checkCompatibility(["plus_one", "plus_two"])).toBe(
compatible,
);
},
);
});
});
});