Skip to content

Commit

Permalink
Merge pull request #78 from isnifer/feature/make-tests-code-more-cons…
Browse files Browse the repository at this point in the history
…istent

Make tests code more consistent
  • Loading branch information
Jin Choi committed Apr 4, 2017
2 parents c4cef4f + 87596e5 commit b93ed51
Showing 1 changed file with 45 additions and 28 deletions.
73 changes: 45 additions & 28 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('React Components', () => {

it('should fire keypress event when key is pressed', () => {
const spy = sinon.spy();
const wrapper = shallow(<CreateForm createItem={spy}/>);
const wrapper = shallow(<CreateForm createItem={spy} />);
wrapper.find('input').simulate('keyPress');
expect(spy.called).toEqual(true);
});
Expand All @@ -55,7 +55,7 @@ describe('React Components', () => {
});

describe('TextEditor', () => {

it('should render', () => {
const wrapper = shallow(<TextEditor />);
expect(wrapper.exists()).toEqual(true);
Expand All @@ -68,51 +68,51 @@ describe('React Components', () => {

it('should render with className \'block\' if id is equal to active tab id', () => {
const wrapper = shallow(<TextEditor id={1} activeTab={1} />);
chai.expect(wrapper.find('.item-views')).to.have.style("display", "block");
chai.expect(wrapper.find('.item-views')).to.have.style('display', 'block');
});

it('should render with className \'none\' if id is not equal to active tab id', () => {
const wrapper = shallow(<TextEditor id={1} activeTab={2} />);
chai.expect(wrapper.find('.item-views')).to.have.style("display", "none");
chai.expect(wrapper.find('.item-views')).to.have.style('display', 'none');
});
});

describe('Tab', () => {

it('should render', () => {
const wrapper = shallow(<Tab setActiveTab={()=>{}} closeTab={()=>{}}/>);
const wrapper = shallow(<Tab setActiveTab={() => {}} closeTab={() => {}} />);
expect(wrapper.exists()).toEqual(true);
});

it('should fire setActiveTab on click', () => {
const spy = sinon.spy();
const wrapper = shallow(<Tab setActiveTab={spy} closeTab={()=>{}} />);
const wrapper = shallow(<Tab setActiveTab={spy} closeTab={() => {}} />);
wrapper.find('li').simulate('click');
expect(spy.called).toEqual(true);
});

it('should fire setActiveTab on click', () => {
const spy = sinon.spy();
const wrapper = shallow(<Tab closeTab={spy} setActiveTab={()=>{}} />);
const wrapper = shallow(<Tab closeTab={spy} setActiveTab={() => {}} />);
wrapper.find('.close-icon').simulate('click');
expect(spy.called).toEqual(true);
});

it('should render prop name', () => {
const wrapper = shallow(<Tab closeTab={()=>{}} setActiveTab={()=>{}} name='Reactide' />);
const wrapper = shallow(<Tab closeTab={() => {}} setActiveTab={() => {}} name="Reactide" />);
expect(wrapper.find('.title').text()).toEqual('Reactide');
});

it('should pass id into setActiveTab', () => {
const spy = sinon.spy();
const wrapper = shallow(<Tab closeTab={()=>{}} setActiveTab={spy} id={1}/>)
const wrapper = shallow(<Tab closeTab={() => {}} setActiveTab={spy} id={1} />)
wrapper.find('li').simulate('click');
expect(spy.calledWithMatch(1)).toEqual(true);
});

it('should pass id into closeTab', () => {
const spy = sinon.spy();
const wrapper = shallow(<Tab setActiveTab={()=>{}} closeTab={spy} id={1}/>)
const wrapper = shallow(<Tab setActiveTab={() => {}} closeTab={spy} id={1} />)
wrapper.find('.close-icon').simulate('click');
expect(spy.calledWithMatch(1)).toEqual(true);
});
Expand All @@ -121,39 +121,54 @@ describe('React Components', () => {
describe('TextEditorPane', () => {

it('should render', () => {
const wrapper = shallow(<TextEditorPane appState={{openTabs:()=>{}}}/>);
const wrapper = shallow(<TextEditorPane appState={{openTabs:()=>{}}} />);
expect(wrapper.exists()).toEqual(true);
});

it('should render TextEditor when openTabs.length > 0', () => {
const wrapper = shallow(<TextEditorPane appState={{openTabs:[{id:1}], activeTab:1}}/>);
const wrapper = shallow(<TextEditorPane appState={{openTabs:[{id:1}], activeTab:1}} />);
expect(wrapper.find(TextEditor).exists()).toEqual(true);
});

it('should render TextEditors for each open tab', () => {
const wrapper = shallow(<TextEditorPane appState={{openTabs:[{id:1}, {id:2}], activeTab:1}}/>);
const wrapper = shallow(
<TextEditorPane appState={{openTabs:[{id:1}, {id:2}], activeTab:1}} />
);
expect(wrapper.find(TextEditor).length).toEqual(2);
})

it('should not render TextEditor when openTabs.length = 0', () => {
const wrapper = shallow(<TextEditorPane appState={{openTabs:[], activeTab:1}}/>);
const wrapper = shallow(<TextEditorPane appState={{openTabs:[], activeTab:1}} />);
expect(wrapper.find(TextEditor).exists()).toEqual(false);
});

it('should render a TabContainer', () => {
const wrapper = shallow(<TextEditorPane appState={{openTabs:[], activeTab:1}}/>);
const wrapper = shallow(<TextEditorPane appState={{openTabs:[], activeTab:1}} />);
expect(wrapper.find(TabContainer).exists()).toEqual(true);
});

it('should pass props to TabContainer', () => {
const wrapper = shallow(<TextEditorPane appState={{openTabs:[], activeTab:1}} setActiveTab='setActive' closeTab='closeTab'/>);
const wrapper = shallow(
<TextEditorPane
appState={{openTabs:[], activeTab:1}}
setActiveTab="setActive"
closeTab="closeTab"
/>
);
expect(wrapper.find(TabContainer).props().closeTab).toEqual('closeTab');
expect(wrapper.find(TabContainer).props().setActiveTab).toEqual('setActive');
expect(wrapper.find(TabContainer).props().appState).toEqual({openTabs:[], activeTab:1})
});

it('should pass props to TextEditor', () => {
const wrapper = shallow(<TextEditorPane appState={{openTabs:[{id:1}], activeTab:1}} setActiveTab='setActive' closeTab='closeTab' addEditorInstance='coolio'/>);
const wrapper = shallow(
<TextEditorPane
appState={{openTabs:[{id:1}], activeTab:1}}
setActiveTab="setActive"
closeTab="closeTab"
addEditorInstance="coolio"
/>
);
const TE = wrapper.find(TextEditor);
expect(TE.props().id).toEqual(1);
expect(TE.props().tab).toEqual({id:1});
Expand All @@ -165,12 +180,12 @@ describe('React Components', () => {
describe('CreateMenu', () => {

it('should render', () => {
const wrapper = shallow(<CreateMenu createForm={()=>{}}/>);
const wrapper = shallow(<CreateMenu createForm={() => {}} />);
expect(wrapper.exists()).toEqual(true);
});

describe('File create onClick', () => {

it('should fire', () => {
const spy = sinon.spy();
const wrapper = shallow(<CreateMenu createForm={spy} />);
Expand All @@ -180,7 +195,7 @@ describe('React Components', () => {

it('should be called with proper params', () => {
const spy = sinon.spy();
const wrapper = shallow(<CreateMenu createForm={spy} id={1}/>);
const wrapper = shallow(<CreateMenu createForm={spy} id={1} />);
wrapper.find('button').first().simulate('click');
expect(spy.calledWith(1, 'file')).toEqual(true);
});
Expand All @@ -198,7 +213,7 @@ describe('React Components', () => {

it('should be called with proper params', () => {
const spy = sinon.spy();
const wrapper = shallow(<CreateMenu createForm={spy} id={1}/>);
const wrapper = shallow(<CreateMenu createForm={spy} id={1} />);
wrapper.find('button').at(1).simulate('click');
expect(spy.calledWith(1, 'directory')).toEqual(true);
});
Expand All @@ -208,27 +223,29 @@ describe('React Components', () => {
describe('DeletePrompt', () => {

it('should render', () => {
const wrapper = shallow(<DeletePrompt deletePromptHandler={()=>{}}/>);
const wrapper = shallow(<DeletePrompt deletePromptHandler={() => {}} />);
expect(wrapper.exists()).toEqual(true);
});

it('should render prop name', () => {
const wrapper = shallow(<DeletePrompt deletePromptHandler={()=>{}} name='Jonny Greenwood'/>);
const wrapper = shallow(
<DeletePrompt deletePromptHandler={() => {}} name="Jonny Greenwood"/>
);
expect(wrapper.find('h1').text()).toEqual('Are you sure you want to delete Jonny Greenwood?');
});

it('should be false when no is clicked', () => {
const spy = sinon.spy();
const wrapper = shallow(<DeletePrompt deletePromptHandler={spy} name='Jonny Greenwood'/>);
const wrapper = shallow(<DeletePrompt deletePromptHandler={spy} name="Jonny Greenwood"/>);
wrapper.find('button').first().simulate('click');
expect(spy.calledWith(false)).toEqual(true);
});

it('should be true when yes is clicked', () => {
const spy = sinon.spy();
const wrapper = shallow(<DeletePrompt deletePromptHandler={spy} name='Jonny Greenwood'/>);
const wrapper = shallow(<DeletePrompt deletePromptHandler={spy} name="Jonny Greenwood"/>);
wrapper.find('button').at(1).simulate('click');
expect(spy.calledWith(true)).toEqual(true);
});
});
});
});

0 comments on commit b93ed51

Please sign in to comment.