@@ -2,18 +2,22 @@ import React from 'react';
22
33import { MemoryRouter } from 'react-router-dom' ;
44
5- import { render } from '@testing-library/react' ;
5+ import { fireEvent , render } from '@testing-library/react' ;
66
77import IntroduceForm from './IntroduceForm' ;
88
99import STUDY_GROUP from '../../../fixtures/study-group' ;
1010
1111describe ( 'IntroduceForm' , ( ) => {
12- const renderIntroduceForm = ( { group, time } ) => render ( (
12+ const handleRemove = jest . fn ( ) ;
13+
14+ const renderIntroduceForm = ( { group, time, user = 'user2' } ) => render ( (
1315 < MemoryRouter >
1416 < IntroduceForm
17+ user = { user }
1518 group = { group }
1619 realTime = { time }
20+ onRemove = { handleRemove }
1721 />
1822 </ MemoryRouter >
1923 ) ) ;
@@ -30,4 +34,30 @@ describe('IntroduceForm', () => {
3034
3135 expect ( container . innerHTML ) . toContain ( '<a ' ) ;
3236 } ) ;
37+
38+ context ( 'with moderator' , ( ) => {
39+ it ( 'renders delete button and revise button' , ( ) => {
40+ const { container } = renderIntroduceForm ( { group : STUDY_GROUP } ) ;
41+
42+ expect ( container ) . toHaveTextContent ( '수정' ) ;
43+ expect ( container ) . toHaveTextContent ( '삭제' ) ;
44+ } ) ;
45+
46+ it ( 'click to delete button call event' , ( ) => {
47+ const { getByText } = renderIntroduceForm ( { group : STUDY_GROUP } ) ;
48+
49+ fireEvent . click ( getByText ( '삭제' ) ) ;
50+
51+ expect ( handleRemove ) . toBeCalled ( ) ;
52+ } ) ;
53+ } ) ;
54+
55+ context ( 'without moderator' , ( ) => {
56+ it ( "doesn't renders delete button and revise button" , ( ) => {
57+ const { container } = renderIntroduceForm ( { group : STUDY_GROUP , user : 'user' } ) ;
58+
59+ expect ( container ) . not . toHaveTextContent ( '수정' ) ;
60+ expect ( container ) . not . toHaveTextContent ( '삭제' ) ;
61+ } ) ;
62+ } ) ;
3363} ) ;
0 commit comments