-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgroup.test.ts
More file actions
124 lines (107 loc) · 3.37 KB
/
group.test.ts
File metadata and controls
124 lines (107 loc) · 3.37 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
118
119
120
121
122
123
124
import { should, expect } from 'chai'; should();
import source from '../source';
import pin from '../pin';
import sink from '../sink';
import group, { Group } from '../group';
describe('Group', () => {
describe('.subscribe()', () => {
it('should subscribe the given function to all pins in the group.', () => {
let r = 0;
let a = source();
a.to(group(pin(), pin())).subscribe(() => r++);
a.send();
r.should.equal(2);
});
});
describe('.clear()', () => {
it('should clear all pins in the group.', () => {
let a = pin(); let b = pin();
source().to(a, b);
a.connected.should.be.true;
b.connected.should.be.true;
group(a, b).clear();
a.connected.should.be.false;
b.connected.should.be.false;
});
});
describe('.bind()', () => {
it('should bind all bindable pins in the group', () => {
let a = sink(); let b = sink(); let c = pin();
group(a, b, c).bind();
a.locked.should.be.true;
b.locked.should.be.true;
c.locked.should.be.false;
});
});
describe('.observable', () => {
it('should throw an error.', () => {
expect(() => group().observable).to.throw();
});
});
describe('.from()', () => {
it('should connect given pins to all pins in the group.', () => {
let r = 1;
let s = source(); let t = source();
let g = group(sink(() => r *= 2), sink(() => r *= 3));
g.from(s, t); g.bind();
s.send(); t.send();
r.should.equal(36);
});
it('should also connect properly to another group.', () => {
let r = 0;
let s = source();
let a = group(sink(() => r++), sink(() => r++));
let b = group(sink(() => r++), sink(() => r++));
b.from(a).from(s);
b.to(pin()).subscribe();
s.send();
r.should.equal(8);
});
it('should return a Group when called on multiple pins.', () => {
group().from(pin(), pin()).should.be.instanceof(Group);
});
it('should not return a Group when called on one pin.', () => {
group().from(pin()).should.not.be.instanceof(Group);
});
});
describe('.to()', () => {
it('should connect given pins to all pins in the group.', () => {
let r = 1;
let s = source(); let t = source();
let a = sink(() => r *= 2); let b = sink(() => r *= 3);
group(s, t).to(a, b);
a.bind(); b.bind();
s.send(); t.send();
r.should.equal(36);
});
it('should also connect properly to another group.', () => {
let r = 1;
let s = source(); let t = source();
let a = sink(() => r *= 2); let b = sink(() => r *= 3);
group(s, t).to(group(a, b));
a.bind(); b.bind();
s.send(); t.send();
r.should.equal(36);
});
it('should return a Group when called on multiple pins.', () => {
group().to(pin(), pin()).should.be.instanceof(Group);
});
it('should not return a Group when called on one pin.', () => {
group().to(pin()).should.not.be.instanceof(Group);
});
});
describe('.pins', () => {
it('should be all pins of the group.', () => {
let a = pin(); let b = pin();
group(a, b).pins.should.eql([a, b]);
});
});
});
describe('group()', () => {
it('should return a group of all given pins.', () => {
let a = pin(); let b = pin();
let g = group(a, b);
g.should.be.instanceof(Group);
g.pins.should.eql([a, b]);
});
});