Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✏️ Planet Names #143

Merged
merged 1 commit into from
Sep 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)