-
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.
- Loading branch information
Showing
13 changed files
with
356 additions
and
35 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
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,9 @@ | ||
import { customRender } from '../../test-utils' | ||
import CreateContract from '../../components/CreateContract' | ||
|
||
describe('<CreateContract />', () => { | ||
it('Should render the <CreateContract /> component.', () => { | ||
const container = customRender({ component: CreateContract }) | ||
expect(container.asFragment()).toMatchSnapshot() | ||
}) | ||
}) |
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
118 changes: 118 additions & 0 deletions
118
src/__tests__/components/__snapshots__/CreateContract.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,118 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<CreateContract /> Should render the <CreateContract /> component. 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
class="StyledBox-sc-13pk1d4-0 ipWbUu" | ||
> | ||
<label | ||
for="item-type" | ||
> | ||
Item Type | ||
</label> | ||
<select | ||
id="item-type" | ||
> | ||
<option | ||
value="{\\"name\\":\\"Ore\\",\\"value\\":2,\\"volume\\":1}" | ||
> | ||
Ore | ||
</option> | ||
<option | ||
value="{\\"name\\":\\"Plasma\\",\\"value\\":3,\\"volume\\":0.4}" | ||
> | ||
Plasma | ||
</option> | ||
<option | ||
value="{\\"name\\":\\"Space Junk\\",\\"value\\":1,\\"volume\\":0.1}" | ||
> | ||
Space Junk | ||
</option> | ||
<option | ||
value="{\\"name\\":\\"Antibiotics\\",\\"value\\":2,\\"volume\\":0.1}" | ||
> | ||
Antibiotics | ||
</option> | ||
<option | ||
value="{\\"name\\":\\"Tobacco\\",\\"value\\":3,\\"volume\\":0.2}" | ||
> | ||
Tobacco | ||
</option> | ||
<option | ||
value="{\\"name\\":\\"Soil\\",\\"volume\\":2,\\"value\\":0.5}" | ||
> | ||
Soil | ||
</option> | ||
<option | ||
value="{\\"name\\":\\"Ammunition\\",\\"value\\":3,\\"volume\\":0.8}" | ||
> | ||
Ammunition | ||
</option> | ||
<option | ||
value="{\\"name\\":\\"Glass\\",\\"value\\":1,\\"volume\\":1}" | ||
> | ||
Glass | ||
</option> | ||
<option | ||
value="{\\"name\\":\\"Silver\\",\\"value\\":4,\\"volume\\":0.5}" | ||
> | ||
Silver | ||
</option> | ||
<option | ||
value="{\\"name\\":\\"Gold\\",\\"value\\":5,\\"volume\\":0.5}" | ||
> | ||
Gold | ||
</option> | ||
</select> | ||
<label | ||
for="item-volume" | ||
> | ||
Item Volume | ||
</label> | ||
<input | ||
disabled="" | ||
id="item-volume" | ||
type="number" | ||
value="1" | ||
/> | ||
<label | ||
for="item-value" | ||
> | ||
Item Value | ||
</label> | ||
<input | ||
disabled="" | ||
id="item-value" | ||
type="number" | ||
value="2" | ||
/> | ||
<label | ||
for="item-destination" | ||
> | ||
Destination | ||
</label> | ||
<select | ||
id="item-destination" | ||
> | ||
<option | ||
value="0" | ||
> | ||
Test Planet 1 | ||
</option> | ||
<option | ||
value="1" | ||
> | ||
Test Planet 2 | ||
</option> | ||
<option | ||
value="2" | ||
> | ||
Test Planet 3 | ||
</option> | ||
</select> | ||
<button> | ||
Create Contract | ||
</button> | ||
</div> | ||
</DocumentFragment> | ||
`; |
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,87 @@ | ||
import React, { useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Box } from 'grommet' | ||
import { itemList } from '../constants' | ||
import { connect } from 'react-redux' | ||
import { createContract } from '../redux/actions/world' | ||
import { generateContract } from '../util' | ||
|
||
/** | ||
* Inputs for creating a contract. | ||
*/ | ||
const CreateContract = ({ handleCreateContract, planets }) => { | ||
const [itemType, setItemType] = useState(itemList[0]) | ||
const [destination, setDestination] = useState({ | ||
location: planets[0].location, | ||
name: planets[0].name | ||
}) | ||
|
||
return ( | ||
<Box width="medium"> | ||
<label htmlFor="item-type">Item Type</label> | ||
<select | ||
id="item-type" | ||
onChange={e => setItemType(JSON.parse(e.target.value))} | ||
> | ||
{itemList.map(item => ( | ||
<option key={item.name} value={JSON.stringify(item)}> | ||
{item.name} | ||
</option> | ||
))} | ||
</select> | ||
<label htmlFor="item-volume">Item Volume</label> | ||
<input | ||
disabled | ||
id="item-volume" | ||
type="number" | ||
value={itemType ? itemType.volume : 0} | ||
/> | ||
<label htmlFor="item-value">Item Value</label> | ||
<input | ||
disabled | ||
id="item-value" | ||
type="number" | ||
value={itemType ? itemType.value : 0} | ||
/> | ||
<label htmlFor="item-destination">Destination</label> | ||
<select | ||
id="item-destination" | ||
onChange={e => { | ||
const planet = planets.find(planet => planet.id === e.target.value) | ||
setDestination({ location: planet.location, name: planet.name }) | ||
}} | ||
> | ||
{planets.map(planet => ( | ||
<option key={planet.id} value={planet.id}> | ||
{planet.name} | ||
</option> | ||
))} | ||
</select> | ||
<button | ||
onClick={() => { | ||
handleCreateContract( | ||
generateContract(planets, itemType.name, destination) | ||
) | ||
}} | ||
> | ||
Create Contract | ||
</button> | ||
</Box> | ||
) | ||
} | ||
|
||
CreateContract.propTypes = { | ||
handleCreateContract: PropTypes.func.isRequired, | ||
planets: PropTypes.array.isRequired | ||
} | ||
|
||
const mapStateToProps = ({ world }) => ({ planets: world.planets }) | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
handleCreateContract: contract => dispatch(createContract(contract)) | ||
}) | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(CreateContract) |
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
Oops, something went wrong.