-
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 pull request #78 from softeerbootcamp4th/feature/test-refactor
[Refactor] 차량 소개, 선착순 이벤트, 인증 모달 관련 테스트 코드 작성 및 리팩토링
- Loading branch information
Showing
65 changed files
with
1,364 additions
and
321 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
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
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
import React from "react"; | ||
import App from "./App"; | ||
test("App", () => { | ||
const a = 1; | ||
expect(a).toBe(1); | ||
}); |
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
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
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,67 @@ | ||
import React from "react"; | ||
import { outsideInfoData } from "../../../constants/InfoData"; | ||
import { render, screen } from "../../../utils/TestUtils"; | ||
import OutsideDescriptionItem from "../../mainPage/InfoScreen/OutsideDescriptionItem/OutsideDescriptionItem"; | ||
import Carousel from "./Carousel"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
const carouselItems = outsideInfoData.map(({ key, title, content, image }) => { | ||
return ( | ||
<OutsideDescriptionItem | ||
key={key} | ||
title={title} | ||
description={content} | ||
img={image} | ||
/> | ||
); | ||
}); | ||
|
||
const onClickCase = Array.from({ length: outsideInfoData.length }, (_, i) => i); | ||
|
||
describe("Carousel Component", () => { | ||
beforeEach(() => { | ||
IntersectionObserver = jest.fn().mockImplementation((callback) => ({ | ||
observe: jest.fn((element) => { | ||
callback([ | ||
{ isIntersecting: false, target: element }, | ||
{ isIntersecting: true, target: element }, | ||
{ isIntersecting: false, target: element }, | ||
]); | ||
}), | ||
unobserve: jest.fn(), | ||
disconnect: jest.fn(), | ||
})); | ||
|
||
Element.prototype.scrollTo = jest.fn(); | ||
}); | ||
|
||
test("props로 전달받은 아이템 숫자 만큼의 하위 요소를 렌더링 해야 한다.", () => { | ||
render(<Carousel items={carouselItems} />); | ||
|
||
const items = screen.getAllByRole("img"); | ||
expect(items.length).toBe(outsideInfoData.length); | ||
}); | ||
|
||
onClickCase.forEach((index) => { | ||
test(`props로 ${index}번 째 아이템을 누르면 ${index}번 째 요소로 스크롤 되고, 투명도가 100이 되어야 한다.`, async () => { | ||
render(<Carousel items={carouselItems} />); | ||
|
||
const items = screen.getAllByRole("img"); | ||
await userEvent.click(items[index]); | ||
|
||
const carouselContainer = items[index].parentElement; | ||
const targetPosition = | ||
items[index].offsetLeft - carouselContainer!.offsetLeft; | ||
|
||
expect(carouselContainer?.scrollTo).toHaveBeenCalledWith({ | ||
top: 0, | ||
left: targetPosition, | ||
behavior: "smooth", | ||
}); | ||
|
||
expect(items[index].parentElement?.parentElement).toHaveClass( | ||
"opacity-100", | ||
); | ||
}); | ||
}); | ||
}); |
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
18 changes: 18 additions & 0 deletions
18
...nts/mainPage/InfoScreen/ConvenienceDescriptionItem/ConvenienceDescriptionItem.stories.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,18 @@ | ||
import React from "react"; | ||
import ConvenienceDescriptionItem from "./ConvenienceDescriptionItem"; | ||
import { convenienceInfoData } from "../../../../constants/InfoData"; | ||
|
||
export default { | ||
component: ConvenienceDescriptionItem, | ||
title: "main/Info/ConvenienceDescriptionItem", | ||
tags: ["autodocs"], | ||
excludeStories: /.*Data$/, | ||
}; | ||
|
||
export const Main = { | ||
args: { | ||
title: convenienceInfoData[0].title, | ||
description: convenienceInfoData[0].description, | ||
img: convenienceInfoData[0].image, | ||
}, | ||
}; |
32 changes: 32 additions & 0 deletions
32
...onents/mainPage/InfoScreen/ConvenienceDescriptionItem/ConvenienceDescriptionItem.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,32 @@ | ||
import React from "react"; | ||
import { render, screen } from "../../../../utils/TestUtils"; | ||
import { convenienceInfoData } from "../../../../constants/InfoData"; | ||
import ConvenienceDescriptionItem from "./ConvenienceDescriptionItem"; | ||
const defaultProps = { | ||
title: convenienceInfoData[0].title, | ||
description: convenienceInfoData[0].description, | ||
img: convenienceInfoData[0].image, | ||
}; | ||
|
||
describe("ConvenienceDescriptionItem 렌더링 테스트", () => { | ||
test("props로 전달받은 제목이 렌더링 되야 한다.", () => { | ||
render(<ConvenienceDescriptionItem {...defaultProps} />); | ||
|
||
const title = screen.getByText(defaultProps.title); | ||
expect(title).toBeInTheDocument(); | ||
}); | ||
|
||
test("props로 전달받은 설명이 렌더링 되야 한다.", () => { | ||
render(<ConvenienceDescriptionItem {...defaultProps} />); | ||
|
||
const description = screen.getByText(defaultProps.description); | ||
expect(description).toBeInTheDocument(); | ||
}); | ||
|
||
test("props로 전달받은 이미지가 렌더링 되야 한다.", () => { | ||
render(<ConvenienceDescriptionItem {...defaultProps} />); | ||
|
||
const image = screen.getByRole("img"); | ||
expect(image).toHaveAttribute("src", defaultProps.img); | ||
}); | ||
}); |
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
17 changes: 17 additions & 0 deletions
17
src/components/mainPage/InfoScreen/DriveDescriptionItem/DriveDescriptionItem.stories.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,17 @@ | ||
import React from "react"; | ||
import DriveDescriptionItem from "./DriveDescriptionItem"; | ||
import { driveInfoData } from "../../../../constants/InfoData"; | ||
|
||
export default { | ||
component: DriveDescriptionItem, | ||
title: "main/Info/DriveDescriptionItem", | ||
tags: ["autodocs"], | ||
excludeStories: /.*Data$/, | ||
}; | ||
|
||
export const Main = { | ||
args: { | ||
title: driveInfoData[0].title, | ||
img: driveInfoData[0].image, | ||
}, | ||
}; |
24 changes: 24 additions & 0 deletions
24
src/components/mainPage/InfoScreen/DriveDescriptionItem/DriveDescriptionItem.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,24 @@ | ||
import React from "react"; | ||
import { render, screen } from "../../../../utils/TestUtils"; | ||
import { driveInfoData } from "../../../../constants/InfoData"; | ||
import DriveDescriptionItem from "./DriveDescriptionItem"; | ||
const defaultProps = { | ||
title: driveInfoData[0].title, | ||
img: driveInfoData[0].image, | ||
}; | ||
|
||
describe("DriveDescriptionItem 렌더링 테스트", () => { | ||
test("props로 전달받은 제목이 렌더링 되야 한다.", () => { | ||
render(<DriveDescriptionItem {...defaultProps} />); | ||
|
||
const title = screen.getByText(defaultProps.title); | ||
expect(title).toBeInTheDocument(); | ||
}); | ||
|
||
test("props로 전달받은 이미지가 렌더링 되야 한다.", () => { | ||
render(<DriveDescriptionItem {...defaultProps} />); | ||
|
||
const image = screen.getByRole("img"); | ||
expect(image).toHaveAttribute("src", defaultProps.img); | ||
}); | ||
}); |
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
18 changes: 18 additions & 0 deletions
18
src/components/mainPage/InfoScreen/OutsideDescriptionItem/OutsideDescriptionItem.stories.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,18 @@ | ||
import React from "react"; | ||
import OutsideDescriptionItem from "./OutsideDescriptionItem"; | ||
import { outsideInfoData } from "../../../../constants/InfoData"; | ||
|
||
export default { | ||
component: OutsideDescriptionItem, | ||
title: "main/Info/OutsideDescriptionItem", | ||
tags: ["autodocs"], | ||
excludeStories: /.*Data$/, | ||
}; | ||
|
||
export const Main = { | ||
args: { | ||
title: outsideInfoData[0].title, | ||
description: outsideInfoData[0].content, | ||
img: outsideInfoData[0].image, | ||
}, | ||
}; |
25 changes: 25 additions & 0 deletions
25
src/components/mainPage/InfoScreen/OutsideDescriptionItem/OutsideDescriptionItem.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,25 @@ | ||
import React from "react"; | ||
import { render, screen } from "../../../../utils/TestUtils"; | ||
import { outsideInfoData } from "../../../../constants/InfoData"; | ||
import OutsideDescriptionItem from "./OutsideDescriptionItem"; | ||
const defaultProps = { | ||
title: outsideInfoData[0].title, | ||
description: outsideInfoData[0].content, | ||
img: outsideInfoData[0].image, | ||
}; | ||
|
||
describe("OutsideDescriptionItem 렌더링 테스트", () => { | ||
test("props로 전달받은 제목이 렌더링 되야 한다.", () => { | ||
render(<OutsideDescriptionItem {...defaultProps} />); | ||
|
||
const title = screen.getByText(defaultProps.title); | ||
expect(title).toBeInTheDocument(); | ||
}); | ||
|
||
test("props로 전달받은 이미지가 렌더링 되야 한다.", () => { | ||
render(<OutsideDescriptionItem {...defaultProps} />); | ||
|
||
const image = screen.getByRole("img"); | ||
expect(image).toHaveAttribute("src", defaultProps.img); | ||
}); | ||
}); |
Oops, something went wrong.