Skip to content

Commit

Permalink
Merge pull request #77 from SystemConsultantGroup/bug/76-EditVidPic
Browse files Browse the repository at this point in the history
[FIX] 비디오카드 수정
  • Loading branch information
Jongmin Lee authored Aug 30, 2024
2 parents e1c242f + 2e526c0 commit 1ab24b7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 22 deletions.
15 changes: 13 additions & 2 deletions src/components/common/VideoCard/VideoCard.story.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";
import { Meta, StoryFn } from "@storybook/react";
import { VideoCard } from "./VideoCard";

Expand All @@ -7,11 +7,22 @@ export default {
component: VideoCard,
} as Meta<typeof VideoCard>;

const Template: StoryFn<typeof VideoCard> = (args) => <VideoCard {...args} />;
const Template: StoryFn<typeof VideoCard> = (args) => {
// Use local state for the 'bookmarked' prop in the Storybook environment
const [bookmarked, setBookmarked] = useState(args.bookmarked);

// Handler for toggling bookmark state
const handleBookmarkToggle = () => {
setBookmarked((prev) => !prev);
};

return <VideoCard {...args} bookmarked={bookmarked} onBookmarkToggle={handleBookmarkToggle} />;
};

export const Default = Template.bind({});
Default.args = {
title: "뤼튼 테크놀로지스",
subtitle: "현지웅 엔지니어님",
videoUrl: "https://www.youtube.com/embed/OBsR6UumFdc",
bookmarked: false, // Default to not bookmarked
};
48 changes: 42 additions & 6 deletions src/components/common/VideoCard/VideoCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import { render, screen, fireEvent } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
import { VideoCard } from "./VideoCard";

// Mock function for onBookmarkToggle
const mockOnBookmarkToggle = jest.fn();

describe("VideoCard", () => {
const defaultProps = {
title: "뤼튼 테크놀로지스",
subtitle: "현지웅 엔지니어님",
videoUrl: "https://www.youtube.com/embed/OBsR6UumFdc",
bookmarked: false,
onBookmarkToggle: mockOnBookmarkToggle,
};

test("renders VideoCard component", () => {
Expand All @@ -16,13 +21,44 @@ describe("VideoCard", () => {
expect(screen.getByText(defaultProps.subtitle)).toBeInTheDocument();
});

test("toggles bookmark state on click", () => {
test("calls onBookmarkToggle when bookmark icon is clicked", () => {
render(<VideoCard {...defaultProps} />);
const bookmarkIcon = screen.getByRole("button");
expect(bookmarkIcon).toBeInTheDocument();
const bookmarkIcon = screen.getByTestId("bookmark-icon");
fireEvent.click(bookmarkIcon);
expect(screen.getByRole("button")).toContainHTML("#36618E");
fireEvent.click(bookmarkIcon);
expect(screen.getByRole("button")).toContainHTML("none");
expect(mockOnBookmarkToggle).toHaveBeenCalledTimes(1);
});

test("renders bookmarked icon when bookmarked prop is true", () => {
render(<VideoCard {...defaultProps} bookmarked={true} />);
const bookmarkIcon = screen.getByTestId("bookmark-icon");

// Ensure bookmarkIcon is found
expect(bookmarkIcon).toBeInTheDocument();

// Ensure the SVG path is found
const path = bookmarkIcon.querySelector("svg path");
expect(path).toBeInTheDocument();

// Ensure the fill attribute is as expected
if (path) {
expect(path.getAttribute("fill")).toBe("#36618E");
}
});

test("renders un-bookmarked icon when bookmarked prop is false", () => {
render(<VideoCard {...defaultProps} bookmarked={false} />);
const bookmarkIcon = screen.getByTestId("bookmark-icon");

// Ensure bookmarkIcon is found
expect(bookmarkIcon).toBeInTheDocument();

// Ensure the SVG path is found
const path = bookmarkIcon.querySelector("svg path");
expect(path).toBeInTheDocument();

// Ensure the fill attribute is as expected
if (path) {
expect(path.getAttribute("fill")).toBe("none");
}
});
});
20 changes: 6 additions & 14 deletions src/components/common/VideoCard/VideoCard.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
import React, { useState, useEffect } from "react";
import React from "react";
import { Group, Button } from "@mantine/core";
import styles from "./VideoCard.module.css";

export interface VideoCardProps {
title: string;
subtitle: string;
videoUrl: string;
bookmarked?: boolean;
bookmarked: boolean;
onBookmarkToggle: () => void;
}

export const VideoCard: React.FC<VideoCardProps> = ({
title,
subtitle,
videoUrl,
bookmarked: initialBookmarked = false,
bookmarked,
onBookmarkToggle,
}) => {
const [bookmarked, setBookmarked] = useState(initialBookmarked);

useEffect(() => {
setBookmarked(initialBookmarked);
}, [initialBookmarked]);

const handleBookmarkClick = () => {
setBookmarked(!bookmarked);
};

return (
<div className={styles.container}>
<div className={styles.videoFrame}>
Expand All @@ -43,7 +35,7 @@ export const VideoCard: React.FC<VideoCardProps> = ({
<div className={styles.subtitle}>{subtitle}</div>

<Group justify="space-between">
<div className={styles.bookmarkIcon} onClick={handleBookmarkClick}>
<div className={styles.bookmarkIcon} onClick={onBookmarkToggle}>
{bookmarked ? (
/* bookmarked icon */
<svg
Expand Down

0 comments on commit 1ab24b7

Please sign in to comment.