diff --git a/src/App.jsx b/src/App.jsx
index c97c2e0..1ece9e1 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -12,6 +12,7 @@ import {
ProfilePage,
NewProfilePage,
ApartmentPage,
+ ResultPage,
NotFoundPage,
} from './pages';
@@ -38,8 +39,9 @@ export default function App() {
-
-
+
+
+
diff --git a/src/App.test.jsx b/src/App.test.jsx
index a9d8dc5..daf16b2 100644
--- a/src/App.test.jsx
+++ b/src/App.test.jsx
@@ -18,6 +18,7 @@ describe('App', () => {
const dispatch = jest.fn();
const profile = {
+ isNew: false,
name: '신형탁',
age: 29,
salary: 5000,
@@ -41,7 +42,18 @@ describe('App', () => {
},
];
+ const apartment = {
+ name: '아크로리버파크',
+ date: '2021-03',
+ district: '반포동',
+ area: '129.92',
+ price: '470,000',
+ lotNumber: 1,
+ };
+
+ given('userFields', () => (profile));
given('apartments', () => apartments);
+ given('apartment', () => apartment);
beforeEach(() => {
jest.clearAllMocks();
@@ -51,6 +63,7 @@ describe('App', () => {
useSelector.mockImplementation((selector) => selector({
userFields: given.userFields,
apartments: given.apartments,
+ apartment: given.apartment,
}));
loadItem.mockImplementation(() => null);
@@ -65,8 +78,6 @@ describe('App', () => {
}
context('with path /', () => {
- given('userFields', () => (profile));
-
beforeEach(() => {
loadItem.mockImplementation(() => (JSON.stringify(profile)));
});
@@ -79,8 +90,6 @@ describe('App', () => {
});
context('with path /profile/new', () => {
- given('userFields', () => (profile));
-
it('renders new profile page', () => {
renderApp({ path: '/profile/new' });
@@ -95,8 +104,6 @@ describe('App', () => {
});
context('with path /profile', () => {
- given('userFields', () => (profile));
-
it('renders profile page', () => {
renderApp({ path: '/profile' });
@@ -107,19 +114,31 @@ describe('App', () => {
});
});
- context('with path /aparment', () => {
+ context('with path /aparments', () => {
it('renders apartment page', () => {
- renderApp({ path: '/apartment' });
+ renderApp({ path: '/apartments' });
expect(screen.getByText('거주하고 싶은신 아파트를 선택해주세요')).toBeInTheDocument();
});
});
- context('with path /apartment/:id', () => {
+ context('with path /apartments/:id', () => {
it('redners the apartment page', () => {
- renderApp({ path: '/apartment/riverside' });
+ renderApp({ path: '/apartments/riverside' });
+
+ expect(screen.getByText('아크로리버파크')).toBeInTheDocument();
+ });
+ });
+
+ context('with path /result', () => {
+ it('renders the apartment result page', () => {
+ renderApp({ path: '/result' });
+
+ expect(screen.getByText('결과')).toBeInTheDocument();
expect(screen.getByText('아크로리버파크')).toBeInTheDocument();
+ expect(screen.getByText('129.92')).toBeInTheDocument();
+ expect(screen.getByText('470,000')).toBeInTheDocument();
});
});
diff --git a/src/components/LinkField.jsx b/src/components/LinkField.jsx
index 0805921..efb6297 100644
--- a/src/components/LinkField.jsx
+++ b/src/components/LinkField.jsx
@@ -1,8 +1,13 @@
import React, { useCallback } from 'react';
-export default function LinkField({ url, title, onClick }) {
+export default function LinkField({
+ url, title, onClick, apartment, changeApartment,
+}) {
const handleClick = useCallback((event) => {
event.preventDefault();
+ if (title === '보기') {
+ changeApartment(apartment);
+ }
onClick({ url });
}, [onClick]);
diff --git a/src/components/LinkField.test.jsx b/src/components/LinkField.test.jsx
index ddf81b4..d920cbe 100644
--- a/src/components/LinkField.test.jsx
+++ b/src/components/LinkField.test.jsx
@@ -6,38 +6,68 @@ import LinkField from './LinkField';
describe('LinkField', () => {
const handleClick = jest.fn();
+ const changeApartment = jest.fn();
beforeEach(() => {
jest.clearAllMocks();
});
- it('renders Link', () => {
- render((
-
- ));
+ context("with '내 정보 입력하러가기' title", () => {
+ it('renders Link', () => {
+ render((
+
+ ));
+
+ expect(screen.getByRole('link', {
+ name: '내 정보 입력하러가기',
+ })).toBeInTheDocument();
+ });
+ });
+
+ context("with '거주하고 싶은 아파트 둘러보기' title", () => {
+ it('calls handleClick upon clicking link', () => {
+ render((
+
+ ));
+
+ fireEvent.click(screen.getByRole('link', {
+ name: '거주하고 싶은 아파트 둘러보기',
+ }));
- expect(screen.getByRole('link', {
- name: '내 정보 입력하러가기',
- })).toBeInTheDocument();
+ expect(handleClick).toBeCalledWith({ url: '/apartments' });
+ });
});
- it('calls handleClick upon clicking link', () => {
+ context("with '보기' title", () => {
render((
));
fireEvent.click(screen.getByRole('link', {
- name: '거주하고 싶은 아파트 둘러보기',
+ name: '보기',
}));
- expect(handleClick).toBeCalledWith({ url: '/apartment' });
+ expect(handleClick).toBeCalled();
+ expect(changeApartment).toBeCalled();
});
});
diff --git a/src/pages/Apartment/Apartment.jsx b/src/pages/Apartment/Apartment.jsx
index ed9048f..6a6a324 100644
--- a/src/pages/Apartment/Apartment.jsx
+++ b/src/pages/Apartment/Apartment.jsx
@@ -1,26 +1,20 @@
import React from 'react';
-export default function Apartment({ apartments }) {
- if (!apartments.length) {
- return (
-
loading
- );
- }
+export default function Apartment({ apartment }) {
+ const {
+ name,
+ district,
+ area,
+ } = apartment;
return (
- <>
- {apartments?.map((apartment) => (
-
-
- - 아파트명:
- - {apartment.name}
- - 법정동:
- - {apartment.district}
- - 전용면적:
- - {apartment.area}
-
-
- ))}
- >
+
+ - 아파트명:
+ - {name}
+ - 법정동:
+ - {district}
+ - 전용면적:
+ - {area}
+
);
}
diff --git a/src/pages/Apartment/Apartment.test.jsx b/src/pages/Apartment/Apartment.test.jsx
index f6164dd..4ea3606 100644
--- a/src/pages/Apartment/Apartment.test.jsx
+++ b/src/pages/Apartment/Apartment.test.jsx
@@ -5,37 +5,20 @@ import { render, screen } from '@testing-library/react';
import Apartment from './Apartment';
describe('Apartment', () => {
- const apartments = [
- {
- name: '아크로리버파크',
- date: '2021-03',
- area: '129.92',
- price: '470,000',
- lotNumber: 1,
- },
- {
- name: '서울',
- date: '2021-02',
- area: '200.27',
- price: '420,000',
- lotNumber: 2,
- },
- ];
+ const apartment = {
+ name: '아크로리버파크',
+ date: '2021-03',
+ district: '반포동',
+ area: '129.92',
+ price: '470,000',
+ lotNumber: 1,
+ };
- context('without apartments', () => {
- it('renders loading', () => {
- render();
+ it('renders apartment', () => {
+ render();
- expect(screen.getByText('loading')).toBeInTheDocument();
- });
- });
-
- context('with apartments', () => {
- it('renders Apartment Page', () => {
- render();
-
- expect(screen.getByText('아크로리버파크')).toBeInTheDocument();
- expect(screen.getByText('서울')).toBeInTheDocument();
- });
+ expect(screen.getByText('아크로리버파크')).toBeInTheDocument();
+ expect(screen.getByText('반포동')).toBeInTheDocument();
+ expect(screen.getByText('129.92')).toBeInTheDocument();
});
});
diff --git a/src/pages/Apartment/ApartmentNavigation.jsx b/src/pages/Apartment/ApartmentNavigation.jsx
index 17a1e71..228a691 100644
--- a/src/pages/Apartment/ApartmentNavigation.jsx
+++ b/src/pages/Apartment/ApartmentNavigation.jsx
@@ -7,14 +7,14 @@ export default function ApartmentNavigation({ onClick }) {