All files / test/properties StorageManagerTest.ts

100% Statements 25/25
100% Branches 0/0
100% Functions 5/5
100% Lines 23/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 461x 1x 1x 1x   1x   1x     1x 1x     1x     1x 1x     1x 1x   1x       1x       1x 1x 1x   1x   1x 1x 1x       1x  
import { TestClass } from '../TestClass';
import StorageManager from '../../src/properties/StorageManager';
import { _EISessionKey, _EIPreviousKey, _MSEI } from '../../src/properties/Constants';
import { Utils } from '@ms/1ds-core-js';
 
export class StorageManagerTest extends TestClass {
    // tslint:disable-next-line:no-empty
    public testInitialize() {
    }
 
    public registerTests() {
        this.testCase({
            name: 'Test set and get property',
            test: () => {
                let storageManager = new StorageManager(false);
 
                //Set property
                storageManager._setProperty('abc', '123');
                QUnit.assert.equal(window.localStorage.getItem('abc'), '123');
 
                //Get property
                const value = storageManager._getProperty('abc');
                QUnit.assert.equal(value, '123');
 
                window.localStorage.removeItem('abc');                
            }
        });
 
        this.testCase({
            name: 'Test storage disabled deletes storage keys',
            test: () => {
                //Set cookie and localstorage keys
                window.localStorage.setItem(_EISessionKey, 'test');
                window.localStorage.setItem(_EIPreviousKey, 'test');
                Utils.setCookie(_MSEI, 'test', 365);
                
                let storageManager = new StorageManager(true);
 
                QUnit.assert.notOk(window.localStorage.getItem(_EISessionKey));
                QUnit.assert.notOk(window.localStorage.getItem(_EIPreviousKey));
                QUnit.assert.notOk(Utils.getCookie(_MSEI));
            }
        });
    }
}