forked from spotify/reactochart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Zoom Container spec * Added npm run test-files
- Loading branch information
Kris Salvador
authored
Jun 6, 2018
1 parent
93891c0
commit 7559bcb
Showing
10 changed files
with
3,237 additions
and
171,935 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
6,810 changes: 3,102 additions & 3,708 deletions
6,810
docs/build/bundle.877bd6ff026ee19fa010.js → docs/build/bundle.a277374995ada5b5cbc9.js
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
.../build/bundle.877bd6ff026ee19fa010.js.map → .../build/bundle.a277374995ada5b5cbc9.js.map
Large diffs are not rendered by default.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,127 @@ | ||
import React from "react"; | ||
import * as d3 from "d3"; | ||
import { expect } from "chai"; | ||
import { mount } from "enzyme"; | ||
|
||
import { XYPlot, ZoomContainer } from "../../../src/index.js"; | ||
import { getValue } from "../../../src/utils/Data.js"; | ||
|
||
describe("ZoomContainer", () => { | ||
const uncontrolledProps = { | ||
width: 500, | ||
height: 500, | ||
scaleExtent: [0.5, 2] | ||
}; | ||
|
||
const controlledProps = { | ||
...uncontrolledProps, | ||
controlled: true | ||
}; | ||
|
||
it("passes props correctly to DOM", () => { | ||
const zoomContainer = mount(<ZoomContainer {...uncontrolledProps} />); | ||
|
||
let svg = zoomContainer.find("svg").getNode(); | ||
let group = zoomContainer.find("g").getNode(); | ||
|
||
expect(parseInt(svg.getAttribute("width"))).to.equal( | ||
uncontrolledProps.width | ||
); | ||
expect(parseInt(svg.getAttribute("height"))).to.equal( | ||
uncontrolledProps.height | ||
); | ||
expect(parseInt(group.getAttribute("width"))).to.equal( | ||
uncontrolledProps.width | ||
); | ||
expect(parseInt(group.getAttribute("height"))).to.equal( | ||
uncontrolledProps.height | ||
); | ||
|
||
const controlledZoomContainer = mount( | ||
<ZoomContainer {...controlledProps} /> | ||
); | ||
|
||
svg = controlledZoomContainer.find("svg").getNode(); | ||
group = controlledZoomContainer.find("g").getNode(); | ||
|
||
expect(parseInt(svg.getAttribute("width"))).to.equal(controlledProps.width); | ||
expect(parseInt(svg.getAttribute("height"))).to.equal( | ||
controlledProps.height | ||
); | ||
expect(parseInt(group.getAttribute("width"))).to.equal( | ||
controlledProps.width | ||
); | ||
expect(parseInt(group.getAttribute("height"))).to.equal( | ||
controlledProps.height | ||
); | ||
}); | ||
|
||
it("passes props correctly to d3 zoom", () => { | ||
const d3Props = { | ||
extent: [[0, 0], [1, 1]], | ||
scaleExtent: [0.5, 2], | ||
translateExtent: [[0, 0], [1, 1]], | ||
clickDistance: 1, | ||
duration: 250, | ||
interpolate: () => {}, | ||
constrain: () => {}, | ||
filter: () => {}, | ||
touchable: () => {}, | ||
wheelDelta: () => {} | ||
}; | ||
|
||
const zoomContainer = mount( | ||
<ZoomContainer {...uncontrolledProps} {...d3Props} /> | ||
); | ||
|
||
const d3Zoom = zoomContainer.instance().zoom; | ||
|
||
expect(d3Zoom.extent).to.be.a("function"); | ||
expect(d3Zoom.scaleExtent).to.be.a("function"); | ||
expect(d3Zoom.translateExtent).to.be.a("function"); | ||
expect(d3Zoom.clickDistance).to.be.a("function"); | ||
expect(d3Zoom.duration).to.be.a("function"); | ||
expect(d3Zoom.interpolate).to.be.a("function"); | ||
expect(d3Zoom.constrain).to.be.a("function"); | ||
expect(d3Zoom.filter).to.be.a("function"); | ||
expect(d3Zoom.touchable).to.be.a("function"); | ||
expect(d3Zoom.wheelDelta).to.be.a("function"); | ||
}); | ||
|
||
it("passes zoom props correctly when controlled", () => { | ||
const zoomContainer = mount(<ZoomContainer {...controlledProps} />); | ||
|
||
expect(zoomContainer.prop("zoomX")).to.equal(0); | ||
expect(zoomContainer.prop("zoomY")).to.equal(0); | ||
expect(zoomContainer.prop("zoomScale")).to.equal(1); | ||
expect(zoomContainer.state("lastZoomTransform").k).to.eql(1); | ||
expect(zoomContainer.state("lastZoomTransform").x).to.eql(0); | ||
expect(zoomContainer.state("lastZoomTransform").y).to.eql(0); | ||
|
||
zoomContainer.setProps({ zoomX: 100, zoomY: 100, zoomScale: 2 }); | ||
|
||
expect(zoomContainer.state("lastZoomTransform").k).to.eql(2); | ||
expect(zoomContainer.state("lastZoomTransform").x).to.eql(100); | ||
expect(zoomContainer.state("lastZoomTransform").y).to.eql(100); | ||
}); | ||
|
||
it("renders correctly", () => { | ||
const zoomContainer = mount(<ZoomContainer {...uncontrolledProps} />); | ||
|
||
let svg = zoomContainer.find("svg"); | ||
let group = zoomContainer.find("g"); | ||
|
||
expect(svg.length).to.equal(1); | ||
expect(group.length).to.equal(1); | ||
|
||
const controlledZoomContainer = mount( | ||
<ZoomContainer {...controlledProps} /> | ||
); | ||
|
||
svg = controlledZoomContainer.find("svg"); | ||
group = controlledZoomContainer.find("g"); | ||
|
||
expect(svg.length).to.equal(1); | ||
expect(group.length).to.equal(1); | ||
}); | ||
}); |