|
1 | | -import { extractDetailsFromCslp } from "../cslpdata"; |
| 1 | +import { extractDetailsFromCslp, isValidCslp } from "../cslpdata"; |
| 2 | + |
| 3 | +describe("isValidCslp", () => { |
| 4 | + describe("valid cases", () => { |
| 5 | + test("should return true for valid v1 format with 3 parts", () => { |
| 6 | + expect( |
| 7 | + isValidCslp("content_type_uid.entry_uid.locale") |
| 8 | + ).toBeTruthy(); |
| 9 | + }); |
| 10 | + |
| 11 | + test("should return true for valid v1 format with field path", () => { |
| 12 | + expect( |
| 13 | + isValidCslp("content_type_uid.entry_uid.locale.field_path") |
| 14 | + ).toBeTruthy(); |
| 15 | + }); |
| 16 | + |
| 17 | + test("should return true for valid v2 format with 3 parts", () => { |
| 18 | + expect( |
| 19 | + isValidCslp("v2:content_type_uid.entry_uid_variant_uid.locale") |
| 20 | + ).toBeTruthy(); |
| 21 | + }); |
| 22 | + |
| 23 | + test("should return true for valid v2 format with field path", () => { |
| 24 | + expect( |
| 25 | + isValidCslp( |
| 26 | + "v2:content_type_uid.entry_uid_variant_uid.locale.field_path" |
| 27 | + ) |
| 28 | + ).toBeTruthy(); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + describe("invalid cases", () => { |
| 33 | + test("should return false for null", () => { |
| 34 | + expect(isValidCslp(null)).toBeFalsy(); |
| 35 | + }); |
| 36 | + |
| 37 | + test("should return false for undefined", () => { |
| 38 | + expect(isValidCslp(undefined)).toBeFalsy(); |
| 39 | + }); |
| 40 | + |
| 41 | + test("should return false for empty string", () => { |
| 42 | + expect(isValidCslp("")).toBeFalsy(); |
| 43 | + }); |
| 44 | + |
| 45 | + test("should return false for string with less than 3 parts", () => { |
| 46 | + expect(isValidCslp("invalid")).toBeFalsy(); |
| 47 | + }); |
| 48 | + |
| 49 | + test("should return false for string with only 2 parts", () => { |
| 50 | + expect(isValidCslp("a.b")).toBeFalsy(); |
| 51 | + }); |
| 52 | + |
| 53 | + test("should return false for v2 prefix with no data", () => { |
| 54 | + expect(isValidCslp("v2:")).toBeFalsy(); |
| 55 | + }); |
| 56 | + |
| 57 | + test("should return false for v2 prefix with only 2 parts", () => { |
| 58 | + expect(isValidCslp("v2:a.b")).toBeFalsy(); |
| 59 | + }); |
| 60 | + |
| 61 | + test("should return false for v2 format where entry_uid_variant_uid has no underscore", () => { |
| 62 | + expect( |
| 63 | + isValidCslp("v2:content_type_uid.entry.locale") |
| 64 | + ).toBeFalsy(); |
| 65 | + }); |
| 66 | + |
| 67 | + test("should return false for v2 format where entry_uid_variant_uid is missing variant_uid", () => { |
| 68 | + expect( |
| 69 | + isValidCslp("v2:content_type_uid.entry_.locale") |
| 70 | + ).toBeFalsy(); |
| 71 | + }); |
| 72 | + |
| 73 | + test("should return false for v2 format where entry_uid_variant_uid is missing entry_uid", () => { |
| 74 | + expect( |
| 75 | + isValidCslp("v2:content_type_uid._variant_uid.locale") |
| 76 | + ).toBeFalsy(); |
| 77 | + }); |
| 78 | + |
| 79 | + test("should return false for v2 format with empty parts", () => { |
| 80 | + expect(isValidCslp("v2:..locale")).toBeFalsy(); |
| 81 | + }); |
| 82 | + |
| 83 | + test("should return false for v2 format with empty content_type_uid", () => { |
| 84 | + expect(isValidCslp("v2:.entry_uid_variant_uid.locale")).toBeFalsy(); |
| 85 | + }); |
| 86 | + |
| 87 | + test("should return false for v2 format with empty locale", () => { |
| 88 | + expect( |
| 89 | + isValidCslp("v2:content_type_uid.entry_uid_variant_uid.") |
| 90 | + ).toBeFalsy(); |
| 91 | + }); |
| 92 | + |
| 93 | + test("should return false for v1 format with empty parts", () => { |
| 94 | + expect(isValidCslp("..locale")).toBeFalsy(); |
| 95 | + }); |
| 96 | + |
| 97 | + test("should return false for v1 format with empty content_type_uid", () => { |
| 98 | + expect(isValidCslp(".entry_uid.locale")).toBeFalsy(); |
| 99 | + }); |
| 100 | + |
| 101 | + test("should return false for v1 format with empty entry_uid", () => { |
| 102 | + expect(isValidCslp("content_type_uid..locale")).toBeFalsy(); |
| 103 | + }); |
| 104 | + |
| 105 | + test("should return false for whitespace-only string", () => { |
| 106 | + expect(isValidCslp(" ")).toBeFalsy(); |
| 107 | + }); |
| 108 | + |
| 109 | + test("should return false for tab and newline whitespace", () => { |
| 110 | + expect(isValidCslp("\t\n")).toBeFalsy(); |
| 111 | + }); |
| 112 | + |
| 113 | + test("should return false for string with only dots", () => { |
| 114 | + expect(isValidCslp("...")).toBeFalsy(); |
| 115 | + }); |
| 116 | + |
| 117 | + test("should return false for string with only two dots", () => { |
| 118 | + expect(isValidCslp("..")).toBeFalsy(); |
| 119 | + }); |
| 120 | + }); |
| 121 | +}); |
2 | 122 |
|
3 | 123 | describe("extractDetailsFromCslp", () => { |
4 | 124 | test("should extract details from a CSLP value string with nested multiple field", () => { |
|
0 commit comments