Skip to content

Commit

Permalink
✅ Add test and snapshot for ItemDisplayInput.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlee-dev committed Aug 24, 2019
1 parent a9ad34c commit 4fc90e9
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/__tests__/components/ItemDisplayInput.test.js
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)
})
})
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>
`;

0 comments on commit 4fc90e9

Please sign in to comment.