|
@@ -2,9 +2,31 @@ import { assertEquals, cleanup, fireEvent, render, screen } from "./setup.ts";
|
|
|
import PostList from "../../islands/PostList.tsx";
|
|
import PostList from "../../islands/PostList.tsx";
|
|
|
|
|
|
|
|
const mockPosts = [
|
|
const mockPosts = [
|
|
|
- { id: "1", title: "First Post", content: "Hello world", shared: false },
|
|
|
|
|
- { id: "2", title: "Second Post", content: "Another post", shared: true },
|
|
|
|
|
- { id: "3", title: "", content: "", shared: false },
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ id: "1",
|
|
|
|
|
+ title: "First Post",
|
|
|
|
|
+ content: "Hello world",
|
|
|
|
|
+ shared: false,
|
|
|
|
|
+ hasPassword: false,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ id: "2",
|
|
|
|
|
+ title: "Second Post",
|
|
|
|
|
+ content: "Another post",
|
|
|
|
|
+ shared: true,
|
|
|
|
|
+ hasPassword: false,
|
|
|
|
|
+ },
|
|
|
|
|
+ { id: "3", title: "", content: "", shared: false, hasPassword: false },
|
|
|
|
|
+];
|
|
|
|
|
+
|
|
|
|
|
+const mockPostWithPassword = [
|
|
|
|
|
+ {
|
|
|
|
|
+ id: "4",
|
|
|
|
|
+ title: "Protected Post",
|
|
|
|
|
+ content: "Secret",
|
|
|
|
|
+ shared: true,
|
|
|
|
|
+ hasPassword: true,
|
|
|
|
|
+ },
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
Deno.test({
|
|
Deno.test({
|
|
@@ -78,11 +100,11 @@ Deno.test({
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
Deno.test({
|
|
|
- name: "PostList - each card has a delete icon",
|
|
|
|
|
|
|
+ name: "PostList - each card has a Delete button",
|
|
|
fn() {
|
|
fn() {
|
|
|
- const { container } = render(<PostList posts={mockPosts} />);
|
|
|
|
|
- const deleteIcons = container.querySelectorAll(".bi-x");
|
|
|
|
|
- assertEquals(deleteIcons.length, 3);
|
|
|
|
|
|
|
+ render(<PostList posts={mockPosts} />);
|
|
|
|
|
+ const deleteButtons = screen.getAllByText("Delete");
|
|
|
|
|
+ assertEquals(deleteButtons.length, 3);
|
|
|
cleanup();
|
|
cleanup();
|
|
|
},
|
|
},
|
|
|
sanitizeResources: false,
|
|
sanitizeResources: false,
|
|
@@ -90,7 +112,7 @@ Deno.test({
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
Deno.test({
|
|
|
- name: "PostList - delete icon triggers $modal.show",
|
|
|
|
|
|
|
+ name: "PostList - Delete button triggers $modal.show",
|
|
|
fn() {
|
|
fn() {
|
|
|
let modalTitle = "";
|
|
let modalTitle = "";
|
|
|
let modalContent = "";
|
|
let modalContent = "";
|
|
@@ -102,9 +124,9 @@ Deno.test({
|
|
|
hide: () => {},
|
|
hide: () => {},
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const { container } = render(<PostList posts={[mockPosts[0]]} />);
|
|
|
|
|
- const deleteIcon = container.querySelector(".bi-x")!;
|
|
|
|
|
- fireEvent.click(deleteIcon);
|
|
|
|
|
|
|
+ render(<PostList posts={[mockPosts[0]]} />);
|
|
|
|
|
+ const deleteButton = screen.getByText("Delete");
|
|
|
|
|
+ fireEvent.click(deleteButton);
|
|
|
|
|
|
|
|
assertEquals(modalTitle, "Confirm delete");
|
|
assertEquals(modalTitle, "Confirm delete");
|
|
|
assertEquals(modalContent.includes("First Post"), true);
|
|
assertEquals(modalContent.includes("First Post"), true);
|
|
@@ -116,6 +138,54 @@ Deno.test({
|
|
|
sanitizeOps: false,
|
|
sanitizeOps: false,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+Deno.test({
|
|
|
|
|
+ name: "PostList - shows shared icon for shared posts",
|
|
|
|
|
+ fn() {
|
|
|
|
|
+ const { container } = render(<PostList posts={mockPosts} />);
|
|
|
|
|
+ const sharedIcons = container.querySelectorAll(".bi-share-fill");
|
|
|
|
|
+ assertEquals(sharedIcons.length, 1);
|
|
|
|
|
+ cleanup();
|
|
|
|
|
+ },
|
|
|
|
|
+ sanitizeResources: false,
|
|
|
|
|
+ sanitizeOps: false,
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+Deno.test({
|
|
|
|
|
+ name: "PostList - shows lock icon for password-protected posts",
|
|
|
|
|
+ fn() {
|
|
|
|
|
+ const { container } = render(<PostList posts={mockPostWithPassword} />);
|
|
|
|
|
+ const lockIcons = container.querySelectorAll(".bi-lock-fill");
|
|
|
|
|
+ assertEquals(lockIcons.length, 1);
|
|
|
|
|
+ cleanup();
|
|
|
|
|
+ },
|
|
|
|
|
+ sanitizeResources: false,
|
|
|
|
|
+ sanitizeOps: false,
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+Deno.test({
|
|
|
|
|
+ name: "PostList - hides shared icon in readOnly mode",
|
|
|
|
|
+ fn() {
|
|
|
|
|
+ const { container } = render(<PostList posts={mockPosts} readOnly />);
|
|
|
|
|
+ const sharedIcons = container.querySelectorAll(".bi-share-fill");
|
|
|
|
|
+ assertEquals(sharedIcons.length, 0);
|
|
|
|
|
+ cleanup();
|
|
|
|
|
+ },
|
|
|
|
|
+ sanitizeResources: false,
|
|
|
|
|
+ sanitizeOps: false,
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+Deno.test({
|
|
|
|
|
+ name: "PostList - hides Edit and Delete buttons in readOnly mode",
|
|
|
|
|
+ fn() {
|
|
|
|
|
+ render(<PostList posts={mockPosts} readOnly />);
|
|
|
|
|
+ assertEquals(screen.queryByText("Edit"), null);
|
|
|
|
|
+ assertEquals(screen.queryByText("Delete"), null);
|
|
|
|
|
+ cleanup();
|
|
|
|
|
+ },
|
|
|
|
|
+ sanitizeResources: false,
|
|
|
|
|
+ sanitizeOps: false,
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
Deno.test({
|
|
Deno.test({
|
|
|
name: "PostList - renders empty grid with no posts",
|
|
name: "PostList - renders empty grid with no posts",
|
|
|
fn() {
|
|
fn() {
|