-
-
Notifications
You must be signed in to change notification settings - Fork 133
/
panel-container-spec.js
160 lines (132 loc) · 5.27 KB
/
panel-container-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
'use strict';
const Panel = require('../src/panel');
const PanelContainer = require('../src/panel-container');
describe('PanelContainer', () => {
let container;
class TestPanelItem {}
beforeEach(() => {
container = new PanelContainer({ viewRegistry: atom.views });
});
describe('::addPanel(panel)', () => {
it('emits an onDidAddPanel event with the index the panel was inserted at', () => {
const addPanelSpy = jasmine.createSpy();
container.onDidAddPanel(addPanelSpy);
const panel1 = new Panel({ item: new TestPanelItem() }, atom.views);
container.addPanel(panel1);
expect(addPanelSpy).toHaveBeenCalledWith({ panel: panel1, index: 0 });
const panel2 = new Panel({ item: new TestPanelItem() }, atom.views);
container.addPanel(panel2);
expect(addPanelSpy).toHaveBeenCalledWith({ panel: panel2, index: 1 });
});
});
describe('when a panel is destroyed', () => {
it('emits an onDidRemovePanel event with the index of the removed item', () => {
const removePanelSpy = jasmine.createSpy();
container.onDidRemovePanel(removePanelSpy);
const panel1 = new Panel({ item: new TestPanelItem() }, atom.views);
container.addPanel(panel1);
const panel2 = new Panel({ item: new TestPanelItem() }, atom.views);
container.addPanel(panel2);
expect(removePanelSpy).not.toHaveBeenCalled();
panel2.destroy();
expect(removePanelSpy).toHaveBeenCalledWith({ panel: panel2, index: 1 });
panel1.destroy();
expect(removePanelSpy).toHaveBeenCalledWith({ panel: panel1, index: 0 });
});
});
describe('::destroy()', () => {
it('destroys the container and all of its panels', () => {
const destroyedPanels = [];
const panel1 = new Panel({ item: new TestPanelItem() }, atom.views);
panel1.onDidDestroy(() => {
destroyedPanels.push(panel1);
});
container.addPanel(panel1);
const panel2 = new Panel({ item: new TestPanelItem() }, atom.views);
panel2.onDidDestroy(() => {
destroyedPanels.push(panel2);
});
container.addPanel(panel2);
container.destroy();
expect(container.getPanels().length).toBe(0);
expect(destroyedPanels).toEqual([panel1, panel2]);
});
});
describe('panel priority', () => {
describe('left / top panel container', () => {
let initialPanel;
beforeEach(() => {
// 'left' logic is the same as 'top'
container = new PanelContainer({ location: 'left' });
initialPanel = new Panel({ item: new TestPanelItem() }, atom.views);
container.addPanel(initialPanel);
});
describe('when a panel with low priority is added', () => {
it('is inserted at the beginning of the list', () => {
const addPanelSpy = jasmine.createSpy();
container.onDidAddPanel(addPanelSpy);
const panel = new Panel(
{ item: new TestPanelItem(), priority: 0 },
atom.views
);
container.addPanel(panel);
expect(addPanelSpy).toHaveBeenCalledWith({ panel, index: 0 });
expect(container.getPanels()[0]).toBe(panel);
});
});
describe('when a panel with priority between two other panels is added', () => {
it('is inserted at the between the two panels', () => {
const addPanelSpy = jasmine.createSpy();
let panel = new Panel(
{ item: new TestPanelItem(), priority: 1000 },
atom.views
);
container.addPanel(panel);
container.onDidAddPanel(addPanelSpy);
panel = new Panel(
{ item: new TestPanelItem(), priority: 101 },
atom.views
);
container.addPanel(panel);
expect(addPanelSpy).toHaveBeenCalledWith({ panel, index: 1 });
expect(container.getPanels()[1]).toBe(panel);
});
});
});
describe('right / bottom panel container', () => {
let initialPanel;
beforeEach(() => {
// 'bottom' logic is the same as 'right'
container = new PanelContainer({ location: 'right' });
initialPanel = new Panel({ item: new TestPanelItem() }, atom.views);
container.addPanel(initialPanel);
});
describe('when a panel with high priority is added', () => {
it('is inserted at the beginning of the list', () => {
const addPanelSpy = jasmine.createSpy();
container.onDidAddPanel(addPanelSpy);
const panel = new Panel(
{ item: new TestPanelItem(), priority: 1000 },
atom.views
);
container.addPanel(panel);
expect(addPanelSpy).toHaveBeenCalledWith({ panel, index: 0 });
expect(container.getPanels()[0]).toBe(panel);
});
});
describe('when a panel with low priority is added', () => {
it('is inserted at the end of the list', () => {
const addPanelSpy = jasmine.createSpy();
container.onDidAddPanel(addPanelSpy);
const panel = new Panel(
{ item: new TestPanelItem(), priority: 0 },
atom.views
);
container.addPanel(panel);
expect(addPanelSpy).toHaveBeenCalledWith({ panel, index: 1 });
expect(container.getPanels()[1]).toBe(panel);
});
});
});
});
});