| 1 | import { describe, expect, test, vi } from "vitest"; |
| 2 | import { DiffLine } from ".."; |
| 3 | import { isNextEditTest, isWhitespaceOnlyDeletion } from "./utils"; |
| 4 | |
| 5 | describe("isNextEditTest", () => { |
| 6 | test("returns true when NEXT_EDIT_TEST_ENABLED is 'true'", () => { |
| 7 | vi.stubEnv("NEXT_EDIT_TEST_ENABLED", "true"); |
| 8 | expect(isNextEditTest()).toBe(true); |
| 9 | }); |
| 10 | |
| 11 | test("returns false when NEXT_EDIT_TEST_ENABLED is 'false'", () => { |
| 12 | vi.stubEnv("NEXT_EDIT_TEST_ENABLED", "false"); |
| 13 | expect(isNextEditTest()).toBe(false); |
| 14 | }); |
| 15 | |
| 16 | test("returns false when NEXT_EDIT_TEST_ENABLED is undefined", () => { |
| 17 | vi.stubEnv("NEXT_EDIT_TEST_ENABLED", undefined); |
| 18 | expect(isNextEditTest()).toBe(false); |
| 19 | }); |
| 20 | }); |
| 21 | |
| 22 | describe("isWhitespaceOnlyDeletion", () => { |
| 23 | test("returns true for whitespace-only deletions", () => { |
| 24 | const diffLines: DiffLine[] = [ |
| 25 | { type: "old", line: " " }, |
| 26 | { type: "old", line: "\t" }, |
| 27 | ]; |
| 28 | expect(isWhitespaceOnlyDeletion(diffLines)).toBe(true); |
| 29 | }); |
| 30 | |
| 31 | test("returns false for non-whitespace deletions", () => { |
| 32 | const diffLines: DiffLine[] = [ |
| 33 | { type: "old", line: "code" }, |
| 34 | { type: "old", line: " " }, |
| 35 | ]; |
| 36 | expect(isWhitespaceOnlyDeletion(diffLines)).toBe(false); |
| 37 | }); |
| 38 | |
| 39 | test("returns false for mixed content", () => { |
| 40 | const diffLines: DiffLine[] = [ |
| 41 | { type: "old", line: " " }, |
| 42 | { type: "old", line: "code" }, |
| 43 | ]; |
| 44 | expect(isWhitespaceOnlyDeletion(diffLines)).toBe(false); |
| 45 | }); |
| 46 | |
| 47 | test("returns false for mixed type", () => { |
| 48 | const diffLines: DiffLine[] = [ |
| 49 | { type: "old", line: " " }, |
| 50 | { type: "new", line: "" }, |
| 51 | ]; |
| 52 | expect(isWhitespaceOnlyDeletion(diffLines)).toBe(false); |
| 53 | }); |
| 54 | |
| 55 | test("returns true for empty array", () => { |
| 56 | const diffLines: DiffLine[] = []; |
| 57 | expect(isWhitespaceOnlyDeletion(diffLines)).toBe(true); |
| 58 | }); |
| 59 | }); |