src/utils/name-generator.test.ts 4.2 K raw
1
import { describe, it, expect } from "bun:test";
2
import { nameGenerator } from "./name-generator";
3
4
describe("nameGenerator", () => {
5
	describe("nameGenerator function", () => {
6
		it("should return original basename for empty options", async () => {
7
			const result = nameGenerator("template.txt", {});
8
			expect(result).toBe("template.txt");
9
		});
10
11
		it("should return original basename when all options are false", async () => {
12
			const options = {
13
				rpc: false,
14
				shadcn: false,
15
				tailwind: false,
16
				tanstackQuery: false,
17
			};
18
			const result = nameGenerator("template.txt", options);
19
			expect(result).toBe("template.txt");
20
		});
21
22
		it("should return filename with '-with-' prefix when only one option is true", async () => {
23
			const options = {
24
				rpc: true,
25
				shadcn: false,
26
				tailwind: false,
27
				tanstackQuery: false,
28
			};
29
			const result = nameGenerator("template.txt", options);
30
			expect(result).toBe("template-with-rpc.txt");
31
		});
32
33
		it("should return multiple options with '-with-' prefix joined with dashes", async () => {
34
			const options = {
35
				rpc: true,
36
				shadcn: true,
37
				tailwind: false,
38
				tanstackQuery: false,
39
			};
40
			const result = nameGenerator("template.txt", options);
41
			expect(result).toBe("template-with-rpc-shadcn.txt");
42
		});
43
44
		it("should sort options alphabetically after '-with-' prefix", async () => {
45
			const options = {
46
				tailwind: true,
47
				rpc: true,
48
				shadcn: true,
49
				tanstackQuery: false,
50
			};
51
			const result = nameGenerator("template.txt", options);
52
			expect(result).toBe("template-with-rpc-shadcn-tailwind.txt");
53
		});
54
55
		it("should handle all options selected", async () => {
56
			const options = {
57
				tailwind: true,
58
				rpc: true,
59
				shadcn: true,
60
				tanstackQuery: true,
61
			};
62
			const result = nameGenerator("template.txt", options);
63
			expect(result).toBe(
64
				"template-with-rpc-shadcn-tailwind-tanstackquery.txt",
65
			);
66
		});
67
68
		it("should convert camelCase options to lowercase", async () => {
69
			const options = {
70
				tanstackQuery: true,
71
				rpc: false,
72
				shadcn: false,
73
				tailwind: false,
74
			};
75
			const result = nameGenerator("template.txt", options);
76
			expect(result).toBe("template-with-tanstackquery.txt");
77
		});
78
79
		it("should handle mixed selections with alphabetical sorting", async () => {
80
			const options = {
81
				tanstackQuery: true,
82
				tailwind: true,
83
				rpc: false,
84
				shadcn: false,
85
			};
86
			const result = nameGenerator("template.txt", options);
87
			expect(result).toBe("template-with-tailwind-tanstackquery.txt");
88
		});
89
90
		it("should handle different combinations maintaining alphabetical order", async () => {
91
			const options = {
92
				shadcn: true,
93
				tanstackQuery: true,
94
				rpc: false,
95
				tailwind: false,
96
			};
97
			const result = nameGenerator("template.txt", options);
98
			expect(result).toBe("template-with-shadcn-tanstackquery.txt");
99
		});
100
101
		it("should handle single tailwind option", async () => {
102
			const options = {
103
				rpc: false,
104
				shadcn: false,
105
				tailwind: true,
106
				tanstackQuery: false,
107
			};
108
			const result = nameGenerator("template.txt", options);
109
			expect(result).toBe("template-with-tailwind.txt");
110
		});
111
112
		it("should handle rpc and tanstackQuery combination", async () => {
113
			const options = {
114
				rpc: true,
115
				shadcn: false,
116
				tailwind: false,
117
				tanstackQuery: true,
118
			};
119
			const result = nameGenerator("template.txt", options);
120
			expect(result).toBe("template-with-rpc-tanstackquery.txt");
121
		});
122
123
		it("should handle different file extensions", async () => {
124
			const options = {
125
				rpc: true,
126
				shadcn: false,
127
				tailwind: false,
128
				tanstackQuery: false,
129
			};
130
			const result = nameGenerator("component.tsx", options);
131
			expect(result).toBe("component-with-rpc.tsx");
132
		});
133
134
		it("should handle files without extensions", async () => {
135
			const options = {
136
				tailwind: true,
137
				shadcn: false,
138
				rpc: false,
139
				tanstackQuery: false,
140
			};
141
			const result = nameGenerator("README", options);
142
			expect(result).toBe("README-with-tailwind");
143
		});
144
145
		it("should handle complex filenames", async () => {
146
			const options = {
147
				rpc: true,
148
				shadcn: true,
149
				tailwind: false,
150
				tanstackQuery: false,
151
			};
152
			const result = nameGenerator("my-app-config.json", options);
153
			expect(result).toBe("my-app-config-with-rpc-shadcn.json");
154
		});
155
	});
156
});