mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2024-11-13 22:36:17 +00:00
3043c6e157
move sample helper functions for localStorage unit testing Signed-off-by: Arthur Lu <learthurgo@gmail.com>
80 lines
2.6 KiB
JavaScript
80 lines
2.6 KiB
JavaScript
const {environment} = require("./testenv.js");
|
|
var assert = require('assert');
|
|
var {saveToLocal, getFromLocal, removeFromLocal, clearLocal} = require('./testenv_helpers');
|
|
|
|
beforeEach(() => {
|
|
window = environment();
|
|
});
|
|
|
|
describe("test localStorage mock", () => {
|
|
it("test save and fetch", () => {
|
|
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", () => {
|
|
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", () => {
|
|
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", () => {
|
|
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);
|
|
});
|
|
}); |