| 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 { Panel, PanelLayout, Widget } from '@lumino/widgets'; |
| 13 |
|
| 14 |
describe('@lumino/widgets', () => { |
| 15 |
describe('Panel', () => { |
| 16 |
describe('#constructor()', () => { |
| 17 |
it('should take no arguments', () => { |
| 18 |
let panel = new Panel(); |
| 19 |
expect(panel).to.be.an.instanceof(Panel); |
| 20 |
}); |
| 21 |
|
| 22 |
it('should accept options', () => { |
| 23 |
let layout = new PanelLayout(); |
| 24 |
let panel = new Panel({ layout }); |
| 25 |
expect(panel.layout).to.equal(layout); |
| 26 |
}); |
| 27 |
|
| 28 |
it('should add the `lm-Panel` class', () => { |
| 29 |
let panel = new Panel(); |
| 30 |
expect(panel.hasClass('lm-Panel')).to.equal(true); |
| 31 |
}); |
| 32 |
}); |
| 33 |
|
| 34 |
describe('#widgets', () => { |
| 35 |
it('should be a read-only array of widgets in the panel', () => { |
| 36 |
let panel = new Panel(); |
| 37 |
let widget = new Widget(); |
| 38 |
panel.addWidget(widget); |
| 39 |
expect(panel.widgets).to.deep.equal([widget]); |
| 40 |
}); |
| 41 |
}); |
| 42 |
|
| 43 |
describe('#addWidget()', () => { |
| 44 |
it('should add a widget to the end of the panel', () => { |
| 45 |
let panel = new Panel(); |
| 46 |
let widget = new Widget(); |
| 47 |
panel.addWidget(new Widget()); |
| 48 |
panel.addWidget(widget); |
| 49 |
expect(panel.widgets[1]).to.equal(widget); |
| 50 |
}); |
| 51 |
|
| 52 |
it('should move an existing widget to the end', () => { |
| 53 |
let panel = new Panel(); |
| 54 |
let widget = new Widget(); |
| 55 |
panel.addWidget(widget); |
| 56 |
panel.addWidget(new Widget()); |
| 57 |
panel.addWidget(widget); |
| 58 |
expect(panel.widgets[1]).to.equal(widget); |
| 59 |
}); |
| 60 |
}); |
| 61 |
|
| 62 |
describe('#insertWidget()', () => { |
| 63 |
it('should insert a widget at the specified index', () => { |
| 64 |
let panel = new Panel(); |
| 65 |
let widget = new Widget(); |
| 66 |
panel.addWidget(new Widget()); |
| 67 |
panel.insertWidget(0, widget); |
| 68 |
expect(panel.widgets[0]).to.equal(widget); |
| 69 |
}); |
| 70 |
|
| 71 |
it('should move an existing widget to the specified index', () => { |
| 72 |
let panel = new Panel(); |
| 73 |
let widget = new Widget(); |
| 74 |
panel.addWidget(new Widget()); |
| 75 |
panel.addWidget(widget); |
| 76 |
panel.insertWidget(0, widget); |
| 77 |
expect(panel.widgets[0]).to.equal(widget); |
| 78 |
}); |
| 79 |
}); |
| 80 |
}); |
| 81 |
}); |