From 183f838e63f9a3f9ca128aa77fccf37150576293 Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Mon, 5 Apr 2021 10:17:56 +0200 Subject: [PATCH] move theme to web-runtime and get it closer where it belongs to extract theme loading into own helper method add test to verify theme loading is working as expected fix theme loading, before it has overwritten the whole theme object, now we respect the values and keys that are set-able. add init step for fetchMock to use mocks in testing by default clean up config test to use global fetch to be able to reset the store in tests we started to use createStore from vuex-extensions which offers a reset method to get back the initial state fine-tune jest to ignore lodash-es which is problematic in some cases introduce web-pkg which provides globally used functionality add and write tests for keysDeep which is similar to lodash keys but deep rename web-runtime Top-Bar component to match style move TopBar tests to web-runtime move web-runtime config to helpers folder move config spec from toplevel to package level bump core-js --- changelog/unreleased/change-introduce-web-pkg | 6 +++ package.json | 5 ++- packages/web-pkg/package.json | 9 ++++ packages/web-pkg/src/utils/object.js | 17 +++++++ packages/web-pkg/tests/utils/object.spec.js | 19 ++++++++ packages/web-runtime/package.json | 2 + packages/web-runtime/src/App.vue | 2 +- .../components/{Top-Bar.vue => TopBar.vue} | 0 .../{configHelper.js => helpers/config.js} | 4 -- packages/web-runtime/src/helpers/theme.js | 22 +++++++++ packages/web-runtime/src/index.js | 8 ++-- packages/web-runtime/src/store/config.js | 3 +- packages/web-runtime/src/store/index.js | 3 +- .../tests/components}/TopBar.spec.js | 12 +++-- .../__snapshots__/TopBar.spec.js.snap | 0 .../web-runtime/tests/helpers/config.spec.js | 13 +++--- .../web-runtime/tests/helpers/theme.spec.js | 42 ++++++++++++++++++ .../web-runtime/tests/store/config.spec.js | 34 ++++++++++++++ .../themes/owncloud.json | 0 .../themes/owncloud/assets/cloud.svg | 0 .../owncloud/assets/loginBackground.jpg | Bin .../themes/owncloud/assets/logo.svg | 0 .../themes/owncloud/favicon.jpg | Bin rollup.config.js | 10 +++-- tests/unit/config/jest.config.js | 1 + tests/unit/config/jest.init.js | 5 ++- tests/unit/config/stubs.js | 4 +- yarn.lock | 15 ++++--- 28 files changed, 194 insertions(+), 42 deletions(-) create mode 100644 changelog/unreleased/change-introduce-web-pkg create mode 100644 packages/web-pkg/package.json create mode 100644 packages/web-pkg/src/utils/object.js create mode 100644 packages/web-pkg/tests/utils/object.spec.js rename packages/web-runtime/src/components/{Top-Bar.vue => TopBar.vue} (100%) rename packages/web-runtime/src/{configHelper.js => helpers/config.js} (88%) create mode 100644 packages/web-runtime/src/helpers/theme.js rename {tests/unit/specs => packages/web-runtime/tests/components}/TopBar.spec.js (91%) rename {tests/unit/specs => packages/web-runtime/tests/components}/__snapshots__/TopBar.spec.js.snap (100%) rename tests/unit/specs/loadConfig.spec.js => packages/web-runtime/tests/helpers/config.spec.js (87%) create mode 100644 packages/web-runtime/tests/helpers/theme.spec.js create mode 100644 packages/web-runtime/tests/store/config.spec.js rename packages/{web-container => web-runtime}/themes/owncloud.json (100%) rename packages/{web-container => web-runtime}/themes/owncloud/assets/cloud.svg (100%) rename packages/{web-container => web-runtime}/themes/owncloud/assets/loginBackground.jpg (100%) rename packages/{web-container => web-runtime}/themes/owncloud/assets/logo.svg (100%) rename packages/{web-container => web-runtime}/themes/owncloud/favicon.jpg (100%) diff --git a/changelog/unreleased/change-introduce-web-pkg b/changelog/unreleased/change-introduce-web-pkg new file mode 100644 index 00000000000..db03d1fa2d4 --- /dev/null +++ b/changelog/unreleased/change-introduce-web-pkg @@ -0,0 +1,6 @@ +Change: Add web-pkg package + +We added web-pkg as a new package. +It is supposed to be the central location for reuse of generic functionality. + +https://github.com/owncloud/web/pull/4907 diff --git a/package.json b/package.json index 2e1a3daa034..8145ec253f5 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "packages/web-app-files", "packages/web-app-markdown-editor", "packages/web-app-media-viewer", + "packages/web-pkg", "packages/web-runtime" ], "scripts": { @@ -45,7 +46,7 @@ "babel-eslint": "^10.1.0", "babel-jest": "^26.6.3", "chromedriver": "^89.0.0", - "core-js": "3", + "core-js": "^3.10.0", "cucumber": ">=6.0.5", "cucumber-pretty": ">=6.0.0", "depcheck": "^1.3.1", @@ -80,13 +81,13 @@ "rollup-plugin-copy-watch": "^0.0.1", "rollup-plugin-delete": "^2.0.0", "rollup-plugin-gzip": "^2.5.0", + "rollup-plugin-livereload": "^2.0.0", "rollup-plugin-modify": "^3.0.0", "rollup-plugin-node-globals": "^1.4.0", "rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-progress": "^1.1.2", "rollup-plugin-serve": "^1.1.0", - "rollup-plugin-livereload": "^2.0.0", "rollup-plugin-terser": "^7.0.2", "rollup-plugin-visualizer": "^4.2.0", "rollup-plugin-vue": "^5.1.4", diff --git a/packages/web-pkg/package.json b/packages/web-pkg/package.json new file mode 100644 index 00000000000..433a74e99cd --- /dev/null +++ b/packages/web-pkg/package.json @@ -0,0 +1,9 @@ +{ + "name": "web-pkg", + "version": "0.0.0", + "description": "ownCloud web pkg", + "license": "AGPL-3.0", + "devDependencies": { + "lodash-es": "^4.17.20" + } +} diff --git a/packages/web-pkg/src/utils/object.js b/packages/web-pkg/src/utils/object.js new file mode 100644 index 00000000000..7c6ab1d69cf --- /dev/null +++ b/packages/web-pkg/src/utils/object.js @@ -0,0 +1,17 @@ +import { isPlainObject } from 'lodash' + +export const keysDeep = obj => { + const paths = [] + + const walk = (o, p = '') => + Object.keys(o).forEach(key => { + if (isPlainObject(o[key])) { + walk(o[key], `${p}${key}.`) + } else { + paths.push(`${p}${key}`) + } + }) + + walk(obj) + return paths +} diff --git a/packages/web-pkg/tests/utils/object.spec.js b/packages/web-pkg/tests/utils/object.spec.js new file mode 100644 index 00000000000..ab442b92874 --- /dev/null +++ b/packages/web-pkg/tests/utils/object.spec.js @@ -0,0 +1,19 @@ +import { keysDeep } from 'web-pkg/src/utils/object' + +describe('keysDeep', () => { + it('should return the correct keys', () => { + expect( + keysDeep({ + foo1: { bar1: { baz1: 1, baz2: 1 }, bar2: { baz1: 1, baz2: 1 }, bar3: 1 }, + foo2: 1 + }) + ).toMatchObject([ + 'foo1.bar1.baz1', + 'foo1.bar1.baz2', + 'foo1.bar2.baz1', + 'foo1.bar2.baz2', + 'foo1.bar3', + 'foo2' + ]) + }) +}) diff --git a/packages/web-runtime/package.json b/packages/web-runtime/package.json index cf253d18165..834d2d22c25 100644 --- a/packages/web-runtime/package.json +++ b/packages/web-runtime/package.json @@ -23,8 +23,10 @@ "vue-scrollto": "^2.15.0", "vue2-touch-events": "^2.2.1", "vuex": "^3.1.1", + "vuex-extensions": "^1.1.5", "vuex-persist": "2.0.1", "vuex-router-sync": "^5.0.0", + "web-pkg": "*", "wicked-good-xpath": "^1.3.0" } } diff --git a/packages/web-runtime/src/App.vue b/packages/web-runtime/src/App.vue index d250a99161c..8cd3d65ad04 100644 --- a/packages/web-runtime/src/App.vue +++ b/packages/web-runtime/src/App.vue @@ -85,7 +85,7 @@