fix merge conflicts

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2022-11-13 21:47:27 +00:00
parent 1819f5042c
commit 37ea4d7e6d
6 changed files with 12 additions and 134 deletions

View File

@ -16,7 +16,9 @@ jobs:
- name: Install apt updates - name: Install apt updates
run: sudo apt -y update; sudo apt -y upgrade; run: sudo apt -y update; sudo apt -y upgrade;
- name: Install prerequisites - name: Install prerequisites
run: sudo apt install -y nodejs npm; uses: actions/setup-node@v3
with:
node-version: 18
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Install dependencies - name: Install dependencies

View File

@ -1,8 +1,9 @@
{ {
"name": "food-journal", "name": "food-journal",
"version": "1.0.0", "version": "1.0.0",
"type": "module",
"scripts": { "scripts": {
"test": "mocha --recursive './{,!(node_modules)/**}/*.test.js'", "test": "mocha --recursive --require mock-local-storage './{,!(node_modules)/**}/*.test.js'",
"lint": "eslint '**/*.js'", "lint": "eslint '**/*.js'",
"fix-style": "eslint --fix **/*.js", "fix-style": "eslint --fix **/*.js",
"lintHTML": "htmlhint '**/*.html'", "lintHTML": "htmlhint '**/*.html'",
@ -12,6 +13,7 @@
"eslint": "^8.27.0", "eslint": "^8.27.0",
"htmlhint": "1.1.4", "htmlhint": "1.1.4",
"mocha": "10", "mocha": "10",
"mock-local-storage": "^1.1.23",
"stylelint": "14.14.1", "stylelint": "14.14.1",
"stylelint-config-standard": "^29.0.0" "stylelint-config-standard": "^29.0.0"
} }

View File

@ -78,5 +78,5 @@ html, body {
} }
form { form {
border border: solid;
} }

View File

@ -1,28 +0,0 @@
module.exports = {environment};
function environment () {
const localStorageMock = (function () {
let store = {};
return {
getItem(key) {
return store[key];
},
setItem(key, value) {
store[key] = value;
},
clear() {
store = {};
},
removeItem(key) {
delete store[key];
},
getAll() {
return store;
},
};
})();
let window = {};
Object.defineProperty(window, "localStorage", { value: localStorageMock });
return window;
}

View File

@ -1,81 +0,0 @@
const {environment} = require("./testenv.js");
var assert = require("assert");
var {describe, it, beforeEach} = require("mocha");
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);
});
});

View File

@ -1,17 +0,0 @@
module.exports = {saveToLocal, getFromLocal, removeFromLocal, clearLocal};
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();
}