Debian Codegraph @

packages/widgets/tests/src/stackedpanel.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 import { expect } from 'chai';
11
12 import { StackedLayout, StackedPanel, Widget } from '@lumino/widgets';
13
14 describe('@lumino/widgets', () => {
15 describe('StackedPanel', () => {
16 describe('#constructor()', () => {
17 it('should take no arguments', () => {
18 let panel = new StackedPanel();
19 expect(panel).to.be.an.instanceof(StackedPanel);
20 });
21
22 it('should take options', () => {
23 let layout = new StackedLayout();
24 let panel = new StackedPanel({ layout });
25 expect(panel.layout).to.equal(layout);
26 });
27
28 it('should add the `lm-StackedPanel` class', () => {
29 let panel = new StackedPanel();
30 expect(panel.hasClass('lm-StackedPanel')).to.equal(true);
31 });
32 });
33
34 describe('hiddenMode', () => {
35 let panel: StackedPanel;
36 let widgets: Widget[] = [];
37
38 beforeEach(() => {
39 panel = new StackedPanel();
40
41 // Create two stacked widgets
42 widgets.push(new Widget());
43 panel.addWidget(widgets[0]);
44 widgets.push(new Widget());
45 panel.addWidget(widgets[1]);
46 });
47
48 afterEach(() => {
49 panel.dispose();
50 });
51
52 it("should be 'display' mode by default", () => {
53 expect(panel.hiddenMode).to.equal(Widget.HiddenMode.Display);
54 });
55
56 it("should switch to 'scale'", () => {
57 panel.hiddenMode = Widget.HiddenMode.Scale;
58
59 expect(widgets[0].hiddenMode).to.equal(Widget.HiddenMode.Scale);
60 expect(widgets[1].hiddenMode).to.equal(Widget.HiddenMode.Scale);
61 });
62
63 it("should switch to 'display'", () => {
64 widgets[0].hiddenMode = Widget.HiddenMode.Scale;
65
66 panel.hiddenMode = Widget.HiddenMode.Scale;
67 panel.hiddenMode = Widget.HiddenMode.Display;
68
69 expect(widgets[0].hiddenMode).to.equal(Widget.HiddenMode.Display);
70 expect(widgets[1].hiddenMode).to.equal(Widget.HiddenMode.Display);
71 });
72
73 it("should not set 'scale' if only one widget", () => {
74 panel.layout!.removeWidget(widgets[1]);
75
76 panel.hiddenMode = Widget.HiddenMode.Scale;
77
78 expect(widgets[0].hiddenMode).to.equal(Widget.HiddenMode.Display);
79 });
80 });
81
82 describe('#widgetRemoved', () => {
83 it('should be emitted when a widget is removed from a stacked panel', () => {
84 let panel = new StackedPanel();
85 let widget = new Widget();
86 panel.addWidget(widget);
87 panel.widgetRemoved.connect((sender, args) => {
88 expect(sender).to.equal(panel);
89 expect(args).to.equal(widget);
90 });
91 widget.parent = null;
92 });
93 });
94
95 describe('#onChildAdded()', () => {
96 it('should add a class to the child widget', () => {
97 let panel = new StackedPanel();
98 let widget = new Widget();
99 panel.addWidget(widget);
100 expect(widget.hasClass('lm-StackedPanel-child')).to.equal(true);
101 });
102 });
103
104 describe('#onChildRemoved()', () => {
105 it('should remove a class to the child widget', () => {
106 let panel = new StackedPanel();
107 let widget = new Widget();
108 panel.addWidget(widget);
109 widget.parent = null;
110 expect(widget.hasClass('lm-StackedPanel-child')).to.equal(false);
111 });
112 });
113 });
114 });