mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2024-11-10 05:34:44 +00:00
0f622d16de
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
100 lines
2.9 KiB
JavaScript
100 lines
2.9 KiB
JavaScript
const {environment} = require("./testenv.js");
|
|
var assert = require('assert');
|
|
var window;
|
|
|
|
function saveToLocal (k, v) {
|
|
window.localStorage.setItem(k, v);
|
|
}
|
|
|
|
function getFromLocal (k) {
|
|
return window.localStorage.getItem(k);
|
|
}
|
|
|
|
function removeFromLocal (k) {
|
|
window.localStorage.removeItem(k);
|
|
}
|
|
|
|
function clearLocal () {
|
|
window.localStorage.clear();
|
|
}
|
|
|
|
describe("test localStorage mock", () => {
|
|
it("test save and fetch", () => {
|
|
window = environment();
|
|
|
|
saveToLocal("testkey1", "testvalue1");
|
|
saveToLocal("testkey2", "testvalue2");
|
|
saveToLocal("testkey3", "testvalue3");
|
|
saveToLocal("testkey4", "testvalue4");
|
|
|
|
assert.equal(getFromLocal("testkey1"), "testvalue1");
|
|
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
|
assert.equal(getFromLocal("testkey3"), "testvalue3");
|
|
assert.equal(getFromLocal("testkey4"), "testvalue4");
|
|
|
|
saveToLocal("testkey6", "testvalue5");
|
|
assert.equal(getFromLocal("testkey6"), "testvalue5");
|
|
});
|
|
|
|
it("test window locality", () => {
|
|
window = environment();
|
|
|
|
assert.equal(getFromLocal("testkey1"), null);
|
|
assert.equal(getFromLocal("testkey2"), null);
|
|
assert.equal(getFromLocal("testkey3"), null);
|
|
assert.equal(getFromLocal("testkey4"), null);
|
|
});
|
|
|
|
it("test delete and fetch", () => {
|
|
window = environment();
|
|
|
|
saveToLocal("testkey1", "testvalue1");
|
|
saveToLocal("testkey2", "testvalue2");
|
|
saveToLocal("testkey3", "testvalue3");
|
|
saveToLocal("testkey4", "testvalue4");
|
|
|
|
removeFromLocal("testkey3");
|
|
|
|
assert.equal(getFromLocal("testkey1"), "testvalue1");
|
|
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
|
assert.equal(getFromLocal("testkey3"), null);
|
|
assert.equal(getFromLocal("testkey4"), "testvalue4");
|
|
|
|
removeFromLocal("testkey1");
|
|
|
|
assert.equal(getFromLocal("testkey1"), null);
|
|
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
|
assert.equal(getFromLocal("testkey3"), null);
|
|
assert.equal(getFromLocal("testkey4"), "testvalue4");
|
|
|
|
removeFromLocal("testkey4");
|
|
|
|
assert.equal(getFromLocal("testkey1"), null);
|
|
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
|
assert.equal(getFromLocal("testkey3"), null);
|
|
assert.equal(getFromLocal("testkey4"), null);
|
|
|
|
removeFromLocal("testkey2");
|
|
|
|
assert.equal(getFromLocal("testkey1"), null);
|
|
assert.equal(getFromLocal("testkey2"), null);
|
|
assert.equal(getFromLocal("testkey3"), null);
|
|
assert.equal(getFromLocal("testkey4"), null);
|
|
});
|
|
|
|
it("test clear and fetch", () => {
|
|
window = environment();
|
|
|
|
saveToLocal("testkey1", "testvalue1");
|
|
saveToLocal("testkey2", "testvalue2");
|
|
saveToLocal("testkey3", "testvalue3");
|
|
saveToLocal("testkey4", "testvalue4");
|
|
|
|
clearLocal();
|
|
|
|
assert.equal(getFromLocal("testkey1"), null);
|
|
assert.equal(getFromLocal("testkey2"), null);
|
|
assert.equal(getFromLocal("testkey3"), null);
|
|
assert.equal(getFromLocal("testkey4"), null);
|
|
});
|
|
}); |