-
Notifications
You must be signed in to change notification settings - Fork 0
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 #76 from swsnu/mypagetesting
Mypagetesting
- Loading branch information
Showing
8 changed files
with
497 additions
and
67 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 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,73 @@ | ||
import { getMockStore } from '../test-utils/mocks'; | ||
import { Provider } from 'react-redux'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { MemoryRouter, Route, Routes } from 'react-router'; | ||
import { | ||
UserInfoType, | ||
} from '../store/slices/user'; | ||
import BlockUser from './BlockUser'; | ||
import { statusType } from './MyPage'; | ||
|
||
const initialState: UserInfoType = { | ||
loggedinuser: null, | ||
userlist: [], | ||
menulist: [], | ||
chosenchatroom: null, | ||
}; | ||
interface propsType { | ||
status: statusType; | ||
blockSubmit: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>, nickname:string) => any; | ||
unblockSubmit: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>, nickname:string) => any; | ||
} | ||
|
||
const blockSumbitMock = jest.fn(); | ||
const unblockSumbitMock = jest.fn(); | ||
|
||
const props: propsType = { | ||
status: {name: '', | ||
mbti: '', | ||
intro: '', | ||
birth: '', | ||
gender: '', | ||
nickname: '', | ||
matched_users: ['한국'], | ||
blocked_users: ['가나'], | ||
temperature: 0.0,}, | ||
blockSubmit: blockSumbitMock, | ||
unblockSubmit: unblockSumbitMock, | ||
}; | ||
|
||
const mockStore = getMockStore({ user: initialState }); | ||
|
||
describe('BlockUser', () => { | ||
let blockuser: JSX.Element; | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
blockuser = ( | ||
<Provider store={mockStore}> | ||
<MemoryRouter> | ||
<Routes> | ||
<Route path='/' element={<BlockUser {...props}/>} /> | ||
</Routes> | ||
</MemoryRouter> | ||
</Provider> | ||
); | ||
}); | ||
it('should render correctly', async () => { | ||
render(blockuser); | ||
screen.getByText("한국"); | ||
screen.getByText("가나"); | ||
}) | ||
it('block correctly', async () => { | ||
render(blockuser); | ||
const blockClick = screen.getByText("차단"); | ||
fireEvent.click(blockClick!); | ||
expect(blockSumbitMock).toHaveBeenCalled(); | ||
}) | ||
it('unblock correctly', async () => { | ||
render(blockuser); | ||
const unblockClick = screen.getByText("차단 해제"); | ||
fireEvent.click(unblockClick!); | ||
expect(unblockSumbitMock).toHaveBeenCalled(); | ||
}) | ||
}); |
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,37 @@ | ||
import { getMockStore } from '../test-utils/mocks'; | ||
import { Provider } from 'react-redux'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { MemoryRouter, Route, Routes } from 'react-router'; | ||
import { | ||
UserInfoType, | ||
} from '../store/slices/user'; | ||
import MyManner from './MyManner'; | ||
|
||
const initialState: UserInfoType = { | ||
loggedinuser: null, | ||
userlist: [], | ||
menulist: [], | ||
chosenchatroom: null, | ||
}; | ||
|
||
const mockStore = getMockStore({ user: initialState }); | ||
|
||
describe('MyManner', () => { | ||
let mymanner: JSX.Element; | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mymanner = ( | ||
<Provider store={mockStore}> | ||
<MemoryRouter> | ||
<Routes> | ||
<Route path='/' element={<MyManner temperature={36.5}/>} /> | ||
</Routes> | ||
</MemoryRouter> | ||
</Provider> | ||
); | ||
}); | ||
it('should render correctly', async () => { | ||
render(mymanner); | ||
screen.getByText("당신의 매너 온도는 36.5입니다."); | ||
}) | ||
}); |
Oops, something went wrong.