chore (cleanup): cleanup public folder

This commit is contained in:
MickaelK 2023-10-20 20:05:35 +11:00
parent 5a09186770
commit 40f575037c
8 changed files with 0 additions and 414 deletions

View file

@ -1,20 +0,0 @@
WIP of the complete frontend rewrite in vanilla JS
Admin section:
- [-] pages:
- [ ] backend
- [ ] settings
- [ ] logs
- [X] about
- [ ] setup
- [X] home
- [X] login
- [X] middleware admin only
- [X] middleware error:
- [X] side menu
- [X] side bar
- [ ] form
- [X] error page
End user section:
TODO

View file

@ -1,26 +0,0 @@
import exec from "./ctrl_boot_backoffice.js";
describe("ctrl::boot", () => {
it("runs", async() => {
const start = new Date();
await exec();
expect(new Date() - start).toBeLessThan(100);
});
it("reset the history", () => {
expect(window.history.state).toEqual({});
});
it("setup the dom", () => {
expect(
document.body.classList.contains("touch-no") ||
document.body.classList.contains("touch-yes")
).toBe(true);
});
it("setup the error screen", () => {
expect(typeof window.onerror).toBe("function");
window.onerror("__MESSAGE__");
expect(document.body.outerHTML).toContain("__MESSAGE__");
});
});

View file

@ -1,9 +0,0 @@
import exec from "./ctrl_boot_backoffice.js";
describe("ctrl::boot", () => {
it("runs", async() => {
const start = new Date();
await exec();
expect(new Date() - start).toBeLessThan(100);
});
});

View file

@ -1,24 +0,0 @@
import { jest } from "@jest/globals";
import { JSDOM } from "jsdom";
global.jest = jest;
global.window = new JSDOM("<html></html>", { url: "http://example.com" }).window;
global.document = global.window.document;
global.nextTick = () => new Promise((done) => process.nextTick(done));
global.location = global.window.location;
global.createRender = function() {
const fn = jest.fn();
fn.get = (i = 0) => fn.mock.calls[i][0];
fn.size = () => fn.mock.calls.length;
return fn;
};
global.console = {
...console,
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn()
};
global.customElements = {
define: jest.fn(),
};

View file

@ -1,131 +0,0 @@
import main, { createElement, onDestroy } from "./index.js";
xdescribe("router with inline controller", () => {
it("can render a string", async() => {
// given
const $app = window.document.createElement("div");
const routes = {
"/": (render) => render("<h1 id=\"test\">main</h1>")
};
// when
main($app, routes);
window.dispatchEvent(new window.Event("pagechange"));
await nextTick();
expect($app.querySelector("#test").textContent).toBe("main");
});
it("can render a dom node", async() => {
// given
const $app = window.document.createElement("div");
const $node = createElement("<h1 id=\"test\">main</h1>");
const routes = {
"/": (render) => render($node)
};
// when
main($app, routes);
window.dispatchEvent(new window.Event("pagechange"));
// then
await nextTick();
expect($node instanceof window.Element).toBe(true);
expect($app.querySelector("#test").textContent).toBe("main");
});
it("errors when given a non valid route", async() => {
// given
const $app = window.document.createElement("div");
const $node = createElement("<h1 id=\"test\">main</h1>");
const routes = {
"/": null
};
// when
main($app, routes);
window.dispatchEvent(new window.Event("pagechange"));
// then
await nextTick();
expect($node instanceof window.Element).toBe(true);
expect($app.querySelector("h1").textContent).toBe("Error");
});
it("errors when given a non valid render", async() => {
// given
const $app = window.document.createElement("div");
const $node = createElement("<h1 id=\"test\">main</h1>");
const routes = {
"/": (render) => render({ json: "object", is: "not_ok" })
};
// when
main($app, routes);
window.dispatchEvent(new window.Event("pagechange"));
// then
await nextTick();
expect($node instanceof window.Element).toBe(true);
expect($app.querySelector("h1").textContent).toBe("Error");
});
});
xdescribe("router with es6 module as a controller", () => {
it("render the default import", async() => {
// given
const $app = window.document.createElement("div");
const routes = {
"/": "./common/skeleton/test/ctrl/ok.js"
};
// when
main($app, routes);
window.dispatchEvent(new window.Event("pagechange"));
// then
await nextTick();
expect($app.querySelector("h1").textContent.trim()).toBe("hello world");
});
it("error when missing the default render", async() => {
// given
const $app = window.document.createElement("div");
const routes = {
"/": "./common/skeleton/test/ctrl/nok.js"
};
// when
main($app, routes);
window.dispatchEvent(new window.Event("pagechange"));
// then
await nextTick();
expect($app.querySelector("h1").textContent.trim()).toBe("Error");
});
});
xdescribe("navigation", () => {
it("using a link with data-link attribute for SPA", async() => {
// given
const $app = window.document.createElement("div");
const routes = {
"/": "./common/skeleton/test/ctrl/link.js",
"/something": (render) => render("<h1>OK</h1>")
};
const destroy = jest.fn();
// when
main($app, routes);
window.dispatchEvent(new window.Event("pagechange"));
await nextTick();
expect(window.location.pathname).toBe("/");
onDestroy(destroy);
$app.querySelector("#spa-link").click();
await nextTick();
// then
expect(destroy).toHaveBeenCalled();
expect(window.location.pathname).toBe("/something");
});
});

View file

@ -1,89 +0,0 @@
import { createElement } from "./index.js";
import { currentRoute, init } from "./router.js";
import * as routerModule from "./router.js";
describe("router", () => {
xit("logic to get the current route", () => {
// given
let res;
const routes = {
"/foo": "route /foo",
"/bar": "route /bar"
};
window.location.pathname = "/";
// when, then
expect(window.location.pathname).toBe("/");
expect(currentRoute({ "/": "route /", ...routes })).toBe("route /");
expect(currentRoute(routes, "/foo")).toBe("route /foo");
expect(currentRoute(routes)).toBe(null);
});
it("trigger a page change when DOMContentLoaded", () => {
// given
const fn = jest.fn();
init(createElement("<div></div>"));
window.addEventListener("pagechange", fn);
// when
window.dispatchEvent(new window.Event("DOMContentLoaded"));
// then
expect(fn).toBeCalled();
});
it("trigger a page change when history back", () => {
// given
const fn = jest.fn();
init(createElement("<div></div>"));
window.addEventListener("pagechange", fn);
// when
window.dispatchEvent(new window.Event("popstate"));
// then
expect(fn).toBeCalled();
});
it("trigger a page change when clicking on a link with [data-link] attribute", () => {
// given
const fn = jest.fn();
const $link = createElement("<a href=\"/something\" data-link></a>");
init($link);
window.addEventListener("pagechange", fn);
// when
$link.click();
// then
expect(fn).toBeCalled();
});
it("trigger a page change when clicking on a link with [data-link] attribute - recursive", () => {
// given
const fn = jest.fn();
const $link = createElement("<a href=\"/something\" data-link><div id=\"click-here\">test</div></a>");
init($link);
window.addEventListener("pagechange", fn);
// when
$link.querySelector("#click-here").click();
// then
expect(fn).toBeCalled();
});
it("does nothing when clicking not on a link", () => {
// given
const fn = jest.fn();
const $app = createElement(`<div>
<div id="click-here">test</div>
<a href="/something" data-link></a>
</div>`);
init($app);
window.addEventListener("pagechange", fn);
// when
$app.querySelector("#click-here").click();
// then
expect(fn).not.toBeCalled();
});
});

View file

@ -1,78 +0,0 @@
{
"type": "module",
"name": "Filestash",
"version": "1.0.0",
"description": "Frontend for Filestash",
"main": "index.js",
"scripts": {
"check": "tsc && eslint .",
"test": "npx jest"
},
"author": "Mickael Kerjean",
"license": "AGPL",
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.22.5",
"@babel/preset-env": "^7.22.10",
"@types/jest": "^29.5.3",
"babel-plugin-transform-import-meta": "^2.2.1",
"eslint": "^8.47.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-n": "^16.0.1",
"eslint-plugin-promise": "^6.1.1",
"jest": "^29.6.2",
"jsdom": "^22.1.0"
},
"jest": {
"verbose": true,
"setupFiles": [
"<rootDir>/jest.setup.js"
],
"modulePaths": [
"<rootDir>"
],
"coveragePathIgnorePatterns": [
"vendor"
]
},
"babel": {
"env": {
"test": {
"plugins": [
"@babel/plugin-transform-modules-commonjs",
"babel-plugin-transform-import-meta"
]
}
}
},
"eslintConfig": {
"env": {
"browser": true,
"es2021": true,
"jest": true
},
"ignorePatterns": ["lib/vendor/*.js", "*.test.js"],
"extends": "standard",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"quotes": ["error", "double"],
"indent": ["error", 4],
"semi": ["error", "always"],
"space-before-function-paren": ["error", "never"],
"camelcase": ["off"],
"dot-notation": ["off"],
"no-case-declarations": ["off"],
"no-fallthrough": ["off"],
"prefer-regex-literals": ["off"],
"promise/param-names": ["off"],
"no-return-assign": ["off"],
"brace-style": ["off"],
"no-useless-escape": ["off"],
"comma-dangle": ["off"],
"curly": ["off"]
}
}
}

View file

@ -1,37 +0,0 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noUncheckedIndexedAccess": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strict": false,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"lib": [
"dom",
"dom.iterable",
"es2022"
],
"module": "es2022",
"target": "es2022",
"typeRoots": [
"types/app.d.ts"
]
},
"input": ["pages/ctrl_boot.d.ts", "pages/*.js"],
"exclude": [
"**/*.test.js", "worker/sw_cache.js",
"coverage", "jest.setup.js"
]
}