blob: 6a2f32ab9294fb5ebc10aaa514ef245fb31a64ff [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 };
Akronb69cbf12020-10-01 13:04:44 +020037
38 expect(s.associates()).toEqual(0);
Akron308a6032019-12-05 16:27:34 +010039 expect(s.get()).toBeFalsy();
40 expect(obj1.x).toBeFalsy();
41 expect(obj2.x).toBeTruthy();
42
43 // Associate object with state
44 s.associate(obj1);
Akronb69cbf12020-10-01 13:04:44 +020045 expect(s.associates()).toEqual(1);
Akron308a6032019-12-05 16:27:34 +010046 s.associate(obj2);
Akronb69cbf12020-10-01 13:04:44 +020047 expect(s.associates()).toEqual(2);
Akron308a6032019-12-05 16:27:34 +010048
49 expect(s.get()).toBeFalsy();
50 expect(obj1.x).toBeFalsy();
51 expect(obj2.x).toBeFalsy();
52
53 s.set(true);
54
55 expect(s.get()).toBeTruthy();
56 expect(obj1.x).toBeTruthy();
57 expect(obj2.x).toBeTruthy();
58 });
59 });
60});