Akron | 7650eaa | 2020-10-19 17:10:30 +0200 | [diff] [blame] | 1 | define(['session'], function (sessionClass) { |
| 2 | |
| 3 | beforeEach( |
| 4 | function () { |
| 5 | document.cookie.split(';').forEach( |
| 6 | function (i) { |
| 7 | var pair = i.split('='); |
| 8 | var name = pair[0].trim().toLowerCase(); |
| 9 | |
| 10 | } |
| 11 | ); |
| 12 | } |
| 13 | ); |
| 14 | |
| 15 | describe('KorAP.Session', function () { |
| 16 | it('should be initializable', function () { |
| 17 | let s = sessionClass.create(); |
| 18 | |
| 19 | expect(s).toBeTruthy(); |
| 20 | |
| 21 | expect(s.toString().startsWith('korap=')).toBeTruthy(); |
| 22 | |
| 23 | s = sessionClass.create('kalamar'); |
| 24 | |
| 25 | expect(s).toBeTruthy(); |
| 26 | |
| 27 | expect(s.toString().startsWith('kalamar=')).toBeTruthy(); |
| 28 | }); |
| 29 | |
| 30 | it('should settable and gettable', function () { |
| 31 | let s = sessionClass.create('koraptest'); |
| 32 | s.set("test1", "works"); |
| 33 | |
| 34 | expect(s.get("test1")).toEqual("works"); |
| 35 | |
| 36 | s.set("test2", "\"wor}ks\""); |
| 37 | |
| 38 | expect(s.get("test1")).toEqual("works"); |
| 39 | expect(s.get("test2")).toEqual("\"wor}ks\""); |
| 40 | |
| 41 | expect(s.toString().includes("test1")).toBeTruthy(); |
| 42 | expect(s.toString().includes("test2")).toBeTruthy(); |
| 43 | expect(s.toString().includes("works")).toBeTruthy(); |
| 44 | expect(s.toString().includes("%5C%22wor%7Dks%5C%22")).toBeTruthy(); |
| 45 | }); |
| 46 | |
| 47 | it('should write to cookie', function () { |
| 48 | let s = sessionClass.create('koraptest'); |
| 49 | s.clear(); |
| 50 | expect(s.toString().includes("koraptest=%7B%7D;")).toBeTruthy(); |
| 51 | expect(document.cookie.includes("koraptest=")).toBeTruthy(); |
| 52 | s.set("test3", "works"); |
| 53 | expect(s.toString().includes("koraptest=%7B%7D;")).toBeFalsy(); |
| 54 | expect(s.toString().includes("koraptest=%7B%22test3%22%3A%22works%22%7D")).toBeTruthy(); |
| 55 | expect(document.cookie.includes("koraptest=%7B%22test3%22%3A%22works%22%7D")).toBeTruthy(); |
| 56 | s.clear(); |
| 57 | expect(document.cookie.includes("koraptest=")).toBeTruthy(); |
Akron | 55a208b | 2021-01-22 17:41:22 +0100 | [diff] [blame] | 58 | expect(s.toString()).toEqual("koraptest=%7B%7D;SameSite=Lax"); |
Akron | 7650eaa | 2020-10-19 17:10:30 +0200 | [diff] [blame] | 59 | }); |
| 60 | }) |
| 61 | }); |