-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make study group list Page #3
Conversation
- Cannot find module @emotion/react - npm install @emotion/react
- Apply to react-router-dom - Create StudyListPage
- Set Header component globally - Fixed test name
- HtmlWebpackPlugin settings
- MainPage - IntroducePage
- Add npm install axios, redux-devtools-extension, redux-logger, json-server - Apply to Redux - Apply to fake-server(json-server) - Renders study group list
src/components/main/StudyGroups.jsx
Outdated
{groups.map((group) => ( | ||
<li key={group.id}>{group.title}</li> | ||
))} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- ์ถ๊ฐ์ ์ธ ์์
์ด ํ์ํ๋ค.
(ํ์ฌ๋ title๋ง ๋์์ง์ง๋ง ๋งํฌ ์ถ๊ฐ ๋ฐ ์ถ๊ฐ์ ์ธ group ์์ธ ์ ๋ณด? ํ๋ฉด์ ๋ํ๋๊ธฐ) - ์ปดํฌ๋ํธ๋ ๋ถ๋ฆฌํด์ฃผ์.
axios.get.mockResolvedValue({ data: STUDY_GROUPS }); | ||
|
||
await expect(getStudyGroups()).resolves.toEqual(STUDY_GROUPS); | ||
|
||
expect(axios.get).toHaveBeenCalledWith( | ||
'http://localhost:3000/groups/', | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- ์ข ๋ ์๊ฐํด๋ณด์.
- https://jestjs.io/docs/en/mock-functions#mocking-modules
- axios-mock-adapter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe('api', () => {
describe('getStudyGroups', () => {
beforeEach(() => {
axios.get.mockResolvedValue({ data: STUDY_GROUPS });
});
it('returns study groups', async () => {
const groups = await getStudyGroups();
expect(groups).toEqual(STUDY_GROUPS);
});
});
});
|
- Apply new StudyGroup Component
|
/* eslint-disable no-plusplus */ | ||
|
||
module.exports = () => { | ||
const data = { groups: [] }; | ||
|
||
for (let i = 0; i < 30; i++) { | ||
const randomMonth = Math.floor((Math.random() * (11 - 1)) + 1); | ||
const randomDay = Math.floor((Math.random() * (30 - 1)) + 1); | ||
|
||
data.groups.push({ | ||
id: i, | ||
moderatorId: `user${i}`, | ||
title: `์คํฐ๋๋ฅผ ์๊ฐํฉ๋๋ค. ${i}`, | ||
applyStartDate: `2020-${randomMonth}-${randomDay}`, | ||
applyEndDate: '2020-12-3', | ||
personnel: randomMonth, | ||
contents: `์ฐ๋ฆฌ๋ ์ด๊ฒ์ ๊ฒ ํฉ๋๋ค.${i}`, | ||
tags: ['JavaScript', 'React', 'Algorithm'], | ||
}); | ||
} | ||
return data; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map
์ด๋ผ๋ ๋ ๋ช
์์ ์ธ ํจ์๋ฅผ ์ด์ฉํด์ ํํํด์ฃผ๋ฉด ์ข์ ๊ฒ ๊ฐ์์\
const range = (length) => Array.from({ length }, (, i) => i);
const randomMonth = () => Math.floor((Math.random() * (11 - 1)) + 1);
const randomDay = () => Math.floor((Math.random() * (30 - 1)) + 1);
module.exports = () => {
const groups = range(30)
.map((i) => {
const month = randomMonth();
const day = randomDay();
return {
id: i,
moderatorId: `user${i}`,
title: `์คํฐ๋๋ฅผ ์๊ฐํฉ๋๋ค. ${i}`,
applyStartDate: `2020-${month}-${day}`,
applyEndDate: '2020-12-3',
personnel: month,
contents: `์ฐ๋ฆฌ๋ ์ด๊ฒ์ ๊ฒ ํฉ๋๋ค.${i}`,
tags: ['JavaScript', 'React', 'Algorithm'],
}
});
return { groups };
}
axios.get.mockResolvedValue({ data: STUDY_GROUPS }); | ||
|
||
await expect(getStudyGroups()).resolves.toEqual(STUDY_GROUPS); | ||
|
||
expect(axios.get).toHaveBeenCalledWith( | ||
'http://localhost:3000/groups/', | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe('api', () => {
describe('getStudyGroups', () => {
beforeEach(() => {
axios.get.mockResolvedValue({ data: STUDY_GROUPS });
});
it('returns study groups', async () => {
const groups = await getStudyGroups();
expect(groups).toEqual(STUDY_GROUPS);
});
});
});
๐ ์คํฐ๋ ๋ชฉ๋ก ๊ตฌํํ๊ธฐ (ํ ํ๋ฉด)