From 40f575037c7723953ec6e65352fd62a32690e05d Mon Sep 17 00:00:00 2001 From: MickaelK Date: Fri, 20 Oct 2023 20:05:35 +1100 Subject: [PATCH] chore (cleanup): cleanup public folder --- public/README.org | 20 ---- public/boot/ctrl_boot_backoffice.test.js | 26 ----- public/boot/ctrl_boot_frontoffice.test.js | 9 -- public/jest.setup.js | 24 ---- public/lib/skeleton/index.test.js | 131 ---------------------- public/lib/skeleton/router.test.js | 89 --------------- public/package.json | 78 ------------- public/tsconfig.json | 37 ------ 8 files changed, 414 deletions(-) delete mode 100644 public/README.org delete mode 100644 public/boot/ctrl_boot_backoffice.test.js delete mode 100644 public/boot/ctrl_boot_frontoffice.test.js delete mode 100644 public/jest.setup.js delete mode 100644 public/lib/skeleton/index.test.js delete mode 100644 public/lib/skeleton/router.test.js delete mode 100644 public/package.json delete mode 100644 public/tsconfig.json diff --git a/public/README.org b/public/README.org deleted file mode 100644 index cea8e423c..000000000 --- a/public/README.org +++ /dev/null @@ -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 diff --git a/public/boot/ctrl_boot_backoffice.test.js b/public/boot/ctrl_boot_backoffice.test.js deleted file mode 100644 index 3d636f796..000000000 --- a/public/boot/ctrl_boot_backoffice.test.js +++ /dev/null @@ -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__"); - }); -}); diff --git a/public/boot/ctrl_boot_frontoffice.test.js b/public/boot/ctrl_boot_frontoffice.test.js deleted file mode 100644 index ed1147f7b..000000000 --- a/public/boot/ctrl_boot_frontoffice.test.js +++ /dev/null @@ -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); - }); -}); diff --git a/public/jest.setup.js b/public/jest.setup.js deleted file mode 100644 index 01a8c6dec..000000000 --- a/public/jest.setup.js +++ /dev/null @@ -1,24 +0,0 @@ -import { jest } from "@jest/globals"; -import { JSDOM } from "jsdom"; - -global.jest = jest; -global.window = new JSDOM("", { 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(), -}; diff --git a/public/lib/skeleton/index.test.js b/public/lib/skeleton/index.test.js deleted file mode 100644 index ac565e8ae..000000000 --- a/public/lib/skeleton/index.test.js +++ /dev/null @@ -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("

main

") - }; - - // 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("

main

"); - 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("

main

"); - 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("

main

"); - 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("

OK

") - }; - 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"); - }); -}); diff --git a/public/lib/skeleton/router.test.js b/public/lib/skeleton/router.test.js deleted file mode 100644 index 7e182960f..000000000 --- a/public/lib/skeleton/router.test.js +++ /dev/null @@ -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("
")); - 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("
")); - 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(""); - 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("
test
"); - 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(`
-
test
- -
`); - init($app); - window.addEventListener("pagechange", fn); - - // when - $app.querySelector("#click-here").click(); - - // then - expect(fn).not.toBeCalled(); - }); -}); diff --git a/public/package.json b/public/package.json deleted file mode 100644 index 5b0b78310..000000000 --- a/public/package.json +++ /dev/null @@ -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": [ - "/jest.setup.js" - ], - "modulePaths": [ - "" - ], - "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"] - } - } -} diff --git a/public/tsconfig.json b/public/tsconfig.json deleted file mode 100644 index 6e93fd804..000000000 --- a/public/tsconfig.json +++ /dev/null @@ -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" - ] -}