-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/test-refactor
- Loading branch information
Showing
34 changed files
with
850 additions
and
522 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { useEffect, useRef } from "react"; | ||
import * as echarts from "echarts"; | ||
|
||
const WordCloud = ({ data, maskImage }: any) => { | ||
const chartRef = useRef(null); | ||
|
||
useEffect(() => { | ||
const chart = echarts.init(chartRef.current); | ||
|
||
const maskImg = new Image(); | ||
maskImg.src = maskImage; | ||
|
||
maskImg.onload = function () { | ||
const option = { | ||
series: [ | ||
{ | ||
type: "wordCloud", | ||
gridSize: 8, | ||
sizeRange: [16, 120], | ||
rotationRange: [0, 0], | ||
shape: "circle", | ||
maskImage: maskImg, | ||
textStyle: { | ||
fontFamily: "Kia-Signature-Regular", | ||
color: function () { | ||
const colors = ["#4B7C83", "#4C7DC4", "#C9C9C9"]; | ||
return colors[Math.floor(Math.random() * colors.length)]; | ||
}, | ||
}, | ||
data: data, | ||
}, | ||
], | ||
}; | ||
|
||
chart.setOption(option); | ||
}; | ||
|
||
return () => { | ||
chart.dispose(); | ||
}; | ||
}, [data]); | ||
|
||
return <div ref={chartRef} style={{ width: "88rem", height: "36rem" }}></div>; | ||
}; | ||
|
||
export default WordCloud; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
src/components/mainPage/MainScreen/EventHeader/EventHeader.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import EventHeader from "./EventHeader"; | ||
|
||
describe("EventHeader", () => { | ||
const title = "Test Title"; | ||
const description = "This is a test description"; | ||
|
||
test("제목은 title로 넘겨준 값이 올바르게 랜더링 되어야 한다", () => { | ||
render(<EventHeader title={title} description={description} />); | ||
|
||
const titleElement = screen.getByText(title); | ||
expect(titleElement).toBeInTheDocument(); | ||
}); | ||
|
||
test("내용은 description으로 넘겨준 값이 올바르게 랜더링 되어야 한다", () => { | ||
render(<EventHeader title={title} description={description} />); | ||
|
||
const descriptionElement = screen.getByText(description); | ||
expect(descriptionElement).toBeInTheDocument(); | ||
}); | ||
}); |
File renamed without changes.
83 changes: 51 additions & 32 deletions
83
src/components/mainPage/MainScreen/EventSelectOptions/EventSelectOptions.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,64 @@ | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import EventSelectOptions from "./EventSelectOptions"; | ||
import { expect } from "@storybook/test"; | ||
import userEvent from "@testing-library/user-event"; | ||
import EventSelectOptions from "./EventSelectOptions"; | ||
import { EventSelectOptionsProps } from "../../../../types/InfoScreen"; | ||
|
||
const mockButtonClick = jest.fn(); | ||
const setHoveredIndex = jest.fn(); | ||
|
||
describe("EventSelectOption Component", () => { | ||
test("EventSelectOption 은 올바르게 랜더링되어야 한다. ", () => { | ||
render( | ||
<EventSelectOptions | ||
index={0} | ||
hoveredIndex={null} | ||
setHoveredIndex={setHoveredIndex} | ||
title="event 1." | ||
description={`매일 선착순 100명! \n퀴즈 풀고 스타벅스 커피 받아가자!`} | ||
img={""} | ||
buttonInfo={{ size: "small", isEnabled: true, onClick: () => {} }} | ||
/>, | ||
); | ||
const defaultProps: EventSelectOptionsProps = { | ||
index: 0, | ||
hoveredIndex: null, | ||
setHoveredIndex: setHoveredIndex, | ||
title: "event 1.", | ||
description: "매일 선착순 100명! \n퀴즈 풀고 스타벅스 커피 받아가자!", | ||
img: "", | ||
buttonInfo: { | ||
onClick: mockButtonClick, | ||
size: "small", | ||
isEnabled: true, | ||
}, | ||
}; | ||
|
||
describe("EventSelectOptions Component", () => { | ||
test("defaultProps에 따라 올바르게 랜더링 되어야 한다.", () => { | ||
render(<EventSelectOptions {...defaultProps} />); | ||
|
||
expect( | ||
screen.getByText("매일 선착순 100명! 퀴즈 풀고 스타벅스 커피 받아가자!"), | ||
).toBeInTheDocument(); | ||
|
||
expect( | ||
screen.getByRole("button", { name: /참여하기/i }), | ||
).toBeInTheDocument(); | ||
}); | ||
test("참여하기 버튼을 누르면 해당 이벤트 페이지로 스크롤 되어야 한다.", async () => { | ||
const handleClick = jest.fn(); | ||
|
||
render( | ||
<EventSelectOptions | ||
index={0} | ||
hoveredIndex={null} | ||
setHoveredIndex={setHoveredIndex} | ||
title="event 1." | ||
description={`매일 선착순 100명! \n퀴즈 풀고 스타벅스 커피 받아가자!`} | ||
img={""} | ||
buttonInfo={{ size: "small", isEnabled: true, onClick: handleClick }} | ||
/>, | ||
); | ||
|
||
await userEvent.click(screen.getByRole("button")); | ||
expect(handleClick).toBeCalled(); | ||
|
||
test("참여하기 버튼을 누르면 onClick 핸들러가 호출되어야 한다.", async () => { | ||
render(<EventSelectOptions {...defaultProps} />); | ||
|
||
const button = screen.getByRole("button", { name: /참여하기/i }); | ||
await userEvent.click(button); | ||
|
||
expect(mockButtonClick).toHaveBeenCalled(); | ||
}); | ||
|
||
test("마우스가 요소 위로 올라가면 setHoveredIndex가 호출되어야 한다.", async () => { | ||
render(<EventSelectOptions {...defaultProps} />); | ||
|
||
const optionContainer = screen.getByText("event 1.").closest("div"); | ||
|
||
await userEvent.hover(optionContainer!); | ||
expect(setHoveredIndex).toHaveBeenCalledWith(0); | ||
|
||
await userEvent.unhover(optionContainer!); | ||
expect(setHoveredIndex).toHaveBeenCalledWith(null); | ||
}); | ||
|
||
test("hoveredIndex가 index와 맞지 않을 때 올바른 opacity가 적용되어야 한다.", () => { | ||
render(<EventSelectOptions {...defaultProps} hoveredIndex={1} />); | ||
|
||
const optionContainer = screen.getByRole("option"); | ||
expect(optionContainer).toHaveClass("opacity-30"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.