@quartic/bokehjs
Version:
Interactive, novel data visualization
105 lines (86 loc) • 4.12 kB
text/coffeescript
_ = require "underscore"
{expect} = require "chai"
utils = require "../../utils"
sinon = require "sinon"
{Strength, Variable} = utils.require("core/layout/solver")
{Document} = utils.require("document")
{Box} = utils.require("models/layouts/box")
{BoxView} = utils.require("models/layouts/box")
{LayoutDOMView} = utils.require("models/layouts/layout_dom")
describe "BoxView", ->
afterEach ->
utils.unstub_solver()
beforeEach ->
solver_stubs = utils.stub_solver()
= new Box()
= new Document()
.add_root()
it.skip "should have a test for get_height", ->
null
it.skip "should have a test for get_width", ->
null
it "should call build_child_views if children change", ->
child_box = new Box()
spy = sinon.spy(LayoutDOMView.prototype, 'build_child_views')
new .default_view({ model: })
expect(spy.callCount).is.equal 1 # Expect one from initialization
.children = [child_box]
LayoutDOMView.prototype.build_child_views.restore()
# Expect another two: one from children changing event; the other because
# we initialize the child_box
expect(spy.callCount).is.equal 3
describe "Box", ->
describe "get_edit_variables", ->
it "should get edit_variables of children", ->
child1 = new Box(sizing_mode: 'fixed')
child2 = new Box(sizing_mode: 'fixed')
parent_box = new Box({children: [child1, child2], sizing_mode: 'fixed'})
ev = parent_box.get_edit_variables()
expect(ev.length).to.be.equal 6
evs = (item.edit_variable for item in ev)
expect(parent_box._height in evs).is.true
expect(parent_box._width in evs).is.true
expect(child1._height in evs).is.true
expect(child1._width in evs).is.true
expect(child2._height in evs).is.true
expect(child2._width in evs).is.true
describe "get_constrained_variables", ->
beforeEach ->
= new Box()
= {
'width': ._width
'height': ._height
'origin-x': ._dom_left
'origin-y': ._dom_top
'whitespace-top' : ._whitespace_top
'whitespace-bottom' : ._whitespace_bottom
'whitespace-left' : ._whitespace_left
'whitespace-right' : ._whitespace_right
'box-equal-size-top' : ._box_equal_size_top
'box-equal-size-bottom' : ._box_equal_size_bottom
'box-equal-size-left' : ._box_equal_size_left
'box-equal-size-right' : ._box_equal_size_right
'box-cell-align-top' : ._box_cell_align_top
'box-cell-align-bottom' : ._box_cell_align_bottom
'box-cell-align-left' : ._box_cell_align_left
'box-cell-align-right' : ._box_cell_align_right
}
it "should return correct constrained_variables in stretch_both mode", ->
.sizing_mode = 'stretch_both'
constrained_variables = .get_constrained_variables()
expect(constrained_variables).to.be.deep.equal
it "should return correct constrained_variables in scale_width mode", ->
expected_constrained_variables = _.omit(, ['height'])
.sizing_mode = 'scale_width'
constrained_variables = .get_constrained_variables()
expect(constrained_variables).to.be.deep.equal expected_constrained_variables
it "should return correct constrained_variables in scale_height mode", ->
expected_constrained_variables = _.omit(, ['width'])
.sizing_mode = 'scale_height'
constrained_variables = .get_constrained_variables()
expect(constrained_variables).to.be.deep.equal expected_constrained_variables
it "should return correct constrained_variables in fixed mode", ->
expected_constrained_variables = _.omit(, ['height', 'width'])
.sizing_mode = 'fixed'
constrained_variables = .get_constrained_variables()
expect(constrained_variables).to.be.deep.equal expected_constrained_variables