blob: 93bf1728000a51ccd0ebb620e8df8f92f2a3b676 [file] [log] [blame]
Akrond7ad9072019-12-09 07:08:20 +01001define(['pipe'], function (pipeClass) {
2
3 describe('KorAP.Pipe', function () {
4 it('should be initializable', function () {
5 let p = pipeClass.create();
6 expect(p.size()).toEqual(0);
7 });
8
9 it('should be appendable', function () {
10 let p = pipeClass.create();
11 expect(p.size()).toEqual(0);
12 expect(p.toString()).toEqual('');
13 p.append('service1');
14 expect(p.size()).toEqual(1);
15 expect(p.toString()).toEqual('service1');
16 p.append('service2');
17 expect(p.size()).toEqual(2);
18 expect(p.toString()).toEqual('service1,service2');
19
20 p.append('');
21 expect(p.size()).toEqual(2);
22 expect(p.toString()).toEqual('service1,service2');
23 });
24
25 it('should be prependable', function () {
26 let p = pipeClass.create();
27 expect(p.size()).toEqual(0);
28 expect(p.toString()).toEqual('');
29 p.prepend('service1');
30 expect(p.size()).toEqual(1);
31 expect(p.toString()).toEqual('service1');
32 p.prepend('service2');
33 expect(p.size()).toEqual(2);
34 expect(p.toString()).toEqual('service2,service1');
35
36 p.prepend('');
37 expect(p.size()).toEqual(2);
38 expect(p.toString()).toEqual('service2,service1');
39 });
40
41 it('should be trimmed', function () {
42 let p = pipeClass.create();
43 expect(p.size()).toEqual(0);
44 expect(p.toString()).toEqual('');
45 p.prepend(' service1 ');
46 expect(p.size()).toEqual(1);
47 expect(p.toString()).toEqual('service1');
48
49 p.prepend("\t service2 \t");
50 expect(p.size()).toEqual(2);
51 expect(p.toString()).toEqual('service2,service1');
52
53 p.append(' ');
54 expect(p.size()).toEqual(2);
55 expect(p.toString()).toEqual('service2,service1');
56 });
57
58 it('should be deletable', function () {
59 let p = pipeClass.create();
60 p.append('service1');
61 p.append('service2');
62 p.append('service3');
63 expect(p.toString()).toEqual('service1,service2,service3');
64 p.remove('service2')
65 expect(p.toString()).toEqual('service1,service3');
66
67 p = pipeClass.create();
68 p.append('service1');
69 p.append('service2');
70 p.append('service3');
71 expect(p.toString()).toEqual('service1,service2,service3');
72 p.remove('service1')
73 expect(p.toString()).toEqual('service2,service3');
74
75 p = pipeClass.create();
76 p.append('service1');
77 p.append('service2');
78 p.append('service3');
79 expect(p.toString()).toEqual('service1,service2,service3');
80 p.remove('service3')
81 expect(p.toString()).toEqual('service1,service2');
82
83 p = pipeClass.create();
84 p.append('service1');
85 p.append('service2');
86 p.append('service3');
87 expect(p.toString()).toEqual('service1,service2,service3');
88 p.remove('service0')
89 expect(p.toString()).toEqual('service1,service2,service3');
90 });
Akronba7a0492019-12-17 20:33:11 +010091
92 it('should sync with an element', function () {
93 let p = pipeClass.create();
94 let e = p.element();
95 expect(e.tagName).toEqual("INPUT");
Akron24f48ea2020-07-01 09:37:19 +020096 expect(e.getAttribute("type")).toEqual("text");
Akronba7a0492019-12-17 20:33:11 +010097 p.append('service1');
98 expect(e.getAttribute("value")).toEqual("service1");
99 p.append('service2');
100 expect(e.getAttribute("value")).toEqual("service1,service2");
101 p.remove('service1');
102 expect(e.getAttribute("value")).toEqual("service2");
103 });
Akrond7ad9072019-12-09 07:08:20 +0100104 });
105});