This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 408
Expand file tree
/
Copy pathstub-item.test.js
More file actions
117 lines (95 loc) · 3.18 KB
/
stub-item.test.js
File metadata and controls
117 lines (95 loc) · 3.18 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
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
import {Emitter} from 'event-kit';
import StubItem from '../../lib/items/stub-item';
class RealItem {
constructor() {
this.emitter = new Emitter();
}
getTitle() { return 'real-title'; }
getIconName() { return 'real-icon-name'; }
getOne() { return 1; }
getElement() { return 'real-element'; }
onDidChangeTitle(cb) { return this.emitter.on('did-change-title', cb); }
onDidChangeIcon(cb) { return this.emitter.on('did-change-icon', cb); }
onDidDestroy(cb) { return this.emitter.on('did-destroy', cb); }
destroy() {
this.emitter.emit('did-destroy');
this.emitter.dispose();
}
}
describe('StubItem', function() {
let stub;
beforeEach(function() {
stub = StubItem.create('name', {
title: 'stub-title',
iconName: 'stub-icon-name',
});
});
afterEach(function() {
stub.destroy();
});
describe('#setRealItem', function() {
let realItem;
beforeEach(function() {
realItem = new RealItem();
});
afterEach(function() {
realItem.destroy();
});
it('sets the real item', function() {
assert.isNull(stub.getRealItem());
stub.setRealItem(realItem);
assert.equal(stub.getRealItem(), realItem);
});
it('emits a title change immediately', function() {
const cb = sinon.stub();
stub.onDidChangeTitle(cb);
stub.setRealItem(realItem);
assert.equal(cb.callCount, 1);
});
it('emits an icon change immediately', function() {
const cb = sinon.stub();
stub.onDidChangeIcon(cb);
stub.setRealItem(realItem);
assert.equal(cb.callCount, 1);
});
describe('method forwarding', function() {
it('forwards getTitle and getIconName', function() {
assert.equal(stub.getTitle(), 'stub-title');
assert.equal(stub.getIconName(), 'stub-icon-name');
stub.setRealItem(realItem);
assert.equal(stub.getTitle(), 'real-title');
assert.equal(stub.getIconName(), 'real-icon-name');
});
it('forwards random methods', function() {
stub.setRealItem(realItem);
assert.equal(stub.getOne(), 1);
});
it('does not forward getElement', function() {
stub.setRealItem(realItem);
assert.notEqual(stub.getElement(), realItem.getElement());
});
it('allows getting the stub', function() {
assert.equal(stub._getStub().getTitle(), stub.getTitle());
});
});
describe('event forwarding', function() {
it('forwards onDidChangeTitle, onDidChangeIcon, and onDidDestroy', function() {
const didChangeTitle = sinon.stub();
const didChangeIcon = sinon.stub();
const didDestroy = sinon.stub();
stub.onDidChangeTitle(didChangeTitle);
stub.onDidChangeIcon(didChangeIcon);
stub.onDidDestroy(didDestroy);
stub.setRealItem(realItem);
didChangeTitle.reset();
didChangeIcon.reset();
realItem.emitter.emit('did-change-title');
assert.equal(didChangeTitle.callCount, 1);
realItem.emitter.emit('did-change-icon');
assert.equal(didChangeIcon.callCount, 1);
realItem.emitter.emit('did-destroy');
assert.equal(didDestroy.callCount, 1);
});
});
});
});