Debian Codegraph @

packages/widgets/tests/src/dockpanel.spec.ts

raw
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
11 import { expect } from 'chai';
12
13 import { DockPanel, TabBar, Widget } from '@lumino/widgets';
14
15 describe('@lumino/widgets', () => {
16 describe('DockPanel', () => {
17 describe('#constructor()', () => {
18 it('should construct a new dock panel and take no arguments', () => {
19 let panel = new DockPanel();
20 expect(panel).to.be.an.instanceof(DockPanel);
21 });
22
23 it('should accept options', () => {
24 let renderer = Object.create(TabBar.defaultRenderer);
25 let panel = new DockPanel({
26 tabsMovable: true,
27 renderer,
28 tabsConstrained: true
29 });
30 for (const tabBar of panel.tabBars()) {
31 expect(tabBar.tabsMovable).to.equal(true);
32 }
33 for (const tabBar of panel.tabBars()) {
34 expect(tabBar.renderer).to.equal(renderer);
35 }
36 });
37
38 it('should not have tabs constrained by default', () => {
39 let panel = new DockPanel();
40 expect(panel.tabsConstrained).to.equal(false);
41 });
42
43 it('should add a `lm-DockPanel` class', () => {
44 let panel = new DockPanel();
45 expect(panel.hasClass('lm-DockPanel')).to.equal(true);
46 });
47
48 it('should not have tabbar as child', () => {
49 let panel = new DockPanel();
50 // Adding a widget in the dock panel adds the DOM of a TabBar, but the TabBar
51 // widget should not be a in the children list of the DockPanel widget.
52 panel.addWidget(new Widget());
53 for (const tabBar of panel.tabBars()) {
54 expect(panel.contains(tabBar)).to.be.false;
55 }
56 });
57 });
58
59 describe('#dispose()', () => {
60 it('should dispose of the resources held by the widget', () => {
61 let panel = new DockPanel();
62 panel.addWidget(new Widget());
63 panel.dispose();
64 expect(panel.isDisposed).to.equal(true);
65 panel.dispose();
66 expect(panel.isDisposed).to.equal(true);
67 });
68 });
69
70 describe('#handles()', () => {
71 it('should return the handles within the dock panel', () => {
72 let dock = new DockPanel();
73 dock.addWidget(new Widget());
74 dock.addWidget(new Widget(), { mode: 'split-bottom' });
75 expect(Array.from(dock.handles())).to.have.lengthOf(2); // one is hidden
76 dock.dispose();
77 });
78 });
79
80 describe('hiddenMode', () => {
81 let panel: DockPanel;
82 let widgets: Widget[] = [];
83
84 beforeEach(() => {
85 panel = new DockPanel();
86
87 // Create two stacked widgets
88 widgets.push(new Widget());
89 panel.addWidget(widgets[0]);
90 widgets.push(new Widget());
91 panel.addWidget(widgets[1], { mode: 'tab-after' });
92 });
93
94 afterEach(() => {
95 panel.dispose();
96 });
97
98 it("should be 'display' mode by default", () => {
99 expect(panel.hiddenMode).to.equal(Widget.HiddenMode.Display);
100 });
101
102 it("should switch to 'scale'", () => {
103 widgets[0].hiddenMode = Widget.HiddenMode.Scale;
104
105 panel.hiddenMode = Widget.HiddenMode.Scale;
106
107 expect(widgets[0].hiddenMode).to.equal(Widget.HiddenMode.Scale);
108 expect(widgets[1].hiddenMode).to.equal(Widget.HiddenMode.Scale);
109 });
110
111 it("should switch to 'display'", () => {
112 widgets[0].hiddenMode = Widget.HiddenMode.Scale;
113
114 panel.hiddenMode = Widget.HiddenMode.Scale;
115 panel.hiddenMode = Widget.HiddenMode.Display;
116
117 expect(widgets[0].hiddenMode).to.equal(Widget.HiddenMode.Display);
118 expect(widgets[1].hiddenMode).to.equal(Widget.HiddenMode.Display);
119 });
120
121 it("should not set 'scale' if only one widget", () => {
122 panel.layout!.removeWidget(widgets[1]);
123
124 panel.hiddenMode = Widget.HiddenMode.Scale;
125
126 expect(widgets[0].hiddenMode).to.equal(Widget.HiddenMode.Display);
127 });
128 });
129
130 describe('#tabsMovable', () => {
131 it('should get whether tabs are movable', () => {
132 let panel = new DockPanel();
133 expect(panel.tabsMovable).to.equal(true);
134 });
135
136 it('should set tabsMovable of all tabs', () => {
137 let panel = new DockPanel();
138 let w1 = new Widget();
139 let w2 = new Widget();
140 panel.addWidget(w1);
141 panel.addWidget(w2, { mode: 'split-right', ref: w1 });
142 for (const tabBar of panel.tabBars()) {
143 expect(tabBar.tabsMovable).to.equal(true);
144 }
145
146 panel.tabsMovable = false;
147 for (const tabBar of panel.tabBars()) {
148 expect(tabBar.tabsMovable).to.equal(false);
149 }
150 });
151 });
152 });
153 });