-
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 #42 from Easybuoy/feature/164954218/create-edit-pr…
…oduct-component #164954218 Create edit product component
- Loading branch information
Showing
26 changed files
with
1,222 additions
and
384 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
"@babel/plugin-proposal-class-properties", | ||
{ | ||
"loose": true | ||
} | ||
}, | ||
] | ||
] | ||
|
||
|
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
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,84 @@ | ||
import React from 'react'; | ||
import { shallow, mount } from 'enzyme'; | ||
import sinon from 'sinon'; | ||
|
||
import { EditProduct } from '../../src/components/Products/EditProduct'; | ||
|
||
describe('<EditProduct />', () => { | ||
const props = { | ||
getProductById: jest.fn(), | ||
editProduct: jest.fn(), | ||
product: jest.mock(), | ||
errors: jest.mock(), | ||
match: {params: jest.mock()}, | ||
history: {push: jest.fn()} | ||
}; | ||
|
||
it('renders the EditProduct component correctly', () => { | ||
const wrapper = shallow(<EditProduct {...props}/>); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
it('should call the mock onSubmit function', () => { | ||
const wrapper = shallow(<EditProduct {...props} />) | ||
const instance = wrapper.instance(); | ||
|
||
instance.refs = { | ||
productname: { | ||
value: jest.mock() | ||
}, | ||
productdescription: { | ||
value: jest.mock() | ||
}, | ||
productprice: { | ||
value: jest.mock() | ||
}, | ||
productquantity: { | ||
value: jest.mock() | ||
}, | ||
productimage: { | ||
files: jest.mock() | ||
} | ||
} | ||
const event = Object.assign(jest.fn(), { preventDefault: () => {} }); | ||
|
||
sinon.spy(wrapper.instance(), 'onSubmit'); | ||
wrapper.instance().onSubmit(event); | ||
expect(wrapper.instance().onSubmit.calledOnce) | ||
.toEqual(true); | ||
expect(wrapper.instance().onSubmit.calledWith(event)); | ||
}); | ||
|
||
it('should render Loading component if loading props is true', () => { | ||
const wrapper = shallow(<EditProduct {...props} />) | ||
|
||
expect(props.getProductById).toBeCalled(); | ||
expect(props.getProductById).toHaveReturned(); | ||
}); | ||
|
||
it('should show error message(s) if product is not created', () => { | ||
props.errors = { message: 'Email field is required'} | ||
const wrapper = shallow(<EditProduct {...props} />) | ||
|
||
expect(props.getProductById).toBeCalled(); | ||
expect(props.getProductById).toHaveReturned(); | ||
// expect(wrapper).toMatchSnapshot(); | ||
|
||
}); | ||
|
||
it('should show toast message(s) if product is edited successfully', () => { | ||
props.product.isProductEdited = true; | ||
const wrapper = shallow(<EditProduct {...props} />) | ||
|
||
expect(props.getProductById).toBeCalled(); | ||
expect(props.getProductById).toHaveReturned(); | ||
}); | ||
|
||
it('should render markup if product exist', () => { | ||
props.product.product = {name: 'Milo'}; | ||
const wrapper = shallow(<EditProduct {...props} />) | ||
|
||
expect(props.getProductById).toBeCalled(); | ||
expect(props.getProductById).toHaveReturned(); | ||
}); | ||
}); |
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
Oops, something went wrong.