Skip to content

Commit

Permalink
Merge 7c7958e into 4e07784
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Lee committed Sep 28, 2019
2 parents 4e07784 + 7c7958e commit db9051a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 9 additions & 1 deletion cypress/integration/Map-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ describe('Map', () => {
})

it('Should travel to a planet.', () => {
const stub = cy.stub()

cy.on('window:alert', stub)

const destinationPlanet = mockState.world.planets.find(
planet => planet.name !== mockState.ship.location.name
)
Expand All @@ -66,6 +70,10 @@ describe('Map', () => {
cy.wait(1000)
cy.get('body').contains(`Warping to ${destinationPlanet.name}...`)
cy.wait(11000)
cy.get('body').contains('Warp complete!')
cy.get('body')
.contains('Warp complete!')
.then(() => {
expect(stub.getCall(0)).to.be.calledWith(destinationPlanet.name)
})
})
})
2 changes: 1 addition & 1 deletion src/components/TravelPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const mapStateToProps = () => ({})

const mapDispatchToProps = dispatch => ({
handleTravel: (destination, setOpen) => {
hidePlanets(destination)
hidePlanets(destination, dispatch)
// dispatch(instantTravel(destination))
setOpen(false)
}
Expand Down
10 changes: 7 additions & 3 deletions src/util/map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as d3 from 'd3'
import { setShipLocation } from '../redux/actions/ship'

const radius = 23
const fill = '#1976d2'
Expand Down Expand Up @@ -210,21 +211,21 @@ export const getHeight = selector =>

export const getWidth = selector => d3.select(selector).property('clientWidth')

export const hidePlanets = destination => {
export const hidePlanets = (destination, dispatch) => {
d3.selectAll('g').style('pointer-events', 'none')
let value = 1.0
const interval = setInterval(() => {
if (value <= 0) {
clearInterval(interval)
d3.selectAll('g').remove()
showWarpingTo(destination)
showWarpingTo(destination, dispatch)
}
d3.selectAll('g').style('opacity', value - 0.05)
value -= 0.05
}, 100)
}

const showWarpingTo = destination => {
const showWarpingTo = (destination, dispatch) => {
const svg = d3.select('#map-root > svg')
const height = getHeight('#map-root > svg')
const width = getWidth('#map-root > svg')
Expand All @@ -242,5 +243,8 @@ const showWarpingTo = destination => {
.text('Warp complete!')
.attr('x', () => width / 2 - getLabelWidth(svg, `#warping-to`) / 2)
.attr('y', height / 2)

dispatch(setShipLocation(destination))
alert(destination.name)
}, 10000)
}

0 comments on commit db9051a

Please sign in to comment.