blob: 865691edff20e68f12d0648e643598d890b5510f [file] [log] [blame]
Akron308a6032019-12-05 16:27:34 +01001define(['state'], function (stateClass) {
2
3 describe('KorAP.State', function () {
4 it('should be initializable', function () {
5 let s = stateClass.create();
6 expect(s.get()).toBeFalsy();
7
8 s = stateClass.create(true);
9 expect(s.get()).toBeTruthy();
10 });
11
12 it('should be settable and gettable', function () {
13 let s = stateClass.create();
14 expect(s.get()).toBeFalsy();
15 s.set(true);
16 expect(s.get()).toBeTruthy();
17 });
18
19 it('should be associatable', function () {
20 let s = stateClass.create();
21
22 // Create
23 let obj1 = {
24 x : false,
25 setState : function (value) {
26 this.x = value;
27 }
28 };
29
30 // Create
31 let obj2 = {
32 x : true,
33 setState : function (value) {
34 this.x = value;
35 }
36 };
37
38 expect(s.get()).toBeFalsy();
39 expect(obj1.x).toBeFalsy();
40 expect(obj2.x).toBeTruthy();
41
42 // Associate object with state
43 s.associate(obj1);
44 s.associate(obj2);
45
46 expect(s.get()).toBeFalsy();
47 expect(obj1.x).toBeFalsy();
48 expect(obj2.x).toBeFalsy();
49
50 s.set(true);
51
52 expect(s.get()).toBeTruthy();
53 expect(obj1.x).toBeTruthy();
54 expect(obj2.x).toBeTruthy();
55 });
56 });
57});