Akron | 308a603 | 2019-12-05 16:27:34 +0100 | [diff] [blame] | 1 | define(['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 | }; |
Akron | b69cbf1 | 2020-10-01 13:04:44 +0200 | [diff] [blame^] | 37 | |
| 38 | expect(s.associates()).toEqual(0); |
Akron | 308a603 | 2019-12-05 16:27:34 +0100 | [diff] [blame] | 39 | expect(s.get()).toBeFalsy(); |
| 40 | expect(obj1.x).toBeFalsy(); |
| 41 | expect(obj2.x).toBeTruthy(); |
| 42 | |
| 43 | // Associate object with state |
| 44 | s.associate(obj1); |
Akron | b69cbf1 | 2020-10-01 13:04:44 +0200 | [diff] [blame^] | 45 | expect(s.associates()).toEqual(1); |
Akron | 308a603 | 2019-12-05 16:27:34 +0100 | [diff] [blame] | 46 | s.associate(obj2); |
Akron | b69cbf1 | 2020-10-01 13:04:44 +0200 | [diff] [blame^] | 47 | expect(s.associates()).toEqual(2); |
Akron | 308a603 | 2019-12-05 16:27:34 +0100 | [diff] [blame] | 48 | |
| 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 | }); |