|
| 1 | +import { extractSheetNameFromA1Notation } from "@/appsscript"; |
| 2 | +import { EmptyStringException } from "@/exception"; |
| 3 | +import { describe, expect, it } from "vitest"; |
| 4 | + |
| 5 | +describe("extractSheetNameFromA1Notation", () => { |
| 6 | + describe("Sheet Name Extraction (Success Cases)", () => { |
| 7 | + it("should correctly extract the sheet name from a standard range (unquoted)", () => { |
| 8 | + expect(extractSheetNameFromA1Notation("Sheet1!A1:B2")).toBe("Sheet1"); |
| 9 | + }); |
| 10 | + |
| 11 | + it("should correctly extract the sheet name from a quoted range with spaces", () => { |
| 12 | + expect(extractSheetNameFromA1Notation("'My Data Sheet'!A1")).toBe( |
| 13 | + "My Data Sheet" |
| 14 | + ); |
| 15 | + }); |
| 16 | + |
| 17 | + it("should correctly extract the sheet name from a column-only reference", () => { |
| 18 | + expect(extractSheetNameFromA1Notation("Data!C:C")).toBe("Data"); |
| 19 | + }); |
| 20 | + }); |
| 21 | + |
| 22 | + describe("Handling Missing Sheet Name (Returning null)", () => { |
| 23 | + it("should return null when the A1 notation does not contain a sheet name (standard range)", () => { |
| 24 | + expect(extractSheetNameFromA1Notation("A1:B2")).toBeNull(); |
| 25 | + }); |
| 26 | + |
| 27 | + it("should return null when only a column/row range is provided", () => { |
| 28 | + expect(extractSheetNameFromA1Notation("A:A")).toBeNull(); |
| 29 | + }); |
| 30 | + |
| 31 | + it("should return null for an empty string input", () => { |
| 32 | + expect(() => extractSheetNameFromA1Notation("")).toThrow( |
| 33 | + EmptyStringException |
| 34 | + ); |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + describe("Handling Invalid Data (Throwing Errors)", () => { |
| 39 | + it("should throw an Error if the extracted sheet name is considered invalid", () => { |
| 40 | + expect(() => extractSheetNameFromA1Notation("Invalid/Name!A1")).toThrow(); |
| 41 | + }); |
| 42 | + |
| 43 | + it("should throw an Error on malformed A1 notation that parseA1Notation cannot handle", () => { |
| 44 | + expect(() => extractSheetNameFromA1Notation("Sheet1!A1:B2!")).toThrow(); |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + describe("Contract Validation (IllegalArgumentException)", () => { |
| 49 | + it("should throw IllegalArgumentException when called with no arguments", () => { |
| 50 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 51 | + expect(() => (extractSheetNameFromA1Notation as any)()).toThrow(); |
| 52 | + }); |
| 53 | + }); |
| 54 | +}); |
0 commit comments