-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Add test and snapshot for ItemDisplayInput.
- Loading branch information
alexlee-dev
committed
Aug 24, 2019
1 parent
a9ad34c
commit 4fc90e9
Showing
2 changed files
with
87 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { customRender } from '../../test-utils' | ||
import { fireEvent } from '@testing-library/react' | ||
import ItemDisplayInput from '../../components/ItemDisplayInput' | ||
|
||
const item = { | ||
name: 'Test Item', | ||
space: 1, | ||
value: 1, | ||
id: '0', | ||
destination: { | ||
name: 'Test Planet 2', | ||
value: 50 | ||
}, | ||
quantity: 10 | ||
} | ||
|
||
describe('<ItemDisplayInput />', () => { | ||
it('Should render the <ItemDisplayInput /> component.', () => { | ||
const container = customRender({ | ||
component: ItemDisplayInput, | ||
props: { item } | ||
}) | ||
expect(container.asFragment()).toMatchSnapshot() | ||
}) | ||
|
||
it('Should handle the user buying an item.', () => { | ||
const container = customRender({ | ||
component: ItemDisplayInput, | ||
props: { item } | ||
}) | ||
|
||
const { getByTestId } = container | ||
|
||
const quantityInput = container.container.querySelector('#quantity-input-0') | ||
const addButton = getByTestId('add-button-0') | ||
|
||
fireEvent.change(quantityInput, { target: { value: 2 } }) | ||
fireEvent.click(addButton) | ||
}) | ||
}) |
47 changes: 47 additions & 0 deletions
47
src/__tests__/components/__snapshots__/ItemDisplayInput.test.js.snap
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,47 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<ItemDisplayInput /> Should render the <ItemDisplayInput /> component. 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
class="StyledBox-sc-13pk1d4-0 hroMnY" | ||
> | ||
<button | ||
class="StyledButton-sc-323bzc-0 jJyttA" | ||
data-testid="add-button-0" | ||
disabled="" | ||
type="button" | ||
> | ||
<svg | ||
aria-label="Add" | ||
class="StyledIcon-ofa7kd-0 iOkQrb" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
d="M12,22 L12,2 M2,12 L22,12" | ||
fill="none" | ||
stroke="#000" | ||
stroke-width="2" | ||
/> | ||
</svg> | ||
</button> | ||
<div | ||
class="StyledBox__StyledBoxGap-sc-13pk1d4-1 hPsznL" | ||
/> | ||
<label | ||
for="quantity-input-0" | ||
> | ||
Quantity to Add | ||
</label> | ||
<div | ||
class="StyledBox__StyledBoxGap-sc-13pk1d4-1 hPsznL" | ||
/> | ||
<input | ||
id="quantity-input-0" | ||
max="5" | ||
min="0" | ||
type="number" | ||
value="0" | ||
/> | ||
</div> | ||
</DocumentFragment> | ||
`; |