-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(selection): Correct multiple callback calls (#120)
- Loading branch information
Showing
2 changed files
with
103 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Copyright (c) 2017 NAVER Corp. | ||
* billboard.js project is licensed under the MIT license | ||
*/ | ||
/* eslint-disable */ | ||
/* global describe, beforeEach, it, expect */ | ||
import util from "./assets/util"; | ||
import CLASS from "../src/config/classes"; | ||
|
||
describe("SELECTION", () => { | ||
let chart; | ||
let args; | ||
const spySelected = sinon.spy(); | ||
const spyUnSelected = sinon.spy(); | ||
|
||
beforeEach(() => { | ||
spySelected.reset(); | ||
spyUnSelected.reset(); | ||
|
||
chart = util.generate(args); | ||
}); | ||
|
||
describe("check for callbacks", () => { | ||
describe("data.selction.enabled", () => { | ||
before(() => { | ||
args = { | ||
data: { | ||
columns: [ | ||
["data1", 30, 200, 100, 400, 150, 250], | ||
["data2", 10, 190, 95, 40, 15, 25] | ||
], | ||
selection: { | ||
enabled: true | ||
}, | ||
onselected: spySelected, | ||
onunselected: spyUnSelected | ||
} | ||
}; | ||
}); | ||
|
||
it("multiple selection & onselected callback", () => { | ||
let circle = d3.select(`.${CLASS.shape}-3`).node().getBBox(); | ||
let rect = d3.select(`.${CLASS.eventRect}-3`).node(); | ||
|
||
util.setMouseEvent(chart, "click", circle.x, circle.y, rect); | ||
expect(spySelected.calledOnce).to.be.true; | ||
|
||
circle = d3.select(`.${CLASS.shape}-4`).node().getBBox(); | ||
rect = d3.select(`.${CLASS.eventRect}-4`).node(); | ||
|
||
util.setMouseEvent(chart, "click", circle.x, circle.y, rect); | ||
expect(spySelected.calledTwice).to.be.true; | ||
|
||
// should be selected multiple data points | ||
expect(d3.selectAll(`.${CLASS.SELECTED}`).size() > 1).to.be.true; | ||
}); | ||
|
||
it("set options data.selection.multiple=false", () => { | ||
args.data.selection.multiple = false; | ||
}); | ||
|
||
it("one selection & onunselected callback", () => { | ||
let circle = d3.select(`.${CLASS.shape}-3`).node().getBBox(); | ||
let rect = d3.select(`.${CLASS.eventRect}-3`).node(); | ||
|
||
util.setMouseEvent(chart, "click", circle.x, circle.y, rect); | ||
expect(spySelected.calledOnce).to.be.true; | ||
|
||
circle = d3.select(`.${CLASS.shape}-4`).node().getBBox(); | ||
rect = d3.select(`.${CLASS.eventRect}-4`).node(); | ||
|
||
util.setMouseEvent(chart, "click", circle.x, circle.y, rect); | ||
expect(spySelected.calledTwice).to.be.true; | ||
expect(spyUnSelected.calledOnce).to.be.true; | ||
|
||
// should be selected one data point only | ||
expect(d3.selectAll(`.${CLASS.SELECTED}`).size() === 1).to.be.true; | ||
}); | ||
|
||
it("onselected & onunselected callback should be called once", () => { | ||
const circle = d3.select(`.${CLASS.shape}-3`).node().getBBox(); | ||
const rect = d3.select(`.${CLASS.eventRect}-3`).node(); | ||
|
||
util.setMouseEvent(chart, "click", circle.x, circle.y, rect); | ||
util.setMouseEvent(chart, "click", circle.x, circle.y, rect); | ||
|
||
expect(spySelected.calledOnce).to.be.true; | ||
expect(spyUnSelected.calledOnce).to.be.true; | ||
}); | ||
}); | ||
|
||
}); | ||
}); |
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