Repository navigation
Expand file tree
/
Copy pathpanel.test.js
More file actions
71 lines (59 loc) · 1.79 KB
/
Copy pathpanel.test.js
File metadata and controls
71 lines (59 loc) · 1.79 KB
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
import React from 'react';
import PropTypes from 'prop-types';
import {Emitter} from 'event-kit';
import {mount} from 'enzyme';
import Panel from '../../lib/atom/panel';
class Component extends React.Component {
static propTypes = {
text: PropTypes.string.isRequired,
}
render() {
return (
<div>{this.props.text}</div>
);
}
getText() {
return this.props.text;
}
}
describe('Panel', function() {
let emitter, workspace;
beforeEach(function() {
emitter = new Emitter();
workspace = {
addLeftPanel: sinon.stub().returns({
destroy: sinon.stub().callsFake(() => emitter.emit('destroy')),
onDidDestroy: cb => emitter.on('destroy', cb),
show: sinon.stub(),
hide: sinon.stub(),
}),
};
});
afterEach(function() {
emitter.dispose();
});
it('renders a React component into an Atom panel', function() {
const wrapper = mount(
<Panel workspace={workspace} location="left" options={{some: 'option'}}>
<Component text="hello" />
</Panel>,
);
assert.strictEqual(workspace.addLeftPanel.callCount, 1);
const options = workspace.addLeftPanel.args[0][0];
assert.strictEqual(options.some, 'option');
assert.isDefined(options.item.getElement());
const panel = wrapper.instance().getPanel();
wrapper.unmount();
assert.strictEqual(panel.destroy.callCount, 1);
});
it('calls props.onDidClosePanel when the panel is destroyed unexpectedly', function() {
const onDidClosePanel = sinon.stub();
const wrapper = mount(
<Panel workspace={workspace} location="left" onDidClosePanel={onDidClosePanel}>
<Component text="hello" />
</Panel>,
);
wrapper.instance().getPanel().destroy();
assert.strictEqual(onDidClosePanel.callCount, 1);
});
});