Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

feat(cover-letter): add title builder helper

Khuram Niazd256bdf78f6c
diff --git a/__tests__/coverLetterTitle.spec.ts b/__tests__/coverLetterTitle.spec.ts
new file mode 100644
index 0000000..8b4feef
--- /dev/null
+++ b/__tests__/coverLetterTitle.spec.ts
@@ -0,0 +1,47 @@
+import { buildCoverLetterTitle } from "@/lib/coverLetterTitle";
+
+describe("buildCoverLetterTitle", () => {
+ it("joins job title and company", () => {
+ expect(buildCoverLetterTitle("Senior Engineer", "Acme", [])).toBe(
+ "Senior Engineer - Acme",
+ );
+ });
+
+ it("appends (2) when the base title is taken", () => {
+ expect(
+ buildCoverLetterTitle("Senior Engineer", "Acme", [
+ "Senior Engineer - Acme",
+ ]),
+ ).toBe("Senior Engineer - Acme (2)");
+ });
+
+ it("keeps counting past (2)", () => {
+ expect(
+ buildCoverLetterTitle("Senior Engineer", "Acme", [
+ "Senior Engineer - Acme",
+ "Senior Engineer - Acme (2)",
+ ]),
+ ).toBe("Senior Engineer - Acme (3)");
+ });
+
+ it("compares case-insensitively and ignores surrounding space", () => {
+ expect(
+ buildCoverLetterTitle("Senior Engineer", "Acme", [
+ " senior engineer - acme ",
+ ]),
+ ).toBe("Senior Engineer - Acme (2)");
+ });
+
+ it("trims to 100 characters", () => {
+ const long = "E".repeat(120);
+ const result = buildCoverLetterTitle(long, "Acme", []);
+ expect(result.length).toBeLessThanOrEqual(100);
+ expect(result.endsWith("- Acme")).toBe(true);
+ });
+
+ it("omits the company segment when there is no company", () => {
+ expect(buildCoverLetterTitle("Senior Engineer", "", [])).toBe(
+ "Senior Engineer",
+ );
+ });
+});
diff --git a/src/lib/coverLetterTitle.ts b/src/lib/coverLetterTitle.ts
new file mode 100644
index 0000000..f224f2d
--- /dev/null
+++ b/src/lib/coverLetterTitle.ts
@@ -0,0 +1,20 @@
+import { ensureUniqueTitle } from "@/lib/resumeCopyTitle";
+
+const MAX_TITLE_LENGTH = 100;
+
+// Reuses the resume-copy uniquifier: the " (2)" / " (3)" convention and the
+// 100-char fit are identical for both document types.
+export const buildCoverLetterTitle = (
+ jobTitle: string,
+ companyName: string,
+ takenTitles: string[],
+): string => {
+ const title = jobTitle.trim();
+ const company = companyName.trim();
+ // Trim the job title rather than the whole string so the company survives.
+ const room = MAX_TITLE_LENGTH - (company ? company.length + 3 : 0);
+ const base = company
+ ? `${title.slice(0, Math.max(room, 0)).trimEnd()} - ${company}`
+ : title.slice(0, MAX_TITLE_LENGTH);
+ return ensureUniqueTitle(base, takenTitles);
+};