Skip to content

Commit

Permalink
improve test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Nov 9, 2022
1 parent edd4161 commit f0e56ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/scriptlets/trusted-set-local-storage-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
* ```
* example.org#%#//scriptlet('trusted-set-local-storage-item', 'player.live.current.mute', 'false')
*
* example.org#%#//scriptlet('trusted-set-local-storage-item', 'COOKIE_CONSENTS', '{"preferences":3,"marketing":false'})
* example.org#%#//scriptlet('trusted-set-local-storage-item', 'COOKIE_CONSENTS', '{"preferences":3,"marketing":false}')
*
* example.org#%#//scriptlet('trusted-set-local-storage-item', 'providers', '[16364,88364]')
*
Expand Down
34 changes: 24 additions & 10 deletions tests/scriptlets/trusted-set-local-storage-item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (isSafariBrowser()) {
assert.ok(true, 'does not work in Safari 10 while browserstack auto tests run');
});
} else {
test('Set localStorage key with valid value', (assert) => {
test('Set localStorage item', (assert) => {
let iName = '__test-item_true';
let iValue = 'true';
runScriptlet(name, [iName, iValue]);
Expand Down Expand Up @@ -61,25 +61,39 @@ if (isSafariBrowser()) {
assert.strictEqual(window.localStorage.getItem(iName), '', 'localStorage item has been set');
clearStorageItem(iName);

iName = '__test-item_int';
iValue = '15';
iName = '__test-item_object';
iValue = '{"preferences":3,"marketing":false}';
runScriptlet(name, [iName, iValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(window.localStorage.getItem(iName), '15', 'localStorage item has been set');
assert.strictEqual(window.localStorage.getItem(iName), iValue, 'localStorage item has been set');
clearStorageItem(iName);

iName = '__test-item_yes';
iValue = 'yes';
iName = '__test-item_array';
iValue = '[1, 2, "test"]';
runScriptlet(name, [iName, iValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(window.localStorage.getItem(iName), 'yes', 'localStorage item has been set');
assert.strictEqual(window.localStorage.getItem(iName), iValue, 'localStorage item has been set');
clearStorageItem(iName);

iName = '__test-item_no';
iValue = 'no';
iName = '__test-item_string';
iValue = 'some arbitrary item value 111';
runScriptlet(name, [iName, iValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(window.localStorage.getItem(iName), 'no', 'localStorage item has been set');
assert.strictEqual(window.localStorage.getItem(iName), iValue, 'localStorage item has been set');
clearStorageItem(iName);

iName = '__test-item_numbers';
iValue = '123123';
runScriptlet(name, [iName, iValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(window.localStorage.getItem(iName), iValue, 'localStorage item has been set');
clearStorageItem(iName);

iName = '__test-item_mix';
iValue = '123string_!!:;@#$';
runScriptlet(name, [iName, iValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(window.localStorage.getItem(iName), iValue, 'localStorage item has been set');
clearStorageItem(iName);
});

Expand Down

0 comments on commit f0e56ca

Please sign in to comment.