-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4907 from owncloud/tests_and_optimize
Tests and optimize
- Loading branch information
Showing
28 changed files
with
194 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,3 @@ export const loadConfig = async () => { | |
} | ||
return config | ||
} | ||
|
||
export default { | ||
loadConfig: loadConfig | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import defaultTheme from 'web-runtime/themes/owncloud.json' | ||
export const loadTheme = async (name = '') => { | ||
const defaults = { theme: defaultTheme, name: 'themes/owncloud/theme.json' } | ||
|
||
if (name === '' || name === defaults.name) { | ||
return defaults | ||
} | ||
|
||
let response | ||
try { | ||
response = await fetch(name) | ||
} catch (e) { | ||
return defaults | ||
} | ||
|
||
if (!response.ok) { | ||
return defaults | ||
} | ||
|
||
const customTheme = await response.json() | ||
return { theme: customTheme, name } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { loadTheme } from 'web-runtime/src/helpers/theme' | ||
import { merge } from 'lodash' | ||
import defaultTheme from 'web-runtime/themes/owncloud.json' | ||
const defaultName = 'themes/owncloud/theme.json' | ||
|
||
describe('theme loading and error reporting', () => { | ||
it('should load the default theme if no name is given', async () => { | ||
const { theme, name } = await loadTheme() | ||
expect(theme).toMatchObject(defaultTheme) | ||
expect(name).toMatch(defaultName) | ||
}) | ||
|
||
it('should load the default theme if default name is given', async () => { | ||
const { theme, name } = await loadTheme(defaultName) | ||
expect(theme).toMatchObject(defaultTheme) | ||
expect(name).toMatch(defaultName) | ||
}) | ||
|
||
it('should load the default theme if name is unknown', async () => { | ||
fetch.mockResponseOnce(new Error(), { status: 404 }) | ||
const { theme, name } = await loadTheme('unknown.json') | ||
expect(theme).toMatchObject(defaultTheme) | ||
expect(name).toMatch(defaultName) | ||
}) | ||
|
||
it('should load the default theme if server errors', async () => { | ||
fetch.mockRejectOnce(new Error()) | ||
const { theme, name } = await loadTheme('something.json') | ||
expect(theme).toMatchObject(defaultTheme) | ||
expect(name).toMatch(defaultName) | ||
}) | ||
|
||
it('should load the custom theme if a custom name is given', async () => { | ||
const customTheme = merge({}, defaultTheme, { logo: { login: 'custom.svg' } }) | ||
const customName = 'themes/custom/theme.json' | ||
fetch.mockResponseOnce(JSON.stringify(customTheme)) | ||
|
||
const { theme, name } = await loadTheme(customName) | ||
expect(theme).toMatchObject(customTheme) | ||
expect(name).toMatch(customName) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { loadTheme } from 'web-runtime/src/helpers/theme' | ||
import store from 'web-runtime/src/store' | ||
import { keysDeep } from 'web-pkg/src/utils/object' | ||
import get from 'lodash-es/get' | ||
import difference from 'lodash-es/difference' | ||
|
||
describe('config theme bootstrap', () => { | ||
const initialStoreTheme = { ...store.getters.configuration.theme } | ||
|
||
beforeEach(() => { | ||
store.reset() | ||
}) | ||
|
||
it('should be able to loadTheme', async () => { | ||
const { theme, name } = await loadTheme() | ||
|
||
await store.dispatch('loadTheme', { theme, name }) | ||
keysDeep(theme).forEach(k => { | ||
expect(get(store.getters.configuration.theme, k)).toBe(get(theme, k)) | ||
}) | ||
}) | ||
|
||
it('should not overwrite keys that are not part of theme', async () => { | ||
const { theme, name } = await loadTheme() | ||
const storeThemeKeys = keysDeep(store.getters.configuration.theme) | ||
const loadedThemeKeys = keysDeep(theme) | ||
const diffThemeKeys = difference(storeThemeKeys, loadedThemeKeys) | ||
await store.dispatch('loadTheme', { theme, name }) | ||
|
||
diffThemeKeys.forEach(k => { | ||
expect(get(store.getters.configuration.theme, k)).toBe(get(initialStoreTheme, k)) | ||
}) | ||
}) | ||
}) |
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { config } from '@vue/test-utils' | ||
import fetchMock from 'jest-fetch-mock' | ||
|
||
const $gettext = str => str | ||
fetchMock.enableMocks() | ||
|
||
config.mocks = { | ||
$gettext | ||
$gettext: str => str | ||
} |
Oops, something went wrong.