Remove unnecessary props and data structure

This commit is contained in:
adilallo
2025-09-05 08:09:44 -06:00
parent fc096129dd
commit 93182e6c2d
8 changed files with 21 additions and 279 deletions
+11 -64
View File
@@ -28,17 +28,14 @@ const mockPost = {
"This is a test description for the blog post that should be long enough to test truncation.",
author: "Test Author",
date: "2025-04-15",
tags: ["test", "blog", "example"],
backgroundImages: ["/test-image-1.jpg", "/test-image-2.jpg"],
},
wordCount: 500,
readingTime: 3,
};
describe("ContentThumbnailTemplate", () => {
describe("Vertical Variant", () => {
it("should render vertical variant with correct dimensions", () => {
render(<ContentThumbnailTemplate post={mockPost} variant="vertical" />);
render(<ContentThumbnailTemplate post={mockPost} />);
const container = screen.getByRole("link");
expect(container).toBeInTheDocument();
@@ -49,7 +46,7 @@ describe("ContentThumbnailTemplate", () => {
});
it("should display post title and description", () => {
render(<ContentThumbnailTemplate post={mockPost} variant="vertical" />);
render(<ContentThumbnailTemplate post={mockPost} />);
expect(screen.getByText("Test Blog Post Title")).toBeInTheDocument();
expect(
@@ -58,57 +55,21 @@ describe("ContentThumbnailTemplate", () => {
});
it("should display tags when showTags is true", () => {
render(
<ContentThumbnailTemplate
post={mockPost}
variant="vertical"
showTags={true}
/>
);
render(<ContentThumbnailTemplate post={mockPost} showTags={true} />);
expect(screen.getByText("test")).toBeInTheDocument();
expect(screen.getByText("blog")).toBeInTheDocument();
});
it("should hide tags when showTags is false", () => {
render(
<ContentThumbnailTemplate
post={mockPost}
variant="vertical"
showTags={false}
/>
);
render(<ContentThumbnailTemplate post={mockPost} showTags={false} />);
expect(screen.queryByText("test")).not.toBeInTheDocument();
expect(screen.queryByText("blog")).not.toBeInTheDocument();
});
it("should display reading time when showReadingTime is true", () => {
render(
<ContentThumbnailTemplate
post={mockPost}
variant="vertical"
showReadingTime={true}
/>
);
expect(screen.getByText(/3 min read/)).toBeInTheDocument();
});
it("should hide reading time when showReadingTime is false", () => {
render(
<ContentThumbnailTemplate
post={mockPost}
variant="vertical"
showReadingTime={false}
/>
);
expect(screen.queryByText(/min read/)).not.toBeInTheDocument();
});
it("should display author and date", () => {
render(<ContentThumbnailTemplate post={mockPost} variant="vertical" />);
render(<ContentThumbnailTemplate post={mockPost} />);
expect(screen.getByText("Test Author")).toBeInTheDocument();
// Check for "Month Year" format (e.g., "April 2025")
@@ -118,7 +79,7 @@ describe("ContentThumbnailTemplate", () => {
describe("Horizontal Variant", () => {
it("should render horizontal variant", () => {
render(<ContentThumbnailTemplate post={mockPost} variant="horizontal" />);
render(<ContentThumbnailTemplate post={mockPost} />);
const container = screen.getByRole("link");
expect(container).toBeInTheDocument();
@@ -129,7 +90,7 @@ describe("ContentThumbnailTemplate", () => {
});
it("should display post information in horizontal layout", () => {
render(<ContentThumbnailTemplate post={mockPost} variant="horizontal" />);
render(<ContentThumbnailTemplate post={mockPost} />);
expect(screen.getByText("Test Blog Post Title")).toBeInTheDocument();
expect(
@@ -142,11 +103,7 @@ describe("ContentThumbnailTemplate", () => {
describe("Props and Customization", () => {
it("should apply custom className", () => {
render(
<ContentThumbnailTemplate
post={mockPost}
variant="vertical"
className="custom-class"
/>
<ContentThumbnailTemplate post={mockPost} className="custom-class" />
);
const container = screen.getByRole("link");
@@ -154,7 +111,7 @@ describe("ContentThumbnailTemplate", () => {
});
it("should generate correct link href", () => {
render(<ContentThumbnailTemplate post={mockPost} variant="vertical" />);
render(<ContentThumbnailTemplate post={mockPost} />);
const link = screen.getByRole("link");
expect(link).toHaveAttribute("href", "/blog/test-post");
@@ -169,9 +126,7 @@ describe("ContentThumbnailTemplate", () => {
},
};
render(
<ContentThumbnailTemplate post={postWithoutTags} variant="vertical" />
);
render(<ContentThumbnailTemplate post={postWithoutTags} />);
// Should still render without errors
expect(screen.getByText("Test Blog Post Title")).toBeInTheDocument();
@@ -186,9 +141,7 @@ describe("ContentThumbnailTemplate", () => {
},
};
render(
<ContentThumbnailTemplate post={postWithoutImages} variant="vertical" />
);
render(<ContentThumbnailTemplate post={postWithoutImages} />);
// Should still render without errors
expect(screen.getByText("Test Blog Post Title")).toBeInTheDocument();
@@ -208,11 +161,5 @@ describe("ContentThumbnailTemplate", () => {
expect(screen.getByText("test")).toBeInTheDocument();
});
it("should show reading time by default", () => {
render(<ContentThumbnailTemplate post={mockPost} />);
expect(screen.getByText(/min read/)).toBeInTheDocument();
});
});
});
-21
View File
@@ -3,7 +3,6 @@ import {
contentProcessor,
getAllPosts,
getBlogStats,
getAllTags,
} from "../../lib/contentProcessor.js";
describe("Content Processor", () => {
@@ -25,14 +24,6 @@ describe("Content Processor", () => {
it("should extract blog statistics", () => {
const stats = getBlogStats();
expect(stats.totalPosts).toBeGreaterThan(0);
expect(stats.totalTags).toBeGreaterThan(0);
expect(stats.totalWords).toBeGreaterThan(0);
});
it("should extract tags from posts", () => {
const tags = getAllTags();
expect(Array.isArray(tags)).toBe(true);
expect(tags.length).toBeGreaterThan(0);
});
});
@@ -44,8 +35,6 @@ describe("Content Processor", () => {
expect(firstPost).toHaveProperty("frontmatter");
expect(firstPost).toHaveProperty("content");
expect(firstPost).toHaveProperty("htmlContent");
expect(firstPost).toHaveProperty("wordCount");
expect(firstPost).toHaveProperty("readingTime");
expect(firstPost).toHaveProperty("headings");
expect(firstPost).toHaveProperty("tableOfContents");
});
@@ -58,16 +47,6 @@ describe("Content Processor", () => {
expect(typeof firstPost.slug).toBe("string");
expect(firstPost.slug.length).toBeGreaterThan(0);
});
it("should calculate word count and reading time", () => {
const posts = getAllPosts();
const firstPost = posts[0];
expect(firstPost.wordCount).toBeGreaterThan(0);
expect(firstPost.readingTime).toBeGreaterThan(0);
expect(typeof firstPost.wordCount).toBe("number");
expect(typeof firstPost.readingTime).toBe("number");
});
});
describe("Content Enhancement", () => {
+1 -44
View File
@@ -14,7 +14,6 @@ describe("Blog Post Validation", () => {
"This is a test description that meets the minimum length requirement",
author: "Test Author",
date: "2025-04-15",
tags: ["test", "blog"],
related: ["post-1", "post-2"],
};
@@ -27,7 +26,6 @@ describe("Blog Post Validation", () => {
const invalidPost = {
title: "Test Title",
// Missing description, author, date
tags: ["test"],
};
const result = validateBlogPost(invalidPost);
@@ -64,41 +62,6 @@ describe("Blog Post Validation", () => {
expect(result.isValid).toBe(false);
expect(result.errors).toContain("Field date format is invalid");
});
it("should validate tags array", () => {
const invalidTags = {
title: "Test Title",
description:
"This is a test description that meets the minimum length requirement",
author: "Test Author",
date: "2025-04-15",
tags: "not-an-array", // Should be array
};
const result = validateBlogPost(invalidTags);
expect(result.isValid).toBe(false);
expect(result.errors).toContain("Field tags must be an array");
});
it("should validate tag item lengths", () => {
const invalidTagItems = {
title: "Test Title",
description:
"This is a test description that meets the minimum length requirement",
author: "Test Author",
date: "2025-04-15",
tags: ["", "very-long-tag-name-that-exceeds-maximum-length"],
};
const result = validateBlogPost(invalidTagItems);
expect(result.isValid).toBe(false);
expect(result.errors).toContain(
"Item 0 in tags must be at least 1 characters"
);
expect(result.errors).toContain(
"Item 1 in tags must be no more than 20 characters"
);
});
});
describe("sanitizeBlogPost", () => {
@@ -108,7 +71,6 @@ describe("Blog Post Validation", () => {
description: "Test description",
author: "Test Author",
date: "2025-04-15",
tags: ["test"],
related: ["post-1"],
};
@@ -122,11 +84,10 @@ describe("Blog Post Validation", () => {
description: "Test description",
author: "Test Author",
date: "2025-04-15",
// Missing tags and related
// Missing related
};
const sanitized = sanitizeBlogPost(post);
expect(sanitized.tags).toEqual([]);
expect(sanitized.related).toEqual([]);
});
@@ -136,12 +97,10 @@ describe("Blog Post Validation", () => {
description: "Test description",
author: "Test Author",
date: "2025-04-15",
tags: ["custom-tag"],
related: ["custom-post"],
};
const sanitized = sanitizeBlogPost(post);
expect(sanitized.tags).toEqual(["custom-tag"]);
expect(sanitized.related).toEqual(["custom-post"]);
});
});
@@ -152,7 +111,6 @@ describe("Blog Post Validation", () => {
expect(BLOG_POST_SCHEMA).toHaveProperty("description");
expect(BLOG_POST_SCHEMA).toHaveProperty("author");
expect(BLOG_POST_SCHEMA).toHaveProperty("date");
expect(BLOG_POST_SCHEMA).toHaveProperty("tags");
expect(BLOG_POST_SCHEMA).toHaveProperty("related");
});
@@ -161,7 +119,6 @@ describe("Blog Post Validation", () => {
expect(BLOG_POST_SCHEMA.description.required).toBe(true);
expect(BLOG_POST_SCHEMA.author.required).toBe(true);
expect(BLOG_POST_SCHEMA.date.required).toBe(true);
expect(BLOG_POST_SCHEMA.tags.required).toBe(false);
expect(BLOG_POST_SCHEMA.related.required).toBe(false);
});
});