Skip to content

Commit

Permalink
Merge 52d3bd5 into f1f6686
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Lee committed Sep 22, 2019
2 parents f1f6686 + 52d3bd5 commit f23375f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
20 changes: 16 additions & 4 deletions cypress/integration/Planets-spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="cypress" />

import { setMockState } from '../fixtures/default'
import { setMockState, mockState } from '../fixtures/default'

describe('Planets', () => {
beforeEach(() => {
Expand All @@ -10,8 +10,20 @@ describe('Planets', () => {
})

it('Should display planets.', () => {
cy.get('body').contains('Planet 1')
cy.get('body').contains('Planet 2')
cy.get('body').contains('Planet 3')
cy.get('body').contains(mockState.world.planets[0].name)
cy.get('body').contains(mockState.world.planets[1].name)
cy.get('body').contains(mockState.world.planets[2].name)
})

// * Update this in the future
it('Should display an alert when clicking a planet.', () => {
const stub = cy.stub()
cy.on('window:alert', stub)
cy.get('body')
.contains(mockState.world.planets[0].name)
.click()
.then(() => {
expect(stub.getCall(0)).to.be.calledWith('Clicked!')
})
})
})
23 changes: 16 additions & 7 deletions src/components/Map.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useEffect } from 'react'
import PropTypes from 'prop-types'
import { Paper } from '@material-ui/core'
import * as d3 from 'd3'
import { connect } from 'react-redux'

const radius = 23
const fill = '#1976d2'
Expand Down Expand Up @@ -75,17 +77,17 @@ const addEventsToNodes = svg => {
})
}

const Map = () => {
const Map = ({ planets }) => {
const drawChart = () => {
const height = d3.select('#map-root').property('clientHeight')
const width = d3.select('#map-root').property('clientWidth')

const svg = createSvg('#map-root', height, width)

const nodes_data = [
{ name: 'Planet 1' },
{ name: 'Planet 2' },
{ name: 'Planet 3' }
{ name: planets[0].name },
{ name: planets[1].name },
{ name: planets[2].name }
]

const simulation = createSimulation(nodes_data)
Expand Down Expand Up @@ -118,8 +120,8 @@ const Map = () => {

//Create links data
const links_data = [
{ source: 'Planet 1', target: 'Planet 2', distance: 5 },
{ source: 'Planet 2', target: 'Planet 3', distance: 10 }
{ source: planets[0].name, target: planets[1].name, distance: 5 },
{ source: planets[1].name, target: planets[2].name, distance: 10 }
]

//Create the link force
Expand Down Expand Up @@ -151,9 +153,16 @@ const Map = () => {

useEffect(() => {
drawChart()
// eslint-disable-next-line
}, [])

return <Paper id="map-root" style={{ height: 'calc(100vh - 50px)' }} />
}

export default Map
Map.propTypes = {
planets: PropTypes.array.isRequired
}

const mapStateToProps = ({ world }) => ({ planets: world.planets })

export default connect(mapStateToProps)(Map)

0 comments on commit f23375f

Please sign in to comment.