Skip to content

Commit d4334cd

Browse files
committed
test: add directional border color tests
Add comprehensive test coverage for directional border colors: - 16 tests for border-{t|r|b|l} with preset colors, opacity, arbitrary values - 12 tests for border-x and border-y shortcuts - 7 tests for parseBorder color pattern detection - 7 integration tests for Babel transformation Total: 28 new tests across parser and Babel plugin.
1 parent 9e68777 commit d4334cd

File tree

3 files changed

+439
-0
lines changed

3 files changed

+439
-0
lines changed

src/babel/plugin/visitors/className.test.ts

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,3 +1178,135 @@ describe("className visitor - custom color scheme hook", () => {
11781178
expect(output).not.toContain("_twColorScheme = useTheme()");
11791179
});
11801180
});
1181+
1182+
describe("className visitor - directional border colors", () => {
1183+
it("should transform directional border colors with preset values", () => {
1184+
const input = `
1185+
import { View } from 'react-native';
1186+
export function Component() {
1187+
return <View className="border-t-red-500 border-l-blue-500" />;
1188+
}
1189+
`;
1190+
1191+
const output = transform(input, undefined, true);
1192+
1193+
// Should have StyleSheet
1194+
expect(output).toContain("StyleSheet.create");
1195+
1196+
// Should generate styles with borderTopColor and borderLeftColor
1197+
expect(output).toMatch(/borderTopColor[:\s]*['"]#[0-9A-F]{6}['"]/i);
1198+
expect(output).toMatch(/borderLeftColor[:\s]*['"]#[0-9A-F]{6}['"]/i);
1199+
1200+
// Should not have className in output
1201+
expect(output).not.toContain("className");
1202+
});
1203+
1204+
it("should combine directional border width and color", () => {
1205+
const input = `
1206+
import { View } from 'react-native';
1207+
export function Component() {
1208+
return <View className="border-l-2 border-l-red-500" />;
1209+
}
1210+
`;
1211+
1212+
const output = transform(input, undefined, true);
1213+
1214+
// Should have both borderLeftWidth and borderLeftColor in the StyleSheet
1215+
expect(output).toMatch(/borderLeftWidth[:\s]*2/);
1216+
expect(output).toMatch(/borderLeftColor[:\s]*['"]#[0-9A-F]{6}['"]/i);
1217+
1218+
// Should not have className in output
1219+
expect(output).not.toContain("className");
1220+
});
1221+
1222+
it("should support directional border colors with opacity", () => {
1223+
const input = `
1224+
import { View } from 'react-native';
1225+
export function Component() {
1226+
return <View className="border-t-red-500/50 border-b-blue-500/80" />;
1227+
}
1228+
`;
1229+
1230+
const output = transform(input, undefined, true);
1231+
1232+
// Should have 8-digit hex colors with alpha channel
1233+
expect(output).toMatch(/borderTopColor[:\s]*['"]#[0-9A-F]{8}['"]/i);
1234+
expect(output).toMatch(/borderBottomColor[:\s]*['"]#[0-9A-F]{8}['"]/i);
1235+
});
1236+
1237+
it("should support directional border colors with arbitrary hex values", () => {
1238+
const input = `
1239+
import { View } from 'react-native';
1240+
export function Component() {
1241+
return <View className="border-t-[#ff0000] border-r-[#abc]" />;
1242+
}
1243+
`;
1244+
1245+
const output = transform(input, undefined, true);
1246+
1247+
// Should have borderTopColor and borderRightColor
1248+
expect(output).toMatch(/borderTopColor[:\s]*['"]#[0-9a-fA-F]{6}['"]/);
1249+
expect(output).toMatch(/borderRightColor[:\s]*['"]#[0-9a-fA-F]{6}['"]/);
1250+
});
1251+
1252+
it("should support all four directional border colors", () => {
1253+
const input = `
1254+
import { View } from 'react-native';
1255+
export function Component() {
1256+
return (
1257+
<View className="border-t-red-500 border-r-blue-500 border-b-green-500 border-l-yellow-500" />
1258+
);
1259+
}
1260+
`;
1261+
1262+
const output = transform(input, undefined, true);
1263+
1264+
// Should have all four directional color properties
1265+
expect(output).toMatch(/borderTopColor[:\s]*['"]#[0-9A-F]{6}['"]/i);
1266+
expect(output).toMatch(/borderRightColor[:\s]*['"]#[0-9A-F]{6}['"]/i);
1267+
expect(output).toMatch(/borderBottomColor[:\s]*['"]#[0-9A-F]{6}['"]/i);
1268+
expect(output).toMatch(/borderLeftColor[:\s]*['"]#[0-9A-F]{6}['"]/i);
1269+
});
1270+
1271+
it("should combine directional widths, colors, and general border color", () => {
1272+
const input = `
1273+
import { View } from 'react-native';
1274+
export function Component() {
1275+
return (
1276+
<View className="border border-gray-300 border-l-4 border-l-blue-500" />
1277+
);
1278+
}
1279+
`;
1280+
1281+
const output = transform(input, undefined, true);
1282+
1283+
// Should have general border properties
1284+
expect(output).toMatch(/borderWidth[:\s]*1/);
1285+
expect(output).toMatch(/borderColor[:\s]*['"]#[0-9A-F]{6}['"]/i);
1286+
1287+
// Should have directional left border properties
1288+
expect(output).toMatch(/borderLeftWidth[:\s]*4/);
1289+
expect(output).toMatch(/borderLeftColor[:\s]*['"]#[0-9A-F]{6}['"]/i);
1290+
});
1291+
1292+
it("should work with dynamic className containing directional border colors", () => {
1293+
const input = `
1294+
import { View } from 'react-native';
1295+
export function Component({ isError }) {
1296+
return (
1297+
<View className={\`border-t-2 \${isError ? 'border-t-red-500' : 'border-t-gray-300'}\`} />
1298+
);
1299+
}
1300+
`;
1301+
1302+
const output = transform(input, undefined, true);
1303+
1304+
// Should have StyleSheet with both color options
1305+
expect(output).toContain("_border_t_2");
1306+
expect(output).toContain("_border_t_red_500");
1307+
expect(output).toContain("_border_t_gray_300");
1308+
1309+
// Should have conditional expression with both styles
1310+
expect(output).toMatch(/isError\s*\?\s*_twStyles\._border_t_red_500/);
1311+
});
1312+
});

src/parser/borders.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,61 @@ describe("parseBorder - comprehensive coverage", () => {
327327
});
328328
});
329329
});
330+
331+
describe("parseBorder - color pattern detection", () => {
332+
it("should return null for directional border colors with preset values", () => {
333+
// These should be handled by parseColor
334+
expect(parseBorder("border-t-red-500")).toBeNull();
335+
expect(parseBorder("border-r-blue-500")).toBeNull();
336+
expect(parseBorder("border-b-green-500")).toBeNull();
337+
expect(parseBorder("border-l-yellow-500")).toBeNull();
338+
});
339+
340+
it("should return null for directional border colors with basic values", () => {
341+
// These should be handled by parseColor
342+
expect(parseBorder("border-t-white")).toBeNull();
343+
expect(parseBorder("border-r-black")).toBeNull();
344+
expect(parseBorder("border-b-transparent")).toBeNull();
345+
expect(parseBorder("border-l-white")).toBeNull();
346+
});
347+
348+
it("should return null for directional border colors with arbitrary hex values", () => {
349+
// These should be handled by parseColor
350+
expect(parseBorder("border-t-[#ff0000]")).toBeNull();
351+
expect(parseBorder("border-r-[#3B82F6]")).toBeNull();
352+
expect(parseBorder("border-b-[#abc]")).toBeNull();
353+
expect(parseBorder("border-l-[#00FF00AA]")).toBeNull();
354+
});
355+
356+
it("should return null for directional border colors with opacity", () => {
357+
// These should be handled by parseColor
358+
expect(parseBorder("border-t-red-500/50")).toBeNull();
359+
expect(parseBorder("border-r-blue-500/80")).toBeNull();
360+
expect(parseBorder("border-b-[#ff0000]/60")).toBeNull();
361+
expect(parseBorder("border-l-black/25")).toBeNull();
362+
});
363+
364+
it("should return null for directional border colors with custom colors", () => {
365+
// These should be handled by parseColor (assuming brand-primary is a custom color)
366+
expect(parseBorder("border-t-brand-primary")).toBeNull();
367+
expect(parseBorder("border-r-accent")).toBeNull();
368+
expect(parseBorder("border-b-brand-secondary")).toBeNull();
369+
expect(parseBorder("border-l-custom")).toBeNull();
370+
});
371+
372+
it("should still handle directional border widths correctly", () => {
373+
// These should NOT be detected as color patterns
374+
expect(parseBorder("border-t-2")).toEqual({ borderTopWidth: 2 });
375+
expect(parseBorder("border-r-4")).toEqual({ borderRightWidth: 4 });
376+
expect(parseBorder("border-b-8")).toEqual({ borderBottomWidth: 8 });
377+
expect(parseBorder("border-l-0")).toEqual({ borderLeftWidth: 0 });
378+
});
379+
380+
it("should still handle directional border width arbitrary values", () => {
381+
// These should NOT be detected as color patterns
382+
expect(parseBorder("border-t-[3px]")).toEqual({ borderTopWidth: 3 });
383+
expect(parseBorder("border-r-[5px]")).toEqual({ borderRightWidth: 5 });
384+
expect(parseBorder("border-b-[10]")).toEqual({ borderBottomWidth: 10 });
385+
expect(parseBorder("border-l-[8px]")).toEqual({ borderLeftWidth: 8 });
386+
});
387+
});

0 commit comments

Comments
 (0)