| 1 |
// Copyright (c) Jupyter Development Team. |
| 2 |
// Distributed under the terms of the Modified BSD License. |
| 3 |
/*----------------------------------------------------------------------------- |
| 4 |
| Copyright (c) 2014-2017, PhosphorJS Contributors |
| 5 |
| |
| 6 |
| Distributed under the terms of the BSD 3-Clause License. |
| 7 |
| |
| 8 |
| The full license is in the file LICENSE, distributed with this software. |
| 9 |
|----------------------------------------------------------------------------*/ |
| 10 |
import { expect } from 'chai'; |
| 11 |
|
| 12 |
import { BoxLayout, BoxPanel, Widget } from '@lumino/widgets'; |
| 13 |
|
| 14 |
describe('@lumino/widgets', () => { |
| 15 |
describe('BoxPanel', () => { |
| 16 |
describe('#constructor()', () => { |
| 17 |
it('should take no arguments', () => { |
| 18 |
let panel = new BoxPanel(); |
| 19 |
expect(panel).to.be.an.instanceof(BoxPanel); |
| 20 |
}); |
| 21 |
|
| 22 |
it('should accept options', () => { |
| 23 |
let panel = new BoxPanel({ direction: 'bottom-to-top', spacing: 10 }); |
| 24 |
expect(panel.direction).to.equal('bottom-to-top'); |
| 25 |
expect(panel.spacing).to.equal(10); |
| 26 |
}); |
| 27 |
|
| 28 |
it('should accept a layout option', () => { |
| 29 |
let layout = new BoxLayout(); |
| 30 |
let panel = new BoxPanel({ layout }); |
| 31 |
expect(panel.layout).to.equal(layout); |
| 32 |
}); |
| 33 |
|
| 34 |
it('should ignore other options if a layout is given', () => { |
| 35 |
let layout = new BoxLayout(); |
| 36 |
let panel = new BoxPanel({ |
| 37 |
layout, |
| 38 |
direction: 'bottom-to-top', |
| 39 |
spacing: 10 |
| 40 |
}); |
| 41 |
expect(panel.layout).to.equal(layout); |
| 42 |
expect(panel.direction).to.equal('top-to-bottom'); |
| 43 |
expect(panel.spacing).to.equal(4); |
| 44 |
}); |
| 45 |
|
| 46 |
it('should add the `lm-BoxPanel` class', () => { |
| 47 |
let panel = new BoxPanel(); |
| 48 |
expect(panel.hasClass('lm-BoxPanel')).to.equal(true); |
| 49 |
}); |
| 50 |
}); |
| 51 |
|
| 52 |
describe('#direction', () => { |
| 53 |
it('should default to `"top-to-bottom"`', () => { |
| 54 |
let panel = new BoxPanel(); |
| 55 |
expect(panel.direction).to.equal('top-to-bottom'); |
| 56 |
}); |
| 57 |
|
| 58 |
it('should set the layout direction for the box panel', () => { |
| 59 |
let panel = new BoxPanel(); |
| 60 |
panel.direction = 'left-to-right'; |
| 61 |
expect(panel.direction).to.equal('left-to-right'); |
| 62 |
}); |
| 63 |
}); |
| 64 |
|
| 65 |
describe('#spacing', () => { |
| 66 |
it('should default to `4`', () => { |
| 67 |
let panel = new BoxPanel(); |
| 68 |
expect(panel.spacing).to.equal(4); |
| 69 |
}); |
| 70 |
|
| 71 |
it('should set the inter-element spacing for the box panel', () => { |
| 72 |
let panel = new BoxPanel(); |
| 73 |
panel.spacing = 8; |
| 74 |
expect(panel.spacing).to.equal(8); |
| 75 |
}); |
| 76 |
}); |
| 77 |
|
| 78 |
describe('#onChildAdded()', () => { |
| 79 |
it('should add the child class to a child added to the panel', () => { |
| 80 |
let panel = new BoxPanel(); |
| 81 |
let widget = new Widget(); |
| 82 |
panel.addWidget(widget); |
| 83 |
expect(widget.hasClass('lm-BoxPanel-child')).to.equal(true); |
| 84 |
}); |
| 85 |
}); |
| 86 |
|
| 87 |
describe('#onChildRemoved()', () => { |
| 88 |
it('should remove the child class from a child removed from the panel', () => { |
| 89 |
let panel = new BoxPanel(); |
| 90 |
let widget = new Widget(); |
| 91 |
panel.addWidget(widget); |
| 92 |
widget.parent = null; |
| 93 |
expect(widget.hasClass('lm-BoxPanel-child')).to.equal(false); |
| 94 |
}); |
| 95 |
}); |
| 96 |
|
| 97 |
describe('.getStretch()', () => { |
| 98 |
it('should get the box panel stretch factor for the given widget', () => { |
| 99 |
let widget = new Widget(); |
| 100 |
expect(BoxPanel.getStretch(widget)).to.equal(0); |
| 101 |
}); |
| 102 |
}); |
| 103 |
|
| 104 |
describe('.setStretch()', () => { |
| 105 |
it('should set the box panel stretch factor for the given widget', () => { |
| 106 |
let widget = new Widget(); |
| 107 |
BoxPanel.setStretch(widget, 8); |
| 108 |
expect(BoxPanel.getStretch(widget)).to.equal(8); |
| 109 |
}); |
| 110 |
}); |
| 111 |
|
| 112 |
describe('.getSizeBasis()', () => { |
| 113 |
it('should get the box panel size basis for the given widget', () => { |
| 114 |
let widget = new Widget(); |
| 115 |
expect(BoxPanel.getSizeBasis(widget)).to.equal(0); |
| 116 |
}); |
| 117 |
}); |
| 118 |
|
| 119 |
describe('.setSizeBasis()', () => { |
| 120 |
it('should set the box panel size basis for the given widget', () => { |
| 121 |
let widget = new Widget(); |
| 122 |
BoxPanel.setSizeBasis(widget, 8); |
| 123 |
expect(BoxPanel.getSizeBasis(widget)).to.equal(8); |
| 124 |
}); |
| 125 |
}); |
| 126 |
}); |
| 127 |
}); |