Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ad946dd7e
|
||
|
|
203d222dc9
|
||
|
|
636f3c4be8
|
||
|
|
977560ae7c
|
||
|
|
05cf1df307
|
||
|
|
c48b610e7a
|
||
|
|
f4f8993e87
|
||
|
|
31588b2f1c
|
||
|
|
e964c2635f
|
||
|
|
0fe98bb03d
|
||
|
|
134fdabffc
|
||
|
|
788bea0016
|
||
|
|
b571a68e3b
|
||
|
|
d5f6108f47
|
||
|
|
3dd9eded41
|
||
|
|
8f44609702
|
||
|
|
5dc3ddd549
|
||
|
|
f739676a1a
|
||
|
|
f73e2edae7
|
||
|
|
f7358ceb34
|
||
|
|
f8d2086433
|
||
|
|
7613122658
|
||
|
|
b27c89945f
|
||
|
|
d9ed16f3de
|
||
|
|
4c39fadd9a
|
||
|
|
dccdab0d4a
|
||
|
|
f6cf1e9777
|
||
|
|
53bd67b7a0
|
||
|
|
1f51a0b3ae
|
||
|
|
bcb0c05d74
|
||
|
|
069b75b3c5
|
||
|
|
589be2a5bc
|
||
|
|
287f02505e
|
||
|
|
ad6f59a85c
|
||
|
|
f9a53a8911
|
||
|
|
f485a2d476
|
||
|
|
dde56c42ae
|
||
|
|
15697144b1
|
||
|
|
396c025ec4
|
||
|
|
30f6b82416
|
||
|
|
7b09cd74cb
|
||
|
|
fab7d7e901
|
||
|
|
04c148a3b1
|
||
|
|
ff6ab7a78c
|
||
|
|
294fdab550
|
||
|
|
26eec92f42
|
||
|
|
a01abe67e1
|
||
|
|
3eaf81a465
|
||
|
|
2addd779a7
|
||
|
|
6afbf3efed
|
||
|
|
dca7f2176b
|
||
|
|
60d3296816
|
||
|
|
b0642cc826
|
||
|
|
32555d9acb
|
@@ -42,4 +42,4 @@ jobs:
|
|||||||
|
|
||||||
printf "Update current build pointer ... "
|
printf "Update current build pointer ... "
|
||||||
echo "$BUILD_ID" | mc pipe "minio/$BUCKET/current"
|
echo "$BUILD_ID" | mc pipe "minio/$BUCKET/current"
|
||||||
echo "done"
|
echo "done"
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
.vscode/
|
.vscode/
|
||||||
node_modules/
|
node_modules/
|
||||||
dist/
|
dist/
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ This software is provided "as is", without warranty of any kind.
|
|||||||
This software uses the Vue.js framework.
|
This software uses the Vue.js framework.
|
||||||
|
|
||||||
This software makes use of various open-source components.
|
This software makes use of various open-source components.
|
||||||
See THIRD_PARTY_LICENSES for details.
|
See THIRD_PARTY_LICENSES for details.
|
||||||
|
|||||||
@@ -8,4 +8,4 @@ Please execute the setup script in `scripts/` for your platform when cloning the
|
|||||||
|
|
||||||
## Legal
|
## Legal
|
||||||
|
|
||||||
After each update to the dependencies, please run the script `scripts/generate-license-files.js` to regenerate the third-party license files.
|
After each update to the dependencies, please run the script `scripts/generate-license-files.js` to regenerate the third-party license files.
|
||||||
|
|||||||
@@ -13,4 +13,4 @@
|
|||||||
- Internationalization and some major languages
|
- Internationalization and some major languages
|
||||||
- Color scheme
|
- Color scheme
|
||||||
- Search results view with error message which indicates that the search is not available
|
- Search results view with error message which indicates that the search is not available
|
||||||
- Settings renderer
|
- Settings renderer
|
||||||
|
|||||||
@@ -21,8 +21,42 @@ limitations under the License.
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta name="theme-color" content="#0158D2" />
|
<meta name="theme-color" content="#0158D2" />
|
||||||
<title>Seekra</title>
|
<title>Seekra</title>
|
||||||
|
<noscript>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #000;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</noscript>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<noscript>
|
||||||
|
<h1>
|
||||||
|
Seekra
|
||||||
|
</h1>
|
||||||
|
<p>
|
||||||
|
You need to enable JavaScript to use Seekra.
|
||||||
|
</p>
|
||||||
|
<section>
|
||||||
|
<h2>Legal Content</h2>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://assets.seekra.jcloud-services.ddns.net/2026-08-04-76a067e/legal/legal_notice.html">
|
||||||
|
Legal Notice
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
</noscript>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script type="module" src="/src/main.js"></script>
|
<script type="module" src="/src/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -4,4 +4,4 @@
|
|||||||
"@/*": ["./src/*"]
|
"@/*": ["./src/*"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,4 +55,4 @@ await generateLicenseFile(
|
|||||||
'./THIRD_PARTY_LICENSES_DEV'
|
'./THIRD_PARTY_LICENSES_DEV'
|
||||||
);
|
);
|
||||||
|
|
||||||
await fs.rename(packageJsonBackup, packageJson);
|
await fs.rename(packageJsonBackup, packageJson);
|
||||||
|
|||||||
@@ -14,4 +14,4 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
git config --local commit.template .gitmessage
|
git config --local commit.template .gitmessage
|
||||||
|
|||||||
@@ -14,4 +14,4 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
git config --local commit.template .gitmessage
|
git config --local commit.template .gitmessage
|
||||||
|
|||||||
@@ -18,36 +18,45 @@ limitations under the License.
|
|||||||
import Navbar from './features/nav/components/Navbar.vue';
|
import Navbar from './features/nav/components/Navbar.vue';
|
||||||
import Footer from './features/footer/components/Footer.vue';
|
import Footer from './features/footer/components/Footer.vue';
|
||||||
|
|
||||||
|
import { LANGUAGE_PATH } from './config/featureSettings.js';
|
||||||
import { updatePageTitle } from './router';
|
import { updatePageTitle } from './router';
|
||||||
import { useColorScheme } from './features/colorScheme/composables/useColorScheme';
|
import { useSettings } from './features/settings/composables/useSettings.js';
|
||||||
import { ref, provide, watch, watchEffect } from 'vue';
|
import { setLocale } from './i18n';
|
||||||
|
import { computed, onMounted, watch, watchEffect } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
const { getColorScheme, updateColorScheme } = useColorScheme();
|
const { getSetting } = useSettings();
|
||||||
const colorScheme = ref(getColorScheme());
|
const colorScheme = computed(() => getSetting(['appearance', 'colorScheme']));
|
||||||
provide('colorScheme', colorScheme);
|
|
||||||
watch(colorScheme, (newValue) => {
|
const updateColorScheme = function updateColorScheme (newColorScheme) {
|
||||||
updateColorScheme(newValue);
|
|
||||||
document.body.style.setProperty(colorScheme, {
|
document.body.style.setProperty(colorScheme, {
|
||||||
auto: 'normal',
|
auto: 'normal',
|
||||||
dark: 'dark',
|
dark: 'dark',
|
||||||
light: 'light'
|
light: 'light'
|
||||||
});
|
});
|
||||||
if (newValue === 'dark') {
|
if (newColorScheme === 'dark') {
|
||||||
document.body.classList.add('dark');
|
document.body.classList.add('dark');
|
||||||
} else {
|
} else {
|
||||||
document.body.classList.remove('dark');
|
document.body.classList.remove('dark');
|
||||||
}
|
}
|
||||||
if (newValue === 'auto') {
|
if (newColorScheme === 'auto') {
|
||||||
document.body.classList.add('color-scheme-auto');
|
document.body.classList.add('color-scheme-auto');
|
||||||
} else {
|
} else {
|
||||||
document.body.classList.remove('color-scheme-auto');
|
document.body.classList.remove('color-scheme-auto');
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
watch(colorScheme, (newColorScheme) => {
|
||||||
|
updateColorScheme(newColorScheme);
|
||||||
});
|
});
|
||||||
|
updateColorScheme(colorScheme.value);
|
||||||
|
|
||||||
watchEffect(() => updatePageTitle(route));
|
watchEffect(() => updatePageTitle(route));
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
setLocale(getSetting(LANGUAGE_PATH));
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -81,4 +90,4 @@ watchEffect(() => updatePageTitle(route));
|
|||||||
--main-content-padding-x: 15px;
|
--main-content-padding-x: 15px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -23,4 +23,4 @@ limitations under the License.
|
|||||||
stroke-linejoin="round"
|
stroke-linejoin="round"
|
||||||
d="M5 12 l6 8 l8 -16"
|
d="M5 12 l6 8 l8 -16"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 832 B After Width: | Height: | Size: 833 B |
@@ -23,4 +23,4 @@ limitations under the License.
|
|||||||
stroke-linejoin="round"
|
stroke-linejoin="round"
|
||||||
d="M4 8 l8 8 l8 -8"
|
d="M4 8 l8 8 l8 -8"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 830 B After Width: | Height: | Size: 831 B |
@@ -23,4 +23,4 @@ limitations under the License.
|
|||||||
stroke-linejoin="round"
|
stroke-linejoin="round"
|
||||||
d="M8 20 l8 -8 l-8 -8"
|
d="M8 20 l8 -8 l-8 -8"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 833 B After Width: | Height: | Size: 834 B |
@@ -35,4 +35,4 @@ limitations under the License.
|
|||||||
a9 9 0 0 0 -9 -9
|
a9 9 0 0 0 -9 -9
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
@@ -33,4 +33,4 @@ limitations under the License.
|
|||||||
c-2.140625 4.351562000000001 -6.480468999999999 7.058593000000002 -11.328125 7.058593000000002
|
c-2.140625 4.351562000000001 -6.480468999999999 7.058593000000002 -11.328125 7.058593000000002
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
@@ -33,4 +33,4 @@ limitations under the License.
|
|||||||
cy="8.5"
|
cy="8.5"
|
||||||
r="6.5"
|
r="6.5"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
@@ -35,4 +35,4 @@ limitations under the License.
|
|||||||
v16
|
v16
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
@@ -42,4 +42,4 @@ limitations under the License.
|
|||||||
|
|
||||||
<!-- bottom right -->
|
<!-- bottom right -->
|
||||||
<circle fill="currentColor" r="2" cx="18.36396103067893" cy="18.36396103067893" />
|
<circle fill="currentColor" r="2" cx="18.36396103067893" cy="18.36396103067893" />
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
@@ -16,4 +16,4 @@ limitations under the License.
|
|||||||
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="758.75" height="192.5">
|
<svg xmlns="http://www.w3.org/2000/svg" width="758.75" height="192.5">
|
||||||
<defs><linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="0%"><stop offset="0%" style="stop-color:#4ba8eb"/><stop offset="100%" style="stop-color:#043485"/></linearGradient></defs>
|
<defs><linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="0%"><stop offset="0%" style="stop-color:#4ba8eb"/><stop offset="100%" style="stop-color:#043485"/></linearGradient></defs>
|
||||||
<path stroke="url(#gradient)" stroke-width="15" fill="none" d=" M94 51 a43.75 43.75 0 0 0 -43.75 -43.75 a43.75 43.75 0 0 0 -43.75 43.75 a43.75 43.75 0 0 0 43.75 43.75 a43.75 43.75 0 0 1 43.75 43.75 a43.75 43.75 0 0 1 -43.75 43.75 a43.75 43.75 0 0 1 -43.75 -43.75 M138.75 95.25 h43.75 a43.75 43.75 0 0 0 43.75 -43.75 a43.75 43.75 0 0 0 -43.75 -43.75 a43.75 43.75 0 0 0 -43.75 43.75 v43.75 v43.75 a43.75 43.75 0 0 0 43.75 43.75 a43.75 43.75 0 0 0 43.75 -43.75 M270 95.25 h43.75 a43.75 43.75 0 0 0 43.75 -43.75 a43.75 43.75 0 0 0 -43.75 -43.75 a43.75 43.75 0 0 0 -43.75 43.75 v43.75 v43.75 a43.75 43.75 0 0 0 43.75 43.75 a43.75 43.75 0 0 0 43.75 -43.75 M401.25 0 v192.5 m0 -96.125 l87.5 -87.5 m-87.5 87.5 l87.5 87.5 M532.5 192.5 v-192.5 m0 51.25 a43.75 43.75 0 0 1 43.75 -43.75 a43.75 43.75 0 0 1 43.75 43.75 M663.75 50.25 a43.75 43.75 0 0 1 43.75 -43.75 a43.75 43.75 0 0 1 43.75 43.75 v43.75 v43.75 v43.75 m0 -43.75 a43.75 43.75 0 0 1 -43.75 43.75 a43.75 43.75 0 0 1 -43.75 -43.75 a43.75 43.75 0 0 1 43.75 -43.75 a43.75 43.75 0 0 1 43.75 43.75 v50"/></svg>
|
<path stroke="url(#gradient)" stroke-width="15" fill="none" d=" M94 51 a43.75 43.75 0 0 0 -43.75 -43.75 a43.75 43.75 0 0 0 -43.75 43.75 a43.75 43.75 0 0 0 43.75 43.75 a43.75 43.75 0 0 1 43.75 43.75 a43.75 43.75 0 0 1 -43.75 43.75 a43.75 43.75 0 0 1 -43.75 -43.75 M138.75 95.25 h43.75 a43.75 43.75 0 0 0 43.75 -43.75 a43.75 43.75 0 0 0 -43.75 -43.75 a43.75 43.75 0 0 0 -43.75 43.75 v43.75 v43.75 a43.75 43.75 0 0 0 43.75 43.75 a43.75 43.75 0 0 0 43.75 -43.75 M270 95.25 h43.75 a43.75 43.75 0 0 0 43.75 -43.75 a43.75 43.75 0 0 0 -43.75 -43.75 a43.75 43.75 0 0 0 -43.75 43.75 v43.75 v43.75 a43.75 43.75 0 0 0 43.75 43.75 a43.75 43.75 0 0 0 43.75 -43.75 M401.25 0 v192.5 m0 -96.125 l87.5 -87.5 m-87.5 87.5 l87.5 87.5 M532.5 192.5 v-192.5 m0 51.25 a43.75 43.75 0 0 1 43.75 -43.75 a43.75 43.75 0 0 1 43.75 43.75 M663.75 50.25 a43.75 43.75 0 0 1 43.75 -43.75 a43.75 43.75 0 0 1 43.75 43.75 v43.75 v43.75 v43.75 m0 -43.75 a43.75 43.75 0 0 1 -43.75 43.75 a43.75 43.75 0 0 1 -43.75 -43.75 a43.75 43.75 0 0 1 43.75 -43.75 a43.75 43.75 0 0 1 43.75 43.75 v50"/></svg>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2026 Seekra
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const LANGUAGE_PATH = ['general', 'language'];
|
||||||
@@ -17,12 +17,14 @@ limitations under the License.
|
|||||||
<script setup>
|
<script setup>
|
||||||
import Icon from '@/features/icons/components/Icon.vue';
|
import Icon from '@/features/icons/components/Icon.vue';
|
||||||
|
|
||||||
import { inject } from 'vue';
|
import { useSettings } from '@/features/settings/composables/useSettings';
|
||||||
|
import { computed } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const { getSetting, setSetting } = useSettings();
|
||||||
|
|
||||||
const colorScheme = inject('colorScheme');
|
const colorScheme = computed(() => getSetting(['appearance', 'colorScheme']));
|
||||||
|
|
||||||
const colorSchemeNextMapper = {
|
const colorSchemeNextMapper = {
|
||||||
'light': 'dark',
|
'light': 'dark',
|
||||||
@@ -39,11 +41,15 @@ const colorSchemeIconMapper = {
|
|||||||
const getTooltipTranslation = function (colorScheme) {
|
const getTooltipTranslation = function (colorScheme) {
|
||||||
return t(`preferences.colorScheme.switch.${colorSchemeNextMapper[colorScheme]}`);
|
return t(`preferences.colorScheme.switch.${colorSchemeNextMapper[colorScheme]}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setColorScheme = function setColorScheme (newColorScheme) {
|
||||||
|
setSetting(['appearance', 'colorScheme'], newColorScheme);
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<button class="color-scheme-button"
|
<button class="color-scheme-button"
|
||||||
@click="colorScheme = colorSchemeNextMapper[colorScheme]"
|
@click="setColorScheme(colorSchemeNextMapper[colorScheme])"
|
||||||
:aria-label="getTooltipTranslation(colorScheme)"
|
:aria-label="getTooltipTranslation(colorScheme)"
|
||||||
:title="getTooltipTranslation(colorScheme)"
|
:title="getTooltipTranslation(colorScheme)"
|
||||||
>
|
>
|
||||||
@@ -72,4 +78,4 @@ const getTooltipTranslation = function (colorScheme) {
|
|||||||
.color-scheme-button:hover {
|
.color-scheme-button:hover {
|
||||||
background: var(--light-hover);
|
background: var(--light-hover);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2026 Seekra
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import ColorSchemeButton from '../ColorSchemeButton.vue';
|
||||||
|
import { useSettings } from '@/features/settings/composables/useSettings.js';
|
||||||
|
import { mountComponent } from '@/test-utils/mountComponent';
|
||||||
|
import { describe, expect, test } from 'vitest';
|
||||||
|
|
||||||
|
const { getSetting } = useSettings();
|
||||||
|
|
||||||
|
const colorSchemeSettingPath = ['appearance', 'colorScheme'];
|
||||||
|
|
||||||
|
const getWrapper = function getWrapper () {
|
||||||
|
return mountComponent(ColorSchemeButton);
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('ColorSchemeButton', () => {
|
||||||
|
test('sets color scheme setting', async () => {
|
||||||
|
const wrapper = getWrapper();
|
||||||
|
|
||||||
|
expect(getSetting(colorSchemeSettingPath)).toBe('auto');
|
||||||
|
|
||||||
|
const colorSchemeButton = wrapper.find('button');
|
||||||
|
|
||||||
|
await colorSchemeButton.trigger('click');
|
||||||
|
expect(getSetting(colorSchemeSettingPath)).toBe('light');
|
||||||
|
|
||||||
|
await colorSchemeButton.trigger('click');
|
||||||
|
expect(getSetting(colorSchemeSettingPath)).toBe('dark');
|
||||||
|
|
||||||
|
await colorSchemeButton.trigger('click');
|
||||||
|
expect(getSetting(colorSchemeSettingPath)).toBe('auto');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2026 Seekra
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export const useColorScheme = function () {
|
|
||||||
const getColorScheme = function () {
|
|
||||||
let colorScheme = localStorage.getItem('colorScheme') || 'auto';
|
|
||||||
if (!(colorScheme === 'dark' || colorScheme === 'light' || colorScheme === 'auto')) {
|
|
||||||
colorScheme = 'auto';
|
|
||||||
};
|
|
||||||
return colorScheme;
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateColorScheme = function (newScheme) {
|
|
||||||
let actualNewScheme = newScheme;
|
|
||||||
if (!(actualNewScheme === 'dark' || actualNewScheme === 'light' || actualNewScheme === 'auto')) {
|
|
||||||
actualNewScheme = 'auto';
|
|
||||||
};
|
|
||||||
|
|
||||||
localStorage.setItem('colorScheme', actualNewScheme);
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
getColorScheme,
|
|
||||||
updateColorScheme
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -21,13 +21,13 @@ import { useI18n } from 'vue-i18n';
|
|||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
const startYear = 2026
|
const startYear = 2026;
|
||||||
const currentYear = new Date().getFullYear()
|
const currentYear = new Date().getFullYear();
|
||||||
|
|
||||||
const copyrightPeriod =
|
const copyrightPeriod =
|
||||||
startYear === currentYear
|
startYear === currentYear
|
||||||
? `${currentYear}`
|
? `${currentYear}`
|
||||||
: `${startYear}-${currentYear}`
|
: `${startYear}-${currentYear}`;
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@@ -40,8 +40,20 @@ const copyrightPeriod =
|
|||||||
</RouterLink>
|
</RouterLink>
|
||||||
<LanguageSwitchButton />
|
<LanguageSwitchButton />
|
||||||
</div>
|
</div>
|
||||||
<div class="footer-segment">
|
<div class="footer-segment legal-segment">
|
||||||
© {{ copyrightPeriod }} Seekra
|
<div></div>
|
||||||
|
<div class="copyright-notice">
|
||||||
|
© {{ copyrightPeriod }} Seekra
|
||||||
|
</div>
|
||||||
|
<div class="legal-links">
|
||||||
|
<RouterLink
|
||||||
|
:to="{ name: 'legalNotice' }"
|
||||||
|
class="link"
|
||||||
|
:title="t('legal.notice.title')"
|
||||||
|
>
|
||||||
|
{{ t('legal.notice.title') }}
|
||||||
|
</RouterLink>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
</template>
|
</template>
|
||||||
@@ -54,6 +66,7 @@ const copyrightPeriod =
|
|||||||
.footer-segment {
|
.footer-segment {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
gap: 32px;
|
gap: 32px;
|
||||||
padding: var(--padding-y);
|
padding: var(--padding-y);
|
||||||
background-color: var(--light-bg);
|
background-color: var(--light-bg);
|
||||||
@@ -63,4 +76,31 @@ const copyrightPeriod =
|
|||||||
.global-footer a {
|
.global-footer a {
|
||||||
color: var(--dark);
|
color: var(--dark);
|
||||||
}
|
}
|
||||||
</style>
|
|
||||||
|
.legal-segment {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr auto 1fr;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.copyright-notice {
|
||||||
|
justify-self: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legal-links {
|
||||||
|
justify-self: end;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 48rem) {
|
||||||
|
.legal-segment {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legal-links {
|
||||||
|
margin-top: 0.8em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -17,29 +17,31 @@ limitations under the License.
|
|||||||
<script setup>
|
<script setup>
|
||||||
import Icon from '@/features/icons/components/Icon.vue';
|
import Icon from '@/features/icons/components/Icon.vue';
|
||||||
|
|
||||||
import { ref } from 'vue';
|
import { LANGUAGE_PATH } from '@/config/featureSettings';
|
||||||
|
import { useSettings } from '@/features/settings/composables/useSettings';
|
||||||
|
import { ref, watch } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { loadLanguage, LANGUAGES_RTL, SUPPORTED_LANGUAGES } from '@/i18n';
|
import { setLocale, SUPPORTED_LANGUAGES } from '@/i18n';
|
||||||
|
|
||||||
const { t, locale } = useI18n();
|
const { t, locale } = useI18n();
|
||||||
|
const { setSetting, getSetting } = useSettings();
|
||||||
|
|
||||||
const isOpen = ref(false);
|
const isOpen = ref(false);
|
||||||
const languageDropdown = ref(null);
|
const languageDropdown = ref(null);
|
||||||
|
|
||||||
async function selectLanguage(code) {
|
const selectLanguage = function selectLanguage (code) {
|
||||||
await loadLanguage(code);
|
setSetting(LANGUAGE_PATH, code);
|
||||||
localStorage.setItem('locale', code);
|
|
||||||
document.documentElement.lang = code;
|
|
||||||
document.documentElement.dir = LANGUAGES_RTL.includes(code) ? 'rtl' : 'ltr';
|
|
||||||
close();
|
close();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
watch(() => getSetting(LANGUAGE_PATH), setLocale);
|
||||||
|
|
||||||
const close = function () {
|
const close = function () {
|
||||||
document.removeEventListener('click', closeWrapperOnClickOutsite);
|
document.removeEventListener('click', closeWrapperOnClickOutside);
|
||||||
isOpen.value = false;
|
isOpen.value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeWrapperOnClickOutsite = function (e) {
|
const closeWrapperOnClickOutside = function (e) {
|
||||||
if (languageDropdown.value) {
|
if (languageDropdown.value) {
|
||||||
if (!languageDropdown.value.contains(e.target)) {
|
if (!languageDropdown.value.contains(e.target)) {
|
||||||
close();
|
close();
|
||||||
@@ -51,7 +53,7 @@ const open = function () {
|
|||||||
if (!isOpen.value) {
|
if (!isOpen.value) {
|
||||||
isOpen.value = true;
|
isOpen.value = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
document.addEventListener('click', closeWrapperOnClickOutsite);
|
document.addEventListener('click', closeWrapperOnClickOutside);
|
||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -161,4 +163,4 @@ const open = function () {
|
|||||||
.flag {
|
.flag {
|
||||||
font-size: 1.1rem;
|
font-size: 1.1rem;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -14,84 +14,57 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { expect, test, describe, vi, beforeEach } from 'vitest';
|
import { LANGUAGE_PATH } from '@/config/featureSettings.js';
|
||||||
import { mount } from '@vue/test-utils';
|
import { useSettings } from '@/features/settings/composables/useSettings.js';
|
||||||
|
import { mountComponent } from '@/test-utils/mountComponent.js';
|
||||||
|
import { expect, test, describe } from 'vitest';
|
||||||
import LanguageSwitchButton from '../LanguageSwitchButton.vue';
|
import LanguageSwitchButton from '../LanguageSwitchButton.vue';
|
||||||
import { loadLanguage } from '@/i18n';
|
|
||||||
|
|
||||||
vi.mock('@/i18n', () => ({
|
const getWrapper = function getWrapper () {
|
||||||
loadLanguage: vi.fn(() => Promise.resolve()),
|
return mountComponent(LanguageSwitchButton);
|
||||||
LANGUAGES_RTL: ['ar', 'he'],
|
};
|
||||||
SUPPORTED_LANGUAGES: ['en', 'de', 'ar']
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock('vue-i18n', () => ({
|
|
||||||
useI18n: () => ({
|
|
||||||
t: (key) => key,
|
|
||||||
locale: { value: 'de' }
|
|
||||||
})
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock('@/features/icons/components/Icon.vue', () => ({
|
|
||||||
default: {
|
|
||||||
name: 'Icon',
|
|
||||||
template: '<span>Icon</span>'
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('LanguageSwitchButton', () => {
|
describe('LanguageSwitchButton', () => {
|
||||||
beforeEach(() => {
|
|
||||||
vi.clearAllMocks();
|
|
||||||
localStorage.clear();
|
|
||||||
document.documentElement.lang = '';
|
|
||||||
document.documentElement.dir = '';
|
|
||||||
});
|
|
||||||
|
|
||||||
test('renders correctly with initial state closed', () => {
|
test('renders correctly with initial state closed', () => {
|
||||||
const wrapper = mount(LanguageSwitchButton);
|
const wrapper = getWrapper();
|
||||||
|
|
||||||
expect(wrapper.find('.language-button').exists()).toBe(true);
|
expect(wrapper.find('.language-button').exists()).toBe(true);
|
||||||
expect(wrapper.find('.language-dropdown').exists()).toBe(false);
|
expect(wrapper.find('.language-dropdown').exists()).toBe(false);
|
||||||
expect(wrapper.find('.language-button').attributes('aria-expanded')).toBe('false');
|
expect(wrapper.find('.language-button').attributes('aria-expanded')).toBe('false');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('opens the dropdown when language button is clicked', async () => {
|
test('opens the dropdown when language button is clicked', async () => {
|
||||||
const wrapper = mount(LanguageSwitchButton);
|
const wrapper = getWrapper();
|
||||||
const button = wrapper.find('.language-button');
|
const button = wrapper.find('.language-button');
|
||||||
|
|
||||||
await button.trigger('click');
|
await button.trigger('click');
|
||||||
|
|
||||||
expect(wrapper.find('.language-dropdown').exists()).toBe(true);
|
expect(wrapper.find('.language-dropdown').exists()).toBe(true);
|
||||||
expect(button.attributes('aria-expanded')).toBe('true');
|
expect(button.attributes('aria-expanded')).toBe('true');
|
||||||
});
|
});
|
||||||
|
|
||||||
const languageTestCases = [
|
test('sets the language when clicking it', async () => {
|
||||||
{ code: 'en', expectedDir: 'ltr' },
|
const { getSetting } = useSettings();
|
||||||
{ code: 'de', expectedDir: 'ltr' },
|
|
||||||
{ code: 'ar', expectedDir: 'rtl' }
|
const wrapper = getWrapper();
|
||||||
];
|
|
||||||
|
|
||||||
test.for(languageTestCases)('selectLanguage($code) sets localStorage, html attributes and changes layout direction to $expectedDir', async ({ code, expectedDir }) => {
|
|
||||||
const wrapper = mount(LanguageSwitchButton);
|
|
||||||
|
|
||||||
await wrapper.find('.language-button').trigger('click');
|
await wrapper.find('.language-button').trigger('click');
|
||||||
|
|
||||||
const options = wrapper.findAll('.language-dropdown li');
|
|
||||||
const optionToClick = options.find(opt => opt.text().includes(code));
|
|
||||||
|
|
||||||
await optionToClick.trigger('click');
|
|
||||||
|
|
||||||
expect(loadLanguage).toHaveBeenCalledWith(code);
|
const options = wrapper.findAll('.language-dropdown li');
|
||||||
expect(localStorage.getItem('locale')).toBe(code);
|
|
||||||
expect(document.documentElement.lang).toBe(code);
|
const enOption = options.find(opt => opt.text().includes('en'));
|
||||||
expect(document.documentElement.dir).toBe(expectedDir);
|
await enOption.trigger('click');
|
||||||
|
expect(getSetting(LANGUAGE_PATH)).toBe('en');
|
||||||
|
expect(wrapper.find('.language-dropdown').exists()).toBe(false);
|
||||||
|
|
||||||
|
const deOption = options.find(opt => opt.text().includes('de'));
|
||||||
|
await deOption.trigger('click');
|
||||||
|
expect(getSetting(LANGUAGE_PATH)).toBe('de');
|
||||||
expect(wrapper.find('.language-dropdown').exists()).toBe(false);
|
expect(wrapper.find('.language-dropdown').exists()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('closes the dropdown when clicking outside the component', async () => {
|
test('closes the dropdown when clicking outside the component', async () => {
|
||||||
const wrapper = mount(LanguageSwitchButton, {
|
const wrapper = getWrapper();
|
||||||
attachTo: document.body
|
|
||||||
});
|
|
||||||
|
|
||||||
await wrapper.find('.language-button').trigger('click');
|
await wrapper.find('.language-button').trigger('click');
|
||||||
expect(wrapper.find('.language-dropdown').exists()).toBe(true);
|
expect(wrapper.find('.language-dropdown').exists()).toBe(true);
|
||||||
@@ -100,10 +73,10 @@ describe('LanguageSwitchButton', () => {
|
|||||||
|
|
||||||
const externalDiv = document.createElement('div');
|
const externalDiv = document.createElement('div');
|
||||||
document.body.appendChild(externalDiv);
|
document.body.appendChild(externalDiv);
|
||||||
|
|
||||||
const clickEvent = new MouseEvent('click', { bubbles: true });
|
const clickEvent = new MouseEvent('click', { bubbles: true });
|
||||||
externalDiv.dispatchEvent(clickEvent);
|
externalDiv.dispatchEvent(clickEvent);
|
||||||
|
|
||||||
await wrapper.vm.$nextTick();
|
await wrapper.vm.$nextTick();
|
||||||
|
|
||||||
expect(wrapper.find('.language-dropdown').exists()).toBe(false);
|
expect(wrapper.find('.language-dropdown').exists()).toBe(false);
|
||||||
@@ -111,4 +84,4 @@ describe('LanguageSwitchButton', () => {
|
|||||||
wrapper.unmount();
|
wrapper.unmount();
|
||||||
externalDiv.remove();
|
externalDiv.remove();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2026 Seekra
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { getNavigatorLanguage } from '../navigatorLanguage';
|
||||||
|
import { describe, expect, test } from 'vitest';
|
||||||
|
|
||||||
|
describe('navigatorLanguage', () => {
|
||||||
|
test.for([
|
||||||
|
{ navigatorLanguage: 'en', expected: 'en'},
|
||||||
|
{ navigatorLanguage: 'de', expected: 'de'},
|
||||||
|
{ navigatorLanguage: 'fr', expected: 'fr'},
|
||||||
|
|
||||||
|
{ navigatorLanguage: 'en-US', expected: 'en'},
|
||||||
|
{ navigatorLanguage: 'en-AU', expected: 'en'},
|
||||||
|
{ navigatorLanguage: 'de-DE', expected: 'de'},
|
||||||
|
{ navigatorLanguage: 'fr-FR', expected: 'fr'},
|
||||||
|
|
||||||
|
{ navigatorLanguage: 'en-us', expected: 'en'},
|
||||||
|
{ navigatorLanguage: 'en-au', expected: 'en'},
|
||||||
|
{ navigatorLanguage: 'de-de', expected: 'de'},
|
||||||
|
{ navigatorLanguage: 'fr-fr', expected: 'fr'},
|
||||||
|
|
||||||
|
{ navigatorLanguage: 'zh-Hans-CN', expected: 'zh'},
|
||||||
|
{ navigatorLanguage: 'zh-Hant-TW', expected: 'zh'},
|
||||||
|
{ navigatorLanguage: 'uz-Latn-UZ', expected: 'uz'},
|
||||||
|
|
||||||
|
{ navigatorLanguage: 'en-US-u-ca-gregory', expected: 'en'},
|
||||||
|
{ navigatorLanguage: 'de-DE-u-co-phonebk', expected: 'de'},
|
||||||
|
{ navigatorLanguage: 'zh-Hant-TW-u-co-phonebk', expected: 'zh'}
|
||||||
|
])('returns language $expected with navigator language $navigatorLanguage', ({ navigatorLanguage, expected }) => {
|
||||||
|
Object.defineProperty(navigator, 'language', {
|
||||||
|
value: navigatorLanguage,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(getNavigatorLanguage()).toBe(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -14,9 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default function getCurrentLanguage () {
|
export const getNavigatorLanguage = function getNavigatorLanguage () {
|
||||||
const saved = localStorage.getItem('locale');
|
|
||||||
if (saved) return saved;
|
|
||||||
const locale = new Intl.Locale(navigator.language);
|
const locale = new Intl.Locale(navigator.language);
|
||||||
return locale.language;
|
return locale.language;
|
||||||
};
|
};
|
||||||
@@ -27,16 +27,16 @@ const props = defineProps({
|
|||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
default: 24
|
default: 24
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
const icons = import.meta.glob('@/assets/icons/*.svg', {
|
const icons = import.meta.glob('@/assets/icons/*.svg', {
|
||||||
eager: true,
|
eager: true,
|
||||||
import: 'default'
|
import: 'default'
|
||||||
})
|
});
|
||||||
|
|
||||||
const Icon = computed(() => icons[`/src/assets/icons/${props.name}.svg`])
|
const Icon = computed(() => icons[`/src/assets/icons/${props.name}.svg`]);
|
||||||
|
|
||||||
const size = computed(() => ensureUnit(props.size))
|
const size = computed(() => ensureUnit(props.size));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -51,4 +51,4 @@ const size = computed(() => ensureUnit(props.size))
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
filter: var(--invert);
|
filter: var(--invert);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2026 Seekra
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export class FetchError extends Error {
|
||||||
|
constructor (message) {
|
||||||
|
super(message);
|
||||||
|
this.name = 'FetchError';
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2026 Seekra
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { FetchError } from '../../errors';
|
||||||
|
import { getLegalNotice } from '../fetchLegalContent';
|
||||||
|
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
||||||
|
|
||||||
|
let fetchSpy;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fetchSpy = vi.spyOn(globalThis, 'fetch');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
fetchSpy.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
const exampleHtml = `<h1>Heading</h1>
|
||||||
|
<p>
|
||||||
|
<a>...</a>
|
||||||
|
</p>`;
|
||||||
|
|
||||||
|
const exampleHtmlWithLinkClass = `<h1>Heading</h1>
|
||||||
|
<p>
|
||||||
|
<a class="link">...</a>
|
||||||
|
</p>`;
|
||||||
|
const exampleHtmlDocument = `<html>
|
||||||
|
<head>
|
||||||
|
<title>Legal Notice</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
${exampleHtml}
|
||||||
|
</body>
|
||||||
|
</html>`;
|
||||||
|
const exampleHtmlDocumentWithMain = `<html>
|
||||||
|
<head>
|
||||||
|
<title>Legal Notice</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
${exampleHtml}
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>`;
|
||||||
|
|
||||||
|
describe('fetchLegalContent', () => {
|
||||||
|
describe('getLegalNotice', () => {
|
||||||
|
describe('success', () => {
|
||||||
|
test('returns HTML body', async () => {
|
||||||
|
fetchSpy.mockResolvedValue(
|
||||||
|
new Response(exampleHtmlDocument)
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
(await getLegalNotice()).trim()
|
||||||
|
).toBe(exampleHtmlWithLinkClass);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns HTML <main>', async () => {
|
||||||
|
fetchSpy.mockResolvedValue(
|
||||||
|
new Response(exampleHtmlDocumentWithMain)
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
(await getLegalNotice()).trim()
|
||||||
|
).toBe(exampleHtmlWithLinkClass);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('does not fail on success status code', async () => {
|
||||||
|
fetchSpy.mockResolvedValue(
|
||||||
|
new Response(null, { status: 206 })
|
||||||
|
);
|
||||||
|
|
||||||
|
await getLegalNotice();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('error', () => {
|
||||||
|
test('throws FetchError when fetch fails', async () => {
|
||||||
|
fetchSpy.mockRejectedValue(new TypeError());
|
||||||
|
await expect(getLegalNotice()).rejects.toThrow(FetchError);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('throws FetchError on HTTP error', async () => {
|
||||||
|
fetchSpy.mockResolvedValue(
|
||||||
|
new Response(null, { status: 404 })
|
||||||
|
)
|
||||||
|
await expect(getLegalNotice()).rejects.toThrow(FetchError);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('does not throw FetchError when fetch throws another error than TypeError', async () => {
|
||||||
|
fetchSpy.mockRejectedValue(new Error());
|
||||||
|
await expect(getLegalNotice()).rejects.toThrow(Error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2026 Seekra
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { FetchError } from '../errors';
|
||||||
|
import { getAssetsUrl } from '@/config/env';
|
||||||
|
|
||||||
|
const fetchHtml = async function fetchHtml (url, options) {
|
||||||
|
let response;
|
||||||
|
try {
|
||||||
|
response = await fetch(url, options);
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof TypeError) throw new FetchError(err);
|
||||||
|
else throw err;
|
||||||
|
}
|
||||||
|
if (response.ok) return await response.text();
|
||||||
|
else throw new FetchError();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getLegalNotice = async function getLegalNotice () {
|
||||||
|
const legalNoticeUrl = new URL('legal/legal_notice.html', getAssetsUrl()).href;
|
||||||
|
const html = await fetchHtml(legalNoticeUrl);
|
||||||
|
|
||||||
|
const parser = new DOMParser();
|
||||||
|
const doc = parser.parseFromString(html, 'text/html');
|
||||||
|
|
||||||
|
const legalNoticeContainer = doc.querySelector('main') ?? doc.body;
|
||||||
|
legalNoticeContainer.querySelectorAll('a').forEach(
|
||||||
|
(link) => link.classList.add('link')
|
||||||
|
);
|
||||||
|
return legalNoticeContainer.innerHTML;
|
||||||
|
};
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<!--
|
||||||
|
Copyright 2026 Seekra
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { getLegalNotice } from '../services/fetchLegalContent';
|
||||||
|
import { onMounted, ref } from 'vue';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
const loading = ref(true);
|
||||||
|
const legalNoticeError = ref(null);
|
||||||
|
const legalNoticeHtml = ref(null);
|
||||||
|
onMounted(async () => {
|
||||||
|
try {
|
||||||
|
legalNoticeHtml.value = await getLegalNotice();
|
||||||
|
} catch {
|
||||||
|
legalNoticeError.value = 'legal.notice.loadError';
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="main-content-padding legal-notice-container">
|
||||||
|
<header class="header">
|
||||||
|
<h1>
|
||||||
|
{{ t('legal.notice.title') }}
|
||||||
|
</h1>
|
||||||
|
</header>
|
||||||
|
<main>
|
||||||
|
<div class="legal-notice-loading" v-if="loading">
|
||||||
|
{{ t('loading') }}
|
||||||
|
</div>
|
||||||
|
<div class="error" v-else-if="legalNoticeError">
|
||||||
|
{{ t(legalNoticeError) }}
|
||||||
|
</div>
|
||||||
|
<div class="legal-notice" v-html="legalNoticeHtml" v-else></div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.header h1 {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2026 Seekra
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { FetchError } from '../../errors.js';
|
||||||
|
import LegalNoticeView from '../LegalNoticeView.vue';
|
||||||
|
import { mountComponent } from '@/test-utils/mountComponent';
|
||||||
|
import { flushPromises } from '@vue/test-utils';
|
||||||
|
import { afterEach, describe, expect, test, vi } from 'vitest';
|
||||||
|
|
||||||
|
const getLegalNotice = vi.hoisted(() => vi.fn().mockResolvedValue('legal notice'));
|
||||||
|
vi.mock('../../services/fetchLegalContent', async (importOriginal) => {
|
||||||
|
const actual = await importOriginal();
|
||||||
|
return {
|
||||||
|
...actual,
|
||||||
|
getLegalNotice
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => getLegalNotice.mockRestore());
|
||||||
|
|
||||||
|
describe('LegalNoticeView', () => {
|
||||||
|
test('shows loading indicator', () => {
|
||||||
|
const wrapper = mountComponent(LegalNoticeView);
|
||||||
|
|
||||||
|
const legalNoticeLoading = wrapper.find('.legal-notice-loading');
|
||||||
|
const legalNoticeError = wrapper.find('.error');
|
||||||
|
const legalNotice = wrapper.find('.legal-notice');
|
||||||
|
|
||||||
|
expect(legalNoticeLoading.exists()).toBe(true);
|
||||||
|
expect(legalNoticeError.exists()).toBe(false);
|
||||||
|
expect(legalNotice.exists()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('shows error', async () => {
|
||||||
|
getLegalNotice.mockRejectedValue(new FetchError());
|
||||||
|
|
||||||
|
const wrapper = mountComponent(LegalNoticeView);
|
||||||
|
|
||||||
|
await flushPromises();
|
||||||
|
await wrapper.vm.$nextTick();
|
||||||
|
|
||||||
|
const legalNoticeLoading = wrapper.find('.legal-notice-loading');
|
||||||
|
const legalNoticeError = wrapper.find('.error');
|
||||||
|
const legalNotice = wrapper.find('.legal-notice');
|
||||||
|
|
||||||
|
expect(legalNoticeLoading.exists()).toBe(false);
|
||||||
|
expect(legalNoticeError.exists()).toBe(true);
|
||||||
|
expect(legalNotice.exists()).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('shows legal notice', async () => {
|
||||||
|
const wrapper = mountComponent(LegalNoticeView);
|
||||||
|
|
||||||
|
await flushPromises();
|
||||||
|
await wrapper.vm.$nextTick();
|
||||||
|
|
||||||
|
const legalNoticeLoading = wrapper.find('.legal-notice-loading');
|
||||||
|
const legalNoticeError = wrapper.find('.error');
|
||||||
|
const legalNotice = wrapper.find('.legal-notice');
|
||||||
|
|
||||||
|
expect(legalNoticeLoading.exists()).toBe(false);
|
||||||
|
expect(legalNoticeError.exists()).toBe(false);
|
||||||
|
expect(legalNotice.exists()).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -40,4 +40,4 @@ watch(() => route.query.q, q => {
|
|||||||
v-model="searchQueryModel"
|
v-model="searchQueryModel"
|
||||||
auto-submit
|
auto-submit
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ import { useI18n } from 'vue-i18n';
|
|||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter();
|
||||||
const props = defineProps(['autoSubmit'])
|
const props = defineProps(['autoSubmit']);
|
||||||
|
|
||||||
const submitSearch = function () {
|
const submitSearch = function () {
|
||||||
if (props.autoSubmit !== undefined) {
|
if (props.autoSubmit !== undefined) {
|
||||||
@@ -33,8 +33,8 @@ const submitSearch = function () {
|
|||||||
name: 'searchResults',
|
name: 'searchResults',
|
||||||
query: { q: searchQuery.value }
|
query: { q: searchQuery.value }
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -114,4 +114,4 @@ const submitSearch = function () {
|
|||||||
.search-form {
|
.search-form {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -94,4 +94,4 @@ const { t } = useI18n();
|
|||||||
transform: scale(1);
|
transform: scale(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -54,10 +54,9 @@ const props = defineProps({
|
|||||||
const store = useSettingsStore();
|
const store = useSettingsStore();
|
||||||
|
|
||||||
const optionType = computed(() => props.setting.allowMultiple ? 'checkbox' : 'radio');
|
const optionType = computed(() => props.setting.allowMultiple ? 'checkbox' : 'radio');
|
||||||
const selected = ref(normalizeSelectedValue(store.get(props.path) ?? props.setting.default));
|
const selected = computed({
|
||||||
|
get: () => normalizeSelectedValue(store.get(props.path) ?? props.setting.default),
|
||||||
watch(selected, (newValue) => {
|
set: (value) => store.set(props.path, value)
|
||||||
store.set(props.path, newValue);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const labelId = useId();
|
const labelId = useId();
|
||||||
@@ -123,4 +122,4 @@ const labelId = useId();
|
|||||||
.option-input:checked + .option-check-mark-wrapper .option-check-mark {
|
.option-input:checked + .option-check-mark-wrapper .option-check-mark {
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -16,4 +16,4 @@
|
|||||||
|
|
||||||
.settings-button:hover {
|
.settings-button:hover {
|
||||||
background-color: var(--light-hover);
|
background-color: var(--light-hover);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ const apply = function apply () {
|
|||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes done-button-disappear {
|
@keyframes done-button-disappear {
|
||||||
0% {
|
0% {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
@@ -212,4 +212,4 @@ const apply = function apply () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -90,4 +90,4 @@ const props = defineProps({
|
|||||||
.section-heading[aria-level="4"] {
|
.section-heading[aria-level="4"] {
|
||||||
--size: 1.4em;
|
--size: 1.4em;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -58,4 +58,4 @@ const followLink = function followLink () {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -106,4 +106,4 @@ const toggle = function toggle () {
|
|||||||
.switch-wrapper.enabled .switch-point {
|
.switch-wrapper.enabled .switch-point {
|
||||||
margin-left: var(--point-size);
|
margin-left: var(--point-size);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -90,6 +90,32 @@ describe('Selection', () => {
|
|||||||
expect(inputsChecked).toStrictEqual([false, true, false]);
|
expect(inputsChecked).toStrictEqual([false, true, false]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('reacts on store change', async () => {
|
||||||
|
const wrapper = getWrapper({
|
||||||
|
options: exampleOptions,
|
||||||
|
piniaOptions: {
|
||||||
|
setupStores: () => {
|
||||||
|
const store = useSettingsStore();
|
||||||
|
store.set('selection', 'o1');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const settings = useSettingsStore();
|
||||||
|
|
||||||
|
{
|
||||||
|
const inputs = wrapper.findAll('input');
|
||||||
|
const inputsChecked = getChecked(inputs);
|
||||||
|
expect(inputsChecked).toStrictEqual([false, true, false]);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
settings.set('selection', 'o2');
|
||||||
|
await nextTick();
|
||||||
|
const inputs = wrapper.findAll('input');
|
||||||
|
const inputsChecked = getChecked(inputs);
|
||||||
|
expect(inputsChecked).toStrictEqual([false, false, true]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('shows multiple values from store', () => {
|
test('shows multiple values from store', () => {
|
||||||
const wrapper = getWrapper({
|
const wrapper = getWrapper({
|
||||||
options: exampleOptions,
|
options: exampleOptions,
|
||||||
@@ -211,7 +237,7 @@ describe('Selection', () => {
|
|||||||
const inputO2 = inputs[2];
|
const inputO2 = inputs[2];
|
||||||
|
|
||||||
await check(inputO0);
|
await check(inputO0);
|
||||||
expectSelectionValue(['o0'])
|
expectSelectionValue(['o0']);
|
||||||
|
|
||||||
await uncheck(inputO0);
|
await uncheck(inputO0);
|
||||||
expectSelectionValue([]);
|
expectSelectionValue([]);
|
||||||
@@ -264,4 +290,4 @@ describe('Selection', () => {
|
|||||||
const label = wrapper.find('.label');
|
const label = wrapper.find('.label');
|
||||||
expect(label.text()).toBe(translation);
|
expect(label.text()).toBe(translation);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const getWrapper = function getWrapper({ type = 'string', i18n = 'input', defaul
|
|||||||
path: 'input'
|
path: 'input'
|
||||||
}
|
}
|
||||||
}, {}, [], piniaOptions);
|
}, {}, [], piniaOptions);
|
||||||
}
|
};
|
||||||
|
|
||||||
describe('SettingsInput', () => {
|
describe('SettingsInput', () => {
|
||||||
test('uses correct input type', () => {
|
test('uses correct input type', () => {
|
||||||
@@ -173,15 +173,15 @@ describe('SettingsInput', () => {
|
|||||||
|
|
||||||
await form.trigger('submit');
|
await form.trigger('submit');
|
||||||
expect(form.classes('done-button-shown')).toBeFalsy();
|
expect(form.classes('done-button-shown')).toBeFalsy();
|
||||||
|
|
||||||
await inputElement.setValue('a');
|
await inputElement.setValue('a');
|
||||||
expect(form.classes('done-button-shown')).toBeTruthy();
|
expect(form.classes('done-button-shown')).toBeTruthy();
|
||||||
|
|
||||||
const store = useSettingsStore();
|
const store = useSettingsStore();
|
||||||
store.set('input', 'a');
|
store.set('input', 'a');
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect(form.classes('done-button-shown')).toBeFalsy();
|
expect(form.classes('done-button-shown')).toBeFalsy();
|
||||||
|
|
||||||
await inputElement.setValue('');
|
await inputElement.setValue('');
|
||||||
store.set('input', '');
|
store.set('input', '');
|
||||||
await nextTick();
|
await nextTick();
|
||||||
@@ -207,4 +207,4 @@ describe('SettingsInput', () => {
|
|||||||
const label = wrapper.find('label');
|
const label = wrapper.find('label');
|
||||||
expect(label.text()).toBe(translation);
|
expect(label.text()).toBe(translation);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -157,4 +157,4 @@ describe('SettingsPage', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -56,4 +56,4 @@ describe('SettingsPageLink', () => {
|
|||||||
|
|
||||||
expect(goToSettingsPage).toHaveBeenCalledWith(target);
|
expect(goToSettingsPage).toHaveBeenCalledWith(target);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ describe('Switch', () => {
|
|||||||
|
|
||||||
const switchElement = wrapper.find('.switch-wrapper');
|
const switchElement = wrapper.find('.switch-wrapper');
|
||||||
expect(switchElement.classes('enabled')).toBeFalsy();
|
expect(switchElement.classes('enabled')).toBeFalsy();
|
||||||
|
|
||||||
store.set('switch', true);
|
store.set('switch', true);
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect(switchElement.classes('enabled')).toBeTruthy();
|
expect(switchElement.classes('enabled')).toBeTruthy();
|
||||||
@@ -97,29 +97,29 @@ describe('Switch', () => {
|
|||||||
|
|
||||||
test('toggles value in store', async () => {
|
test('toggles value in store', async () => {
|
||||||
const wrapper = getWrapper();
|
const wrapper = getWrapper();
|
||||||
|
|
||||||
const switchElement = wrapper.find('.switch-wrapper');
|
const switchElement = wrapper.find('.switch-wrapper');
|
||||||
|
|
||||||
const store = useSettingsStore();
|
const store = useSettingsStore();
|
||||||
expect(store.get('switch')).toBeUndefined();
|
expect(store.get('switch')).toBeUndefined();
|
||||||
|
|
||||||
switchElement.trigger('click');
|
switchElement.trigger('click');
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect(store.get('switch')).toBe(true);
|
expect(store.get('switch')).toBe(true);
|
||||||
|
|
||||||
switchElement.trigger('click');
|
switchElement.trigger('click');
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect(store.get('switch')).toBe(false);
|
expect(store.get('switch')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('shows correct translation', () => {
|
test('shows correct translation', () => {
|
||||||
const translation = 'Switch';
|
const translation = 'Switch';
|
||||||
|
|
||||||
const wrapper = getWrapper({
|
const wrapper = getWrapper({
|
||||||
translations: { switch1: translation }
|
translations: { switch1: translation }
|
||||||
})
|
});
|
||||||
|
|
||||||
const label = wrapper.find('label');
|
const label = wrapper.find('label');
|
||||||
expect(label.text()).toBe(translation);
|
expect(label.text()).toBe(translation);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2026 Seekra
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { useSettings } from '../useSettings';
|
||||||
|
import { createTestingPinia } from '@pinia/testing';
|
||||||
|
import { setActivePinia } from 'pinia';
|
||||||
|
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||||
|
|
||||||
|
const settingDefaultValue = vi.hoisted(() => 42);
|
||||||
|
const settingPath = ['test', 'number'];
|
||||||
|
|
||||||
|
vi.mock('../../config.js', () => ({
|
||||||
|
default: {
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
name: 'test',
|
||||||
|
i18n: '',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'number',
|
||||||
|
i18n: '',
|
||||||
|
name: 'number',
|
||||||
|
default: settingDefaultValue
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
i18n: '',
|
||||||
|
name: 'bool'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('useSettings', () => {
|
||||||
|
describe('getSetting', () => {
|
||||||
|
test('returns stored value', () => {
|
||||||
|
const { getSetting, setSetting } = useSettings();
|
||||||
|
|
||||||
|
const key = ['setting'];
|
||||||
|
const value = 42;
|
||||||
|
|
||||||
|
setSetting(key, value);
|
||||||
|
expect(getSetting(key)).toBe(value);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns default value', () => {
|
||||||
|
const { getSetting, setSetting } = useSettings();
|
||||||
|
expect(getSetting(settingPath)).toBe(settingDefaultValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns stored value instead of default value', () => {
|
||||||
|
const { getSetting, setSetting } = useSettings();
|
||||||
|
|
||||||
|
const value = 43;
|
||||||
|
|
||||||
|
expect(getSetting(settingPath)).toBe(settingDefaultValue);
|
||||||
|
|
||||||
|
setSetting(settingPath, value);
|
||||||
|
expect(getSetting(settingPath)).toBe(value);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns undefined if there is no value', () => {
|
||||||
|
const { getSetting } = useSettings();
|
||||||
|
expect(getSetting(['test', 'bool'])).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
setActivePinia(
|
||||||
|
createTestingPinia({
|
||||||
|
createSpy: vi.fn,
|
||||||
|
stubActions: false
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -37,4 +37,4 @@ describe('useSettingsPage', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2026 Seekra
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import settings from '../config.js';
|
||||||
|
import { useSettingsStore } from '../stores/settingsStore';
|
||||||
|
import { getSettingRecursively } from '../utils/getSetting';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides access to the stored settings.
|
||||||
|
*/
|
||||||
|
export const useSettings = function useSettings () {
|
||||||
|
/**
|
||||||
|
* Returns the value of a specific setting.
|
||||||
|
* @param {string[]} key - The settings key.
|
||||||
|
* @return The value of the setting.
|
||||||
|
*/
|
||||||
|
const getSetting = function getSetting (key) {
|
||||||
|
const settingsStore = useSettingsStore();
|
||||||
|
|
||||||
|
return (
|
||||||
|
settingsStore.get(key.join('.')) ??
|
||||||
|
getSettingRecursively(
|
||||||
|
key, settings.contents ?? []
|
||||||
|
)?.default
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of a specific setting.
|
||||||
|
* @param {string[]} key - The setting key.
|
||||||
|
* @param value - The new value for the setting.
|
||||||
|
*/
|
||||||
|
const setSetting = function setSetting (key, value) {
|
||||||
|
const settingsStore = useSettingsStore();
|
||||||
|
settingsStore.set(key.join('.'), value);
|
||||||
|
};
|
||||||
|
|
||||||
|
return { getSetting, setSetting };
|
||||||
|
};
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2026 Seekra
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { ref, readonly } from 'vue';
|
|
||||||
import { loadSettingsConfig } from '../utils/settingsParser.js';
|
|
||||||
|
|
||||||
const config = ref(null);
|
|
||||||
const error = ref(null);
|
|
||||||
const loading = ref(false);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides reactive access to the parsed settings configuration.
|
|
||||||
* The config is loaded once and shared across all consumers.
|
|
||||||
*/
|
|
||||||
export function useSettingsConfig() {
|
|
||||||
async function load() {
|
|
||||||
loading.value = true;
|
|
||||||
error.value = null;
|
|
||||||
try {
|
|
||||||
config.value = await loadSettingsConfig();
|
|
||||||
} catch (e) {
|
|
||||||
error.value = e.message;
|
|
||||||
config.value = null;
|
|
||||||
} finally {
|
|
||||||
loading.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
config: readonly(config),
|
|
||||||
error: readonly(error),
|
|
||||||
loading: readonly(loading),
|
|
||||||
load,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -30,4 +30,4 @@ export const useSettingsPage = function useSettingsPage () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return { goToSettingsPage };
|
return { goToSettingsPage };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2026 Seekra
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { getNavigatorLanguage } from '../i18n/utils/navigatorLanguage';
|
||||||
|
import { fallbackLocale, SUPPORTED_LANGUAGES } from '@/i18n';
|
||||||
|
|
||||||
|
let defaultLanguage;
|
||||||
|
{
|
||||||
|
const navigatorLanguage = getNavigatorLanguage();
|
||||||
|
if (SUPPORTED_LANGUAGES.includes(navigatorLanguage)) {
|
||||||
|
defaultLanguage = navigatorLanguage;
|
||||||
|
} else {
|
||||||
|
defaultLanguage = fallbackLocale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general.title',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
name: 'language',
|
||||||
|
type: 'selection',
|
||||||
|
i18n: 'settings.settings.general.settings.language.title',
|
||||||
|
default: defaultLanguage,
|
||||||
|
options: SUPPORTED_LANGUAGES.map((language) => ({
|
||||||
|
name: language,
|
||||||
|
i18n: `preferences.locale.languages.${language}`
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'appearance',
|
||||||
|
i18n: 'settings.settings.appearance.title',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
name: 'colorScheme',
|
||||||
|
type: 'selection',
|
||||||
|
i18n: 'settings.settings.appearance.contents.colorScheme.title',
|
||||||
|
default: 'auto',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'auto',
|
||||||
|
i18n: 'settings.settings.appearance.contents.colorScheme.options.auto'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'light',
|
||||||
|
i18n: 'settings.settings.appearance.contents.colorScheme.options.light'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'dark',
|
||||||
|
i18n: 'settings.settings.appearance.contents.colorScheme.options.dark'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"contents": []
|
|
||||||
}
|
|
||||||
@@ -39,4 +39,4 @@ export const useSettingsStore = defineStore('settings', () => {
|
|||||||
return { set, get, remove, clear, settings };
|
return { set, get, remove, clear, settings };
|
||||||
}, {
|
}, {
|
||||||
persist: true
|
persist: true
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -62,4 +62,4 @@ limitations under the License.
|
|||||||
* @typedef {BoolSettingConfig | NumberSettingConfig | StringSettingConfig | SelectionSettingConfig | SectionSettingConfig} SettingConfigEntry
|
* @typedef {BoolSettingConfig | NumberSettingConfig | StringSettingConfig | SelectionSettingConfig | SectionSettingConfig} SettingConfigEntry
|
||||||
* @typedef {{ contents: SettingConfigEntry[] }} FirstLevelSettingConfigEntry
|
* @typedef {{ contents: SettingConfigEntry[] }} FirstLevelSettingConfigEntry
|
||||||
* @typedef {{ contents: FirstLevelSettingConfigEntry[] }} SettingsConfig
|
* @typedef {{ contents: FirstLevelSettingConfigEntry[] }} SettingsConfig
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,512 +15,514 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { getSetting, getSettingRecursively } from '../getSetting.js';
|
import { getSetting, getSettingRecursively } from '../getSetting.js';
|
||||||
import { test, expect } from 'vitest';
|
import { describe, test, expect } from 'vitest';
|
||||||
|
|
||||||
test.for([
|
describe('getSetting', () => {
|
||||||
({ settings: [], name: '', expected: undefined }),
|
test.for([
|
||||||
({ settings: [], name: 'a', expected: undefined }),
|
({ settings: [], name: '', expected: undefined }),
|
||||||
({ settings: [
|
({ settings: [], name: 'a', expected: undefined }),
|
||||||
{
|
({ settings: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'a',
|
||||||
|
i18n: 'a'
|
||||||
|
}
|
||||||
|
], name: 'a', expected: {
|
||||||
type: 'bool',
|
type: 'bool',
|
||||||
name: 'a',
|
name: 'a',
|
||||||
i18n: 'a'
|
i18n: 'a'
|
||||||
}
|
} })
|
||||||
], name: 'a', expected: {
|
])('returns $expected', ({ settings, name, expected }) => {
|
||||||
type: 'bool',
|
expect(getSetting(name, settings)).toStrictEqual(expected);
|
||||||
name: 'a',
|
});
|
||||||
i18n: 'a'
|
|
||||||
} })
|
|
||||||
])('returns $expected', ({ settings, name, expected }) => {
|
|
||||||
expect(getSetting(name, settings)).toStrictEqual(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
const veryNestedSettingsList = [
|
const veryNestedSettingsList = [
|
||||||
{
|
{
|
||||||
type: 'bool',
|
type: 'bool',
|
||||||
name: '1a',
|
name: '1a',
|
||||||
i18n: '1a'
|
i18n: '1a'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'section',
|
type: 'section',
|
||||||
name: '1b',
|
name: '1b',
|
||||||
i18n: '1b',
|
i18n: '1b',
|
||||||
content: [
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '2a',
|
||||||
|
i18n: '2a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '2b',
|
||||||
|
i18n: '2b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '3a',
|
||||||
|
i18n: '3a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '3b',
|
||||||
|
i18n: '3b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '4a',
|
||||||
|
i18n: '4a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '4b',
|
||||||
|
i18n: '4b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '5a',
|
||||||
|
i18n: '5a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '5b',
|
||||||
|
i18n: '5b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '6a',
|
||||||
|
i18n: '6a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '6b',
|
||||||
|
i18n: '6b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '7a',
|
||||||
|
i18n: '7a'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
test.for([
|
||||||
|
({ settings: [], path: ['a'], expected: undefined }),
|
||||||
|
({ settings: [
|
||||||
{
|
{
|
||||||
type: 'bool',
|
type: 'bool',
|
||||||
name: '2a',
|
name: '1a',
|
||||||
i18n: '2a'
|
i18n: '1a'
|
||||||
|
}
|
||||||
|
], path: ['1a'], expected: {
|
||||||
|
type: 'bool',
|
||||||
|
name: '1a',
|
||||||
|
i18n: '1a'
|
||||||
|
} }),
|
||||||
|
({ settings: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '1a',
|
||||||
|
i18n: '1a'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'section',
|
type: 'section',
|
||||||
name: '2b',
|
name: '1b',
|
||||||
i18n: '2b',
|
i18n: '1b',
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
type: 'bool',
|
type: 'bool',
|
||||||
name: '3a',
|
name: '2a',
|
||||||
i18n: '3a'
|
i18n: '2a'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
], path: ['1a'], expected: {
|
||||||
|
type: 'bool',
|
||||||
|
name: '1a',
|
||||||
|
i18n: '1a'
|
||||||
|
} }),
|
||||||
|
({ settings: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '1a',
|
||||||
|
i18n: '1a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '1b',
|
||||||
|
i18n: '1b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '2a',
|
||||||
|
i18n: '2a'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
], path: ['1b', '2a'], expected: {
|
||||||
|
type: 'bool',
|
||||||
|
name: '2a',
|
||||||
|
i18n: '2a'
|
||||||
|
} }),
|
||||||
|
({ settings: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '1a',
|
||||||
|
i18n: '1a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '1b',
|
||||||
|
i18n: '1b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '2a',
|
||||||
|
i18n: '2a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'number',
|
||||||
|
name: '2b',
|
||||||
|
i18n: '2b',
|
||||||
|
default: 42
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
], path: ['1b', '2b'], expected: {
|
||||||
|
type: 'number',
|
||||||
|
name: '2b',
|
||||||
|
i18n: '2b',
|
||||||
|
default: 42
|
||||||
|
} }),
|
||||||
|
({ settings: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '1a',
|
||||||
|
i18n: '1a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '1b',
|
||||||
|
i18n: '1b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '2a',
|
||||||
|
i18n: '2a'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'section',
|
type: 'section',
|
||||||
name: '3b',
|
name: '2b',
|
||||||
i18n: '3b',
|
i18n: '2b',
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
type: 'bool',
|
type: 'string',
|
||||||
name: '4a',
|
name: '3a',
|
||||||
i18n: '4a'
|
i18n: '3a'
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '4b',
|
|
||||||
i18n: '4b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '5a',
|
|
||||||
i18n: '5a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '5b',
|
|
||||||
i18n: '5b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '6a',
|
|
||||||
i18n: '6a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '6b',
|
|
||||||
i18n: '6b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '7a',
|
|
||||||
i18n: '7a'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
], path: ['1b', '2b', '3a'], expected: {
|
||||||
}
|
type: 'string',
|
||||||
];
|
name: '3a',
|
||||||
|
i18n: '3a'
|
||||||
test.for([
|
} }),
|
||||||
({ settings: [], path: ['a'], expected: undefined }),
|
({ settings: [
|
||||||
({ settings: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '1a',
|
|
||||||
i18n: '1a'
|
|
||||||
}
|
|
||||||
], path: ['1a'], expected: {
|
|
||||||
type: 'bool',
|
|
||||||
name: '1a',
|
|
||||||
i18n: '1a'
|
|
||||||
} }),
|
|
||||||
({ settings: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '1a',
|
|
||||||
i18n: '1a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '1b',
|
|
||||||
i18n: '1b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '2a',
|
|
||||||
i18n: '2a'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
], path: ['1a'], expected: {
|
|
||||||
type: 'bool',
|
|
||||||
name: '1a',
|
|
||||||
i18n: '1a'
|
|
||||||
} }),
|
|
||||||
({ settings: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '1a',
|
|
||||||
i18n: '1a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '1b',
|
|
||||||
i18n: '1b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '2a',
|
|
||||||
i18n: '2a'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
], path: ['1b', '2a'], expected: {
|
|
||||||
type: 'bool',
|
|
||||||
name: '2a',
|
|
||||||
i18n: '2a'
|
|
||||||
} }),
|
|
||||||
({ settings: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '1a',
|
|
||||||
i18n: '1a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '1b',
|
|
||||||
i18n: '1b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '2a',
|
|
||||||
i18n: '2a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'number',
|
|
||||||
name: '2b',
|
|
||||||
i18n: '2b',
|
|
||||||
default: 42
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
], path: ['1b', '2b'], expected: {
|
|
||||||
type: 'number',
|
|
||||||
name: '2b',
|
|
||||||
i18n: '2b',
|
|
||||||
default: 42
|
|
||||||
} }),
|
|
||||||
({ settings: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '1a',
|
|
||||||
i18n: '1a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '1b',
|
|
||||||
i18n: '1b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '2a',
|
|
||||||
i18n: '2a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '2b',
|
|
||||||
i18n: '2b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: '3a',
|
|
||||||
i18n: '3a'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
], path: ['1b', '2b', '3a'], expected: {
|
|
||||||
type: 'string',
|
|
||||||
name: '3a',
|
|
||||||
i18n: '3a'
|
|
||||||
} }),
|
|
||||||
({ settings: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '1a',
|
|
||||||
i18n: '1a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '1b',
|
|
||||||
i18n: '1b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '2a',
|
|
||||||
i18n: '2a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '2b',
|
|
||||||
i18n: '2b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: '3a',
|
|
||||||
i18n: '3a'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
], path: ['1b'], expected: {
|
|
||||||
type: 'section',
|
|
||||||
name: '1b',
|
|
||||||
i18n: '1b',
|
|
||||||
content: [
|
|
||||||
{
|
{
|
||||||
type: 'bool',
|
type: 'bool',
|
||||||
name: '2a',
|
name: '1a',
|
||||||
i18n: '2a'
|
i18n: '1a'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'section',
|
type: 'section',
|
||||||
name: '2b',
|
name: '1b',
|
||||||
i18n: '2b',
|
i18n: '1b',
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: '3a',
|
|
||||||
i18n: '3a'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
} }),
|
|
||||||
({ settings: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '1a',
|
|
||||||
i18n: '1a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '1b',
|
|
||||||
i18n: '1b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '2a',
|
|
||||||
i18n: '2a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '2b',
|
|
||||||
i18n: '2b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: '3a',
|
|
||||||
i18n: '3a'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
], path: ['1b', '2b'], expected: {
|
|
||||||
type: 'section',
|
|
||||||
name: '2b',
|
|
||||||
i18n: '2b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: '3a',
|
|
||||||
i18n: '3a'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
} }),
|
|
||||||
|
|
||||||
({ settings: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '1a',
|
|
||||||
i18n: '1a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '1b',
|
|
||||||
i18n: '1b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '2a',
|
|
||||||
i18n: '2a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '2b',
|
|
||||||
i18n: '2b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: '3a',
|
|
||||||
i18n: '3a'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
], path: ['1b', '2b', '3b'], expected: undefined }),
|
|
||||||
({ settings: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '1a',
|
|
||||||
i18n: '1a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '1b',
|
|
||||||
i18n: '1b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '2a',
|
|
||||||
i18n: '2a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '2b',
|
|
||||||
i18n: '2b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: '3a',
|
|
||||||
i18n: '3a'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
], path: ['1b', '2a', '3a'], expected: undefined }),
|
|
||||||
({ settings: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '1a',
|
|
||||||
i18n: '1a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '1b',
|
|
||||||
i18n: '1b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '2a',
|
|
||||||
i18n: '2a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '2b',
|
|
||||||
i18n: '2b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: '3a',
|
|
||||||
i18n: '3a'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
], path: ['1b', '2c', '3a'], expected: undefined }),
|
|
||||||
({ settings: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '1a',
|
|
||||||
i18n: '1a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '1b',
|
|
||||||
i18n: '1b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '2a',
|
|
||||||
i18n: '2a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '2b',
|
|
||||||
i18n: '2b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: '3a',
|
|
||||||
i18n: '3a'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
], path: ['1a', '2b', '3a'], expected: undefined }),
|
|
||||||
({ settings: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '1a',
|
|
||||||
i18n: '1a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '1b',
|
|
||||||
i18n: '1b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '2a',
|
|
||||||
i18n: '2a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '2b',
|
|
||||||
i18n: '2b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: '3a',
|
|
||||||
i18n: '3a'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
], path: ['1c', '2b', '3a'], expected: undefined }),
|
|
||||||
({ settings: veryNestedSettingsList, path: ['1b', '2b', '3b', '4b', '5b', '6b', '7a'], expected: {
|
|
||||||
type: 'bool',
|
|
||||||
name: '7a',
|
|
||||||
i18n: '7a'
|
|
||||||
} }),
|
|
||||||
({ settings: veryNestedSettingsList, path: ['1b', '2b', '3b', '4b', '5b'], expected: {
|
|
||||||
type: 'section',
|
|
||||||
name: '5b',
|
|
||||||
i18n: '5b',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: '6a',
|
|
||||||
i18n: '6a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: '6b',
|
|
||||||
i18n: '6b',
|
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
type: 'bool',
|
type: 'bool',
|
||||||
name: '7a',
|
name: '2a',
|
||||||
i18n: '7a'
|
i18n: '2a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '2b',
|
||||||
|
i18n: '2b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: '3a',
|
||||||
|
i18n: '3a'
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
], path: ['1b'], expected: {
|
||||||
} }),
|
type: 'section',
|
||||||
({ settings: veryNestedSettingsList, path: ['1b', '2b', '3b', '4ba', '5b', '6b', '7a'], expected: undefined })
|
name: '1b',
|
||||||
])('returns $expected', ({ settings, path, expected }) => {
|
i18n: '1b',
|
||||||
expect(getSettingRecursively(path, settings)).toStrictEqual(expected);
|
content: [
|
||||||
});
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '2a',
|
||||||
|
i18n: '2a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '2b',
|
||||||
|
i18n: '2b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: '3a',
|
||||||
|
i18n: '3a'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} }),
|
||||||
|
({ settings: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '1a',
|
||||||
|
i18n: '1a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '1b',
|
||||||
|
i18n: '1b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '2a',
|
||||||
|
i18n: '2a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '2b',
|
||||||
|
i18n: '2b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: '3a',
|
||||||
|
i18n: '3a'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
], path: ['1b', '2b'], expected: {
|
||||||
|
type: 'section',
|
||||||
|
name: '2b',
|
||||||
|
i18n: '2b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: '3a',
|
||||||
|
i18n: '3a'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} }),
|
||||||
|
|
||||||
|
({ settings: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '1a',
|
||||||
|
i18n: '1a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '1b',
|
||||||
|
i18n: '1b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '2a',
|
||||||
|
i18n: '2a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '2b',
|
||||||
|
i18n: '2b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: '3a',
|
||||||
|
i18n: '3a'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
], path: ['1b', '2b', '3b'], expected: undefined }),
|
||||||
|
({ settings: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '1a',
|
||||||
|
i18n: '1a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '1b',
|
||||||
|
i18n: '1b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '2a',
|
||||||
|
i18n: '2a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '2b',
|
||||||
|
i18n: '2b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: '3a',
|
||||||
|
i18n: '3a'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
], path: ['1b', '2a', '3a'], expected: undefined }),
|
||||||
|
({ settings: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '1a',
|
||||||
|
i18n: '1a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '1b',
|
||||||
|
i18n: '1b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '2a',
|
||||||
|
i18n: '2a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '2b',
|
||||||
|
i18n: '2b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: '3a',
|
||||||
|
i18n: '3a'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
], path: ['1b', '2c', '3a'], expected: undefined }),
|
||||||
|
({ settings: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '1a',
|
||||||
|
i18n: '1a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '1b',
|
||||||
|
i18n: '1b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '2a',
|
||||||
|
i18n: '2a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '2b',
|
||||||
|
i18n: '2b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: '3a',
|
||||||
|
i18n: '3a'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
], path: ['1a', '2b', '3a'], expected: undefined }),
|
||||||
|
({ settings: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '1a',
|
||||||
|
i18n: '1a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '1b',
|
||||||
|
i18n: '1b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '2a',
|
||||||
|
i18n: '2a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '2b',
|
||||||
|
i18n: '2b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: '3a',
|
||||||
|
i18n: '3a'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
], path: ['1c', '2b', '3a'], expected: undefined }),
|
||||||
|
({ settings: veryNestedSettingsList, path: ['1b', '2b', '3b', '4b', '5b', '6b', '7a'], expected: {
|
||||||
|
type: 'bool',
|
||||||
|
name: '7a',
|
||||||
|
i18n: '7a'
|
||||||
|
} }),
|
||||||
|
({ settings: veryNestedSettingsList, path: ['1b', '2b', '3b', '4b', '5b'], expected: {
|
||||||
|
type: 'section',
|
||||||
|
name: '5b',
|
||||||
|
i18n: '5b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '6a',
|
||||||
|
i18n: '6a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: '6b',
|
||||||
|
i18n: '6b',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: '7a',
|
||||||
|
i18n: '7a'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} }),
|
||||||
|
({ settings: veryNestedSettingsList, path: ['1b', '2b', '3b', '4ba', '5b', '6b', '7a'], expected: undefined })
|
||||||
|
])('returns $expected', ({ settings, path, expected }) => {
|
||||||
|
expect(getSettingRecursively(path, settings)).toStrictEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -59,5 +59,5 @@ describe('settingsPage', () => {
|
|||||||
])('returns $expected', async ({ path, expected }) => {
|
])('returns $expected', async ({ path, expected }) => {
|
||||||
expect(getSettingsPagePathSegments(path)).toStrictEqual(expected);
|
expect(getSettingsPagePathSegments(path)).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|||||||
@@ -20,18 +20,10 @@ import { validateSettingsConfig, validateEntry, validateSelectionOptions, assert
|
|||||||
describe('settingsValidator', () => {
|
describe('settingsValidator', () => {
|
||||||
describe('validateSettingsConfig', () => {
|
describe('validateSettingsConfig', () => {
|
||||||
test.for([
|
test.for([
|
||||||
{ raw: false, expected: false },
|
{ settings: {
|
||||||
{ raw: true, expected: false },
|
|
||||||
{ raw: 0, expected: false },
|
|
||||||
{ raw: 42, expected: false },
|
|
||||||
{ raw: '', expected: false },
|
|
||||||
{ raw: ' ', expected: false },
|
|
||||||
{ raw: 'a', expected: false },
|
|
||||||
{ raw: {}, expected: false },
|
|
||||||
{ raw: {
|
|
||||||
contents: []
|
contents: []
|
||||||
}, expected: true },
|
} },
|
||||||
{ raw: {
|
{ settings: {
|
||||||
contents: [
|
contents: [
|
||||||
{
|
{
|
||||||
name: 'general',
|
name: 'general',
|
||||||
@@ -45,8 +37,8 @@ describe('settingsValidator', () => {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}, expected: true },
|
} },
|
||||||
{ raw: {
|
{ settings: {
|
||||||
contents: [
|
contents: [
|
||||||
{
|
{
|
||||||
name: 'general',
|
name: 'general',
|
||||||
@@ -71,8 +63,8 @@ describe('settingsValidator', () => {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}, expected: true },
|
} },
|
||||||
{ raw: {
|
{ settings: {
|
||||||
contents: [
|
contents: [
|
||||||
{
|
{
|
||||||
name: 'general',
|
name: 'general',
|
||||||
@@ -128,12 +120,12 @@ describe('settingsValidator', () => {
|
|||||||
default: 'str'
|
default: 'str'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
}, expected: true },
|
} },
|
||||||
{ raw: {
|
{ settings: {
|
||||||
contents: [
|
contents: [
|
||||||
{
|
{
|
||||||
name: 'general',
|
name: 'general',
|
||||||
@@ -190,12 +182,283 @@ describe('settingsValidator', () => {
|
|||||||
default: 'str'
|
default: 'str'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} }
|
||||||
|
])('does not throw an error and returns input', ({ settings }) => {
|
||||||
|
validateSettingsConfig(settings);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.for([
|
||||||
|
{ settings: false },
|
||||||
|
{ settings: true },
|
||||||
|
{ settings: 0 },
|
||||||
|
{ settings: 42 },
|
||||||
|
{ settings: '' },
|
||||||
|
{ settings: ' ' },
|
||||||
|
{ settings: 'a' },
|
||||||
|
{ settings: {} },
|
||||||
|
{ settings: {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'sectio',
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'copyOfGeneral',
|
||||||
|
i18n: 'settings.settings.copyOfGeneral',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
default: false,
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'aSection',
|
||||||
|
i18n: 'settings.settings.aSection',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 43',
|
||||||
|
i18n: 'settings.settings.aSection.enableFeature43'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'language',
|
||||||
|
i18n: 'settings.settings.aSection.language.label',
|
||||||
|
default: 'en',
|
||||||
|
allowMultiple: 'false',
|
||||||
|
options: [
|
||||||
|
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
||||||
|
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'section2',
|
||||||
|
i18n: 'settings.settings.aSection.section2.label',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'string',
|
||||||
|
i18n: 'settings.settings.aSection.sections.string',
|
||||||
|
default: 'str'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}, expected: true },
|
} },
|
||||||
{ raw: {
|
{ settings: {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'sectio',
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'copyOfGeneral',
|
||||||
|
i18n: 'settings.settings.copyOfGeneral',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
default: false,
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'aSection',
|
||||||
|
i18n: 'settings.settings.aSection',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 43',
|
||||||
|
i18n: 'settings.settings.aSection.enableFeature43'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'language',
|
||||||
|
i18n: 'settings.settings.aSection.language.label',
|
||||||
|
default: 'en',
|
||||||
|
options: [
|
||||||
|
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
||||||
|
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'section2',
|
||||||
|
i18n: 'settings.settings.aSection.section2.label',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'string',
|
||||||
|
i18n: 'settings.settings.aSection.sections.string',
|
||||||
|
default: 'str'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} },
|
||||||
|
{ settings: {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'copyOfGeneral',
|
||||||
|
i18n: 'settings.settings.copyOfGeneral',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
default: false,
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'aSection',
|
||||||
|
i18n: 'settings.settings.aSection',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 43',
|
||||||
|
i18n: 'settings.settings.aSection.enableFeature43'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'language',
|
||||||
|
i18n: 'settings.settings.aSection.language.label',
|
||||||
|
default: 'en',
|
||||||
|
options: [
|
||||||
|
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
||||||
|
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'section2',
|
||||||
|
i18n: 'settings.settings.aSection.section2.label',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'string',
|
||||||
|
i18n: 'settings.settings.aSection.sections.string',
|
||||||
|
default: 'str'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} },
|
||||||
|
{ settings: {
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'general',
|
||||||
|
i18n: 'settings.settings.general',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'copyOfGeneral',
|
||||||
|
i18n: 'settings.settings.copyOfGeneral',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 42',
|
||||||
|
default: false,
|
||||||
|
i18n: 'settings.settings.general.enableFeature42'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'aSection',
|
||||||
|
i18n: 'settings.settings.aSection',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'bool',
|
||||||
|
name: 'Enable feature 43',
|
||||||
|
i18n: 'settings.settings.aSection.enableFeature43',
|
||||||
|
default: 'true'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
name: 'language',
|
||||||
|
i18n: 'settings.settings.aSection.language.label',
|
||||||
|
default: 'en',
|
||||||
|
options: [
|
||||||
|
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
||||||
|
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
name: 'section2',
|
||||||
|
i18n: 'settings.settings.aSection.section2.label',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'string',
|
||||||
|
i18n: 'settings.settings.aSection.sections.string',
|
||||||
|
default: 42
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} },
|
||||||
|
{ settings: {
|
||||||
contents: [
|
contents: [
|
||||||
{
|
{
|
||||||
type: 'bool',
|
type: 'bool',
|
||||||
@@ -258,275 +521,13 @@ describe('settingsValidator', () => {
|
|||||||
default: 'str'
|
default: 'str'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
}, expected: false },
|
} }
|
||||||
{ raw: {
|
])('throws error', ({ settings }) => {
|
||||||
contents: [
|
expect(() => validateSettingsConfig(settings)).toThrow(Error);
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'general',
|
|
||||||
i18n: 'settings.settings.general',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'copyOfGeneral',
|
|
||||||
i18n: 'settings.settings.copyOfGeneral',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
default: false,
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'aSection',
|
|
||||||
i18n: 'settings.settings.aSection',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 43',
|
|
||||||
i18n: 'settings.settings.aSection.enableFeature43',
|
|
||||||
default: 'true'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'selection',
|
|
||||||
name: 'language',
|
|
||||||
i18n: 'settings.settings.aSection.language.label',
|
|
||||||
default: 'en',
|
|
||||||
options: [
|
|
||||||
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
|
||||||
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'section2',
|
|
||||||
i18n: 'settings.settings.aSection.section2.label',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: 'string',
|
|
||||||
i18n: 'settings.settings.aSection.sections.string',
|
|
||||||
default: 42
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}, expected: false },
|
|
||||||
{ raw: {
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'general',
|
|
||||||
i18n: 'settings.settings.general',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'copyOfGeneral',
|
|
||||||
i18n: 'settings.settings.copyOfGeneral',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
default: false,
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'aSection',
|
|
||||||
i18n: 'settings.settings.aSection',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 43',
|
|
||||||
i18n: 'settings.settings.aSection.enableFeature43'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'selection',
|
|
||||||
name: 'language',
|
|
||||||
i18n: 'settings.settings.aSection.language.label',
|
|
||||||
default: 'en',
|
|
||||||
options: [
|
|
||||||
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
|
||||||
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'section2',
|
|
||||||
i18n: 'settings.settings.aSection.section2.label',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: 'string',
|
|
||||||
i18n: 'settings.settings.aSection.sections.string',
|
|
||||||
default: 'str'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}, expected: false },
|
|
||||||
{ raw: {
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'sectio',
|
|
||||||
name: 'general',
|
|
||||||
i18n: 'settings.settings.general',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'copyOfGeneral',
|
|
||||||
i18n: 'settings.settings.copyOfGeneral',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
default: false,
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'aSection',
|
|
||||||
i18n: 'settings.settings.aSection',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 43',
|
|
||||||
i18n: 'settings.settings.aSection.enableFeature43'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'selection',
|
|
||||||
name: 'language',
|
|
||||||
i18n: 'settings.settings.aSection.language.label',
|
|
||||||
default: 'en',
|
|
||||||
options: [
|
|
||||||
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
|
||||||
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'section2',
|
|
||||||
i18n: 'settings.settings.aSection.section2.label',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: 'string',
|
|
||||||
i18n: 'settings.settings.aSection.sections.string',
|
|
||||||
default: 'str'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}, expected: false },
|
|
||||||
{ raw: {
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'sectio',
|
|
||||||
name: 'general',
|
|
||||||
i18n: 'settings.settings.general',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'copyOfGeneral',
|
|
||||||
i18n: 'settings.settings.copyOfGeneral',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 42',
|
|
||||||
default: false,
|
|
||||||
i18n: 'settings.settings.general.enableFeature42'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'aSection',
|
|
||||||
i18n: 'settings.settings.aSection',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'bool',
|
|
||||||
name: 'Enable feature 43',
|
|
||||||
i18n: 'settings.settings.aSection.enableFeature43'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'selection',
|
|
||||||
name: 'language',
|
|
||||||
i18n: 'settings.settings.aSection.language.label',
|
|
||||||
default: 'en',
|
|
||||||
allowMultiple: 'false',
|
|
||||||
options: [
|
|
||||||
{ name: 'en', i18n: 'settings.settings.aSection.language.options.en' },
|
|
||||||
{ name: 'de', i18n: 'settings.settings.aSection.language.options.de' },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'section',
|
|
||||||
name: 'section2',
|
|
||||||
i18n: 'settings.settings.aSection.section2.label',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'string',
|
|
||||||
name: 'string',
|
|
||||||
i18n: 'settings.settings.aSection.sections.string',
|
|
||||||
default: 'str'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}, expected: false }
|
|
||||||
])('returns valid: $expected', ({ raw, expected }) => {
|
|
||||||
const result = validateSettingsConfig(raw);
|
|
||||||
if (!result.valid) {
|
|
||||||
console.error('Error message:', result.error);
|
|
||||||
};
|
|
||||||
expect(result.valid).toBe(expected);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -535,12 +536,12 @@ describe('settingsValidator', () => {
|
|||||||
[{ name: 'enableFeature42', type: 'bool', i18n: 'feature.42.enable' }],
|
[{ name: 'enableFeature42', type: 'bool', i18n: 'feature.42.enable' }],
|
||||||
[{ name: 'enableFeature42', type: 'bool', i18n: 'feature.42.enable', default: true }],
|
[{ name: 'enableFeature42', type: 'bool', i18n: 'feature.42.enable', default: true }],
|
||||||
[{ name: 'enableFeature42', type: 'bool', i18n: 'feature.42.enable', default: false }],
|
[{ name: 'enableFeature42', type: 'bool', i18n: 'feature.42.enable', default: false }],
|
||||||
|
|
||||||
[{ name: 'aNumber', type: 'number', i18n: 'aNumber.label' }],
|
[{ name: 'aNumber', type: 'number', i18n: 'aNumber.label' }],
|
||||||
[{ name: 'aNumber', type: 'number', i18n: 'aNumber.label', default: 42 }],
|
[{ name: 'aNumber', type: 'number', i18n: 'aNumber.label', default: 42 }],
|
||||||
[{ name: 'aNumber', type: 'number', i18n: 'aNumber.label', default: 0 }],
|
[{ name: 'aNumber', type: 'number', i18n: 'aNumber.label', default: 0 }],
|
||||||
[{ name: 'aNumber', type: 'number', i18n: 'aNumber.label', default: -42.7 }],
|
[{ name: 'aNumber', type: 'number', i18n: 'aNumber.label', default: -42.7 }],
|
||||||
|
|
||||||
[{ name: 'aString', type: 'string', i18n: 'aString.label' }],
|
[{ name: 'aString', type: 'string', i18n: 'aString.label' }],
|
||||||
[{ name: 'aString', type: 'string', i18n: 'aString.label', default: '' }],
|
[{ name: 'aString', type: 'string', i18n: 'aString.label', default: '' }],
|
||||||
[{ name: 'aString', type: 'string', i18n: 'aString.label', default: 'Seekra is great!' }],
|
[{ name: 'aString', type: 'string', i18n: 'aString.label', default: 'Seekra is great!' }],
|
||||||
@@ -617,7 +618,7 @@ describe('settingsValidator', () => {
|
|||||||
[{ name: 'enableFeature42', type: 'bool', i18n: 'feature.42.enable', default: [] }],
|
[{ name: 'enableFeature42', type: 'bool', i18n: 'feature.42.enable', default: [] }],
|
||||||
[{ name: 'enableFeature42', type: 'bool', i18n: 'feature.42.enable', default: {} }],
|
[{ name: 'enableFeature42', type: 'bool', i18n: 'feature.42.enable', default: {} }],
|
||||||
[{ name: 'enableFeature42', type: '', i18n: 'feature.42.enable', default: {} }],
|
[{ name: 'enableFeature42', type: '', i18n: 'feature.42.enable', default: {} }],
|
||||||
|
|
||||||
[{ name: '', type: 'number', i18n: 'aNumber.label' }],
|
[{ name: '', type: 'number', i18n: 'aNumber.label' }],
|
||||||
[{ name: 'aNumber', type: 'number', i18n: 'aNumber.label', default: '42' }],
|
[{ name: 'aNumber', type: 'number', i18n: 'aNumber.label', default: '42' }],
|
||||||
[{ name: 'aNumber', type: 'number', i18n: 'aNumber.label', default: 'zero' }],
|
[{ name: 'aNumber', type: 'number', i18n: 'aNumber.label', default: 'zero' }],
|
||||||
@@ -629,7 +630,7 @@ describe('settingsValidator', () => {
|
|||||||
[{ name: 'aNumber', type: 'number', i18n: 'aNumber.label', default: {} }],
|
[{ name: 'aNumber', type: 'number', i18n: 'aNumber.label', default: {} }],
|
||||||
[{ name: 'aNumber', type: '', i18n: 'aNumber.label', default: {} }],
|
[{ name: 'aNumber', type: '', i18n: 'aNumber.label', default: {} }],
|
||||||
[{ name: 'aNumber', type: '', i18n: 'aNumber.label', default: 42 }],
|
[{ name: 'aNumber', type: '', i18n: 'aNumber.label', default: 42 }],
|
||||||
|
|
||||||
[{ name: 'aString', type: 'string', i18n: '' }],
|
[{ name: 'aString', type: 'string', i18n: '' }],
|
||||||
[{ name: 'aString', type: 'string', i18n: 'aString.label', default: 42 }],
|
[{ name: 'aString', type: 'string', i18n: 'aString.label', default: 42 }],
|
||||||
[{ name: 'aString', type: 'string', i18n: 'aString.label', default: true }],
|
[{ name: 'aString', type: 'string', i18n: 'aString.label', default: true }],
|
||||||
@@ -809,4 +810,4 @@ describe('settingsValidator', () => {
|
|||||||
expect(() => assertString(value)).throws(Error);
|
expect(() => assertString(value)).throws(Error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ export const getSettingRecursively = function getSettingRecursively (sectionPath
|
|||||||
return oneSettingsLevel(cursor.slice(1, cursor.length), setting);
|
return oneSettingsLevel(cursor.slice(1, cursor.length), setting);
|
||||||
} else {
|
} else {
|
||||||
return setting;
|
return setting;
|
||||||
};
|
}
|
||||||
} else if (cursor.length <= 1) {
|
} else if (cursor.length <= 1) {
|
||||||
return setting;
|
return setting;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
return oneSettingsLevel(sectionPath, { content: settings });
|
return oneSettingsLevel(sectionPath, { content: settings });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,4 +28,4 @@ export const getSettingsPagePathSegments = function getSettingsPagePathSegments
|
|||||||
(segment) => segment.replace(/[^a-zA-Z0-9-]/g, '')
|
(segment) => segment.replace(/[^a-zA-Z0-9-]/g, '')
|
||||||
)
|
)
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2026 Seekra
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { validateSettingsConfig } from './settingsValidator.js';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads and parses the settings configuration via dynamic import.
|
|
||||||
* @returns {Promise<import('../types/settingsConfig').SettingsConfig>}
|
|
||||||
*/
|
|
||||||
export async function loadSettingsConfig() {
|
|
||||||
let raw;
|
|
||||||
|
|
||||||
try {
|
|
||||||
raw = (await import('../settings.json')).default;
|
|
||||||
} catch (e) {
|
|
||||||
throw new Error(`[settings] Failed to load settings.json: ${e.message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = validateSettingsConfig(raw);
|
|
||||||
if (!result.valid) {
|
|
||||||
throw new Error(result.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.config;
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,7 @@ export const assertString = function assertString (value, path) {
|
|||||||
if (typeof value !== 'string' || value.trim() === '') {
|
if (typeof value !== 'string' || value.trim() === '') {
|
||||||
throw new Error(`[settings] "${path}" must be a non-empty string`);
|
throw new Error(`[settings] "${path}" must be a non-empty string`);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
export const assertType = function assertType (value, path) {
|
export const assertType = function assertType (value, path) {
|
||||||
if (!VALID_TYPES.includes(value)) {
|
if (!VALID_TYPES.includes(value)) {
|
||||||
@@ -28,21 +28,21 @@ export const assertType = function assertType (value, path) {
|
|||||||
`[settings] "${path}" has invalid type "${value}". Must be one of: ${VALID_TYPES.join(', ')}`
|
`[settings] "${path}" has invalid type "${value}". Must be one of: ${VALID_TYPES.join(', ')}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
export const validateSelectionOptions = function validateSelectionOptions (options, path) {
|
export const validateSelectionOptions = function validateSelectionOptions (options, path) {
|
||||||
if (!Array.isArray(options) || options.length === 0) {
|
if (!Array.isArray(options) || options.length === 0) {
|
||||||
throw new Error(`[settings] "${path}.options" must be a non-empty array`);
|
throw new Error(`[settings] "${path}.options" must be a non-empty array`);
|
||||||
};
|
}
|
||||||
options.forEach((opt, i) => {
|
options.forEach((opt, i) => {
|
||||||
assertString(opt.name, `${path}.options[${i}].name`);
|
assertString(opt.name, `${path}.options[${i}].name`);
|
||||||
assertString(opt.i18n, `${path}.options[${i}].i18n`);
|
assertString(opt.i18n, `${path}.options[${i}].i18n`);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
export const validateEntry = function validateEntry (entry, path) {
|
export const validateEntry = function validateEntry (entry, path) {
|
||||||
assertType(entry.type, `${path}.type`);
|
assertType(entry.type, `${path}.type`);
|
||||||
|
|
||||||
assertString(entry.name, `${path}.name`);
|
assertString(entry.name, `${path}.name`);
|
||||||
assertString(entry.i18n, `${path}.i18n`);
|
assertString(entry.i18n, `${path}.i18n`);
|
||||||
|
|
||||||
@@ -55,13 +55,13 @@ export const validateEntry = function validateEntry (entry, path) {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.type === 'selection') {
|
if (entry.type === 'selection') {
|
||||||
validateSelectionOptions(entry.options, path);
|
validateSelectionOptions(entry.options, path);
|
||||||
if (typeof entry.allowMultiple !== 'boolean' && entry.allowMultiple) {
|
if (typeof entry.allowMultiple !== 'boolean' && entry.allowMultiple) {
|
||||||
throw new Error(`[settings] "${path}.allowMultiple" must be a boolean`);
|
throw new Error(`[settings] "${path}.allowMultiple" must be a boolean`);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
if (entry.default !== undefined) {
|
if (entry.default !== undefined) {
|
||||||
if (entry.type === 'bool' && typeof entry.default !== 'boolean') {
|
if (entry.type === 'bool' && typeof entry.default !== 'boolean') {
|
||||||
throw new Error(`[settings] "${path}.default" must be a boolean`);
|
throw new Error(`[settings] "${path}.default" must be a boolean`);
|
||||||
@@ -89,14 +89,14 @@ export const validateEntry = function validateEntry (entry, path) {
|
|||||||
} else {
|
} else {
|
||||||
if (typeof entry.default !== 'string') {
|
if (typeof entry.default !== 'string') {
|
||||||
throw new Error(`[settings] "${path}.default" must be a string`);
|
throw new Error(`[settings] "${path}.default" must be a string`);
|
||||||
};
|
}
|
||||||
if (!entry.options.map((option) => option.name).includes(entry.default)) {
|
if (!entry.options.map((option) => option.name).includes(entry.default)) {
|
||||||
throw new Error(`[settings] option "${path}.default" does not exist`);
|
throw new Error(`[settings] option "${path}.default" does not exist`);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
export const validateFirstLevelSection = function validateFirstLevelSection (section, path) {
|
export const validateFirstLevelSection = function validateFirstLevelSection (section, path) {
|
||||||
assertString(section.name);
|
assertString(section.name);
|
||||||
@@ -104,7 +104,7 @@ export const validateFirstLevelSection = function validateFirstLevelSection (sec
|
|||||||
|
|
||||||
if (!Array.isArray(section.content)) {
|
if (!Array.isArray(section.content)) {
|
||||||
throw new Error(`[settings] "${path}.content" must be an array`);
|
throw new Error(`[settings] "${path}.content" must be an array`);
|
||||||
};
|
}
|
||||||
|
|
||||||
section.content.forEach((entry, i) =>
|
section.content.forEach((entry, i) =>
|
||||||
validateEntry(entry, `${path}.content[${i}]`)
|
validateEntry(entry, `${path}.content[${i}]`)
|
||||||
@@ -117,18 +117,13 @@ export const validateFirstLevelSection = function validateFirstLevelSection (sec
|
|||||||
* @returns {{ valid: true, config: import('../types/settingsConfig').SettingsConfig } | { valid: false, error: string }}
|
* @returns {{ valid: true, config: import('../types/settingsConfig').SettingsConfig } | { valid: false, error: string }}
|
||||||
*/
|
*/
|
||||||
export function validateSettingsConfig(raw) {
|
export function validateSettingsConfig(raw) {
|
||||||
try {
|
if (!raw || typeof raw !== 'object') {
|
||||||
if (!raw || typeof raw !== 'object') {
|
throw new Error('[settings] Config must be an object');
|
||||||
throw new Error('[settings] Config must be an object');
|
|
||||||
}
|
|
||||||
if (!Array.isArray(raw.contents)) {
|
|
||||||
throw new Error('[settings] "contents" must be an array');
|
|
||||||
}
|
|
||||||
raw.contents.forEach((entry, i) =>
|
|
||||||
validateFirstLevelSection(entry, `contents[${i}]`)
|
|
||||||
);
|
|
||||||
return { valid: true, config: raw };
|
|
||||||
} catch (e) {
|
|
||||||
return { valid: false, error: e.message };
|
|
||||||
}
|
}
|
||||||
}
|
if (!Array.isArray(raw.contents)) {
|
||||||
|
throw new Error('[settings] "contents" must be an array');
|
||||||
|
}
|
||||||
|
raw.contents.forEach((entry, i) =>
|
||||||
|
validateFirstLevelSection(entry, `contents[${i}]`)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ limitations under the License.
|
|||||||
import LeftSidebarLayout from '@/layouts/LeftSidebarLayout.vue';
|
import LeftSidebarLayout from '@/layouts/LeftSidebarLayout.vue';
|
||||||
import SettingsPage from '../components/SettingsPage.vue';
|
import SettingsPage from '../components/SettingsPage.vue';
|
||||||
|
|
||||||
|
import settingsConfiguration from '../config.js';
|
||||||
import { getSettingRecursively } from '../utils/getSetting.js';
|
import { getSettingRecursively } from '../utils/getSetting.js';
|
||||||
import { loadSettingsConfig } from '../utils/settingsParser';
|
import { computed, onMounted, ref, watch } from 'vue';
|
||||||
import { onMounted, ref, watchEffect } from 'vue';
|
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
|
||||||
@@ -28,39 +28,27 @@ const { t } = useI18n();
|
|||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const settingsLoaded = ref(false)
|
const settings = settingsConfiguration.contents;
|
||||||
const settings = ref([]);
|
|
||||||
const activeSectionContent = ref({});
|
|
||||||
const activeSection = ref(null);
|
|
||||||
|
|
||||||
watchEffect(() => {
|
const activePath = computed(() => {
|
||||||
const segments = route.path
|
const segments = route.path
|
||||||
.split('/')
|
.split('/')
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|
||||||
activeSection.value = segments.slice(1, segments.length).join('.');
|
return segments.slice(1, segments.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateSettings = function updateSettings () {
|
const activeSection = ref(null);
|
||||||
if (activeSection.value) {
|
const updateSettings = async function updateSettings () {
|
||||||
const setting = getSettingRecursively(activeSection.value.split('.'), settings.value);
|
const setting = getSettingRecursively(activePath.value, settings);
|
||||||
if (!setting) {
|
if (setting) {
|
||||||
router.push('/settings');
|
activeSection.value = setting;
|
||||||
} else {
|
|
||||||
activeSectionContent.value = setting;
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
activeSectionContent.value = { content: [] };
|
await router.push('/settings');
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
|
watch(route, (newRoute) => updateSettings(newRoute));
|
||||||
onMounted(async () => {
|
onMounted(updateSettings);
|
||||||
settings.value = (await loadSettingsConfig()).contents;
|
|
||||||
watchEffect(() => {
|
|
||||||
updateSettings();
|
|
||||||
});
|
|
||||||
settingsLoaded.value = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
const toggleSidebarIfSmallScreen = function toggleSidebarIfSmallScreen (toggleSidebarFunction) {
|
const toggleSidebarIfSmallScreen = function toggleSidebarIfSmallScreen (toggleSidebarFunction) {
|
||||||
if (matchMedia('(max-width: 48rem)').matches) toggleSidebarFunction();
|
if (matchMedia('(max-width: 48rem)').matches) toggleSidebarFunction();
|
||||||
@@ -81,7 +69,7 @@ const toggleSidebarIfSmallScreen = function toggleSidebarIfSmallScreen (toggleSi
|
|||||||
<RouterLink
|
<RouterLink
|
||||||
:to="`/settings/${section.name}`"
|
:to="`/settings/${section.name}`"
|
||||||
class="button button-link link sidebar-section"
|
class="button button-link link sidebar-section"
|
||||||
:class="{ active: activeSection === section.name }"
|
:class="{ active: activeSection && activeSection.name === section.name }"
|
||||||
@click="toggleSidebarIfSmallScreen(toggleSidebar)"
|
@click="toggleSidebarIfSmallScreen(toggleSidebar)"
|
||||||
>
|
>
|
||||||
{{ t(section.i18n) }}
|
{{ t(section.i18n) }}
|
||||||
@@ -89,12 +77,9 @@ const toggleSidebarIfSmallScreen = function toggleSidebarIfSmallScreen (toggleSi
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</template>
|
</template>
|
||||||
<div v-if="!settingsLoaded" class="main-content--loading">
|
<div v-if="activeSection">
|
||||||
{{ t('loading') }}
|
|
||||||
</div>
|
|
||||||
<div v-else-if="activeSection" class="main-content--loaded">
|
|
||||||
<div class="settings-main-content">
|
<div class="settings-main-content">
|
||||||
<SettingsPage :setting="activeSectionContent" :path="activeSection" />
|
<SettingsPage :setting="activeSection" :path="activePath" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="main-content--no-section">
|
<div v-else class="main-content--no-section">
|
||||||
@@ -152,4 +137,4 @@ const toggleSidebarIfSmallScreen = function toggleSidebarIfSmallScreen (toggleSi
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ limitations under the License.
|
|||||||
|
|
||||||
import SettingsView from '../SettingsView.vue';
|
import SettingsView from '../SettingsView.vue';
|
||||||
import { mountComponent } from '@/test-utils/mountComponent.js';
|
import { mountComponent } from '@/test-utils/mountComponent.js';
|
||||||
import { flushPromises } from '@vue/test-utils';
|
|
||||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||||
|
import { nextTick } from 'vue';
|
||||||
|
|
||||||
const settingsHoisted = vi.hoisted(() => [
|
const settingsHoisted = vi.hoisted(() => [
|
||||||
{
|
{
|
||||||
@@ -197,10 +197,8 @@ const settings = settingsHoisted.values();
|
|||||||
const originalCurrentSection = 's0';
|
const originalCurrentSection = 's0';
|
||||||
let currentSection = originalCurrentSection;
|
let currentSection = originalCurrentSection;
|
||||||
|
|
||||||
vi.mock('../../utils/settingsParser', () => ({
|
vi.mock('../../config.js', () => ({
|
||||||
loadSettingsConfig: vi.fn().mockResolvedValue({
|
default: { contents: settingsHoisted }
|
||||||
contents: settingsHoisted
|
|
||||||
})
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('vue-router', async (importOriginal) => {
|
vi.mock('vue-router', async (importOriginal) => {
|
||||||
@@ -235,9 +233,7 @@ describe('SettingsView', () => {
|
|||||||
describe('sidebar', () => {
|
describe('sidebar', () => {
|
||||||
test('shows all top-level sections', async () => {
|
test('shows all top-level sections', async () => {
|
||||||
const wrapper = getWrapper();
|
const wrapper = getWrapper();
|
||||||
|
await nextTick();
|
||||||
await flushPromises();
|
|
||||||
await wrapper.vm.$nextTick();
|
|
||||||
|
|
||||||
const sidebarItems = wrapper.findAll('.sidebar-sections-list > li');
|
const sidebarItems = wrapper.findAll('.sidebar-sections-list > li');
|
||||||
settings.forEach((setting, index) => {
|
settings.forEach((setting, index) => {
|
||||||
@@ -254,47 +250,27 @@ describe('SettingsView', () => {
|
|||||||
|
|
||||||
describe('main', () => {
|
describe('main', () => {
|
||||||
describe('correct element', () => {
|
describe('correct element', () => {
|
||||||
test('shows that it is loading', () => {
|
|
||||||
const wrapper = getWrapper();
|
|
||||||
|
|
||||||
const mainContentLoading = wrapper.find('.main-content--loading');
|
|
||||||
const mainContentLoaded = wrapper.find('.main-content--loaded');
|
|
||||||
const mainContentNoSection = wrapper.find('.main-content--no-section');
|
|
||||||
|
|
||||||
expect(mainContentLoading.exists()).toBe(true);
|
|
||||||
expect(mainContentLoaded.exists()).toBe(false);
|
|
||||||
expect(mainContentNoSection.exists()).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('shows that no section is selected', async () => {
|
test('shows that no section is selected', async () => {
|
||||||
currentSection = '';
|
currentSection = '';
|
||||||
|
|
||||||
const wrapper = getWrapper();
|
const wrapper = getWrapper();
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
await flushPromises();
|
const mainContent = wrapper.find('.settings-main-content');
|
||||||
await wrapper.vm.$nextTick();
|
|
||||||
|
|
||||||
const mainContentLoading = wrapper.find('.main-content--loading');
|
|
||||||
const mainContentLoaded = wrapper.find('.main-content--loaded');
|
|
||||||
const mainContentNoSection = wrapper.find('.main-content--no-section');
|
const mainContentNoSection = wrapper.find('.main-content--no-section');
|
||||||
|
|
||||||
expect(mainContentLoading.exists()).toBe(false);
|
expect(mainContent.exists()).toBe(false);
|
||||||
expect(mainContentLoaded.exists()).toBe(false);
|
|
||||||
expect(mainContentNoSection.exists()).toBe(true);
|
expect(mainContentNoSection.exists()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('shows main content', async () => {
|
test('shows main content', async () => {
|
||||||
const wrapper = getWrapper();
|
const wrapper = getWrapper();
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
await flushPromises();
|
const mainContent = wrapper.find('.settings-main-content');
|
||||||
await wrapper.vm.$nextTick();
|
|
||||||
|
|
||||||
const mainContentLoading = wrapper.find('.main-content--loading');
|
|
||||||
const mainContentLoaded = wrapper.find('.main-content--loaded');
|
|
||||||
const mainContentNoSection = wrapper.find('.main-content--no-section');
|
const mainContentNoSection = wrapper.find('.main-content--no-section');
|
||||||
|
|
||||||
expect(mainContentLoading.exists()).toBe(false);
|
expect(mainContent.exists()).toBe(true);
|
||||||
expect(mainContentLoaded.exists()).toBe(true);
|
|
||||||
expect(mainContentNoSection.exists()).toBe(false);
|
expect(mainContentNoSection.exists()).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -303,4 +279,4 @@ describe('SettingsView', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
currentSection = originalCurrentSection;
|
currentSection = originalCurrentSection;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ const toggleSidebar = function toggleSidebar () {
|
|||||||
<div class="sidebar-controls">
|
<div class="sidebar-controls">
|
||||||
<SidebarExpandButton @click="toggleSidebar" class="sidebar-expand-button" />
|
<SidebarExpandButton @click="toggleSidebar" class="sidebar-expand-button" />
|
||||||
</div>
|
</div>
|
||||||
<div class="sidebar-content" v-if="props.expanded">
|
<div class="sidebar-content" v-show="props.expanded">
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
@@ -74,4 +74,4 @@ const toggleSidebar = function toggleSidebar () {
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
padding-top: 0;
|
padding-top: 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -38,4 +38,4 @@ const click = function click (event) {
|
|||||||
padding: 4px;
|
padding: 4px;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { createI18n } from 'vue-i18n';
|
import { createI18n } from 'vue-i18n';
|
||||||
import getCurrentLanguage from './utils/currentLanguage';
|
|
||||||
|
|
||||||
export const fallbackLocale = 'en';
|
export const fallbackLocale = 'en';
|
||||||
|
|
||||||
@@ -34,7 +33,7 @@ export const SUPPORTED_LANGUAGES = [
|
|||||||
|
|
||||||
export const i18n = createI18n({
|
export const i18n = createI18n({
|
||||||
legacy: false,
|
legacy: false,
|
||||||
locale: getCurrentLanguage(),
|
locale: fallbackLocale,
|
||||||
fallbackLocale: fallbackLocale,
|
fallbackLocale: fallbackLocale,
|
||||||
messages: {}
|
messages: {}
|
||||||
});
|
});
|
||||||
@@ -49,7 +48,7 @@ export async function loadLanguage (locale) {
|
|||||||
if (loadedLanguages.has(locale)) {
|
if (loadedLanguages.has(locale)) {
|
||||||
i18n.global.locale.value = locale;
|
i18n.global.locale.value = locale;
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
|
|
||||||
const messages = (await import(`./locales/${locale}.json`)).default;
|
const messages = (await import(`./locales/${locale}.json`)).default;
|
||||||
|
|
||||||
@@ -57,4 +56,10 @@ export async function loadLanguage (locale) {
|
|||||||
i18n.global.locale.value = locale;
|
i18n.global.locale.value = locale;
|
||||||
|
|
||||||
loadedLanguages.add(locale);
|
loadedLanguages.add(locale);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const setLocale = async function setLocale (locale) {
|
||||||
|
await loadLanguage(locale);
|
||||||
|
document.documentElement.lang = locale;
|
||||||
|
document.documentElement.dir = LANGUAGES_RTL.includes(locale) ? 'rtl' : 'ltr';
|
||||||
|
};
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ const toggleSidebar = function toggleSidebar () {
|
|||||||
.layout-container.expanded {
|
.layout-container.expanded {
|
||||||
grid-template-columns: 1fr 0;
|
grid-template-columns: 1fr 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.layout-container:not(.expanded) .sidebar-expand-button-container {
|
.layout-container:not(.expanded) .sidebar-expand-button-container {
|
||||||
justify-content: end;
|
justify-content: end;
|
||||||
display: block;
|
display: block;
|
||||||
@@ -100,4 +100,4 @@ const toggleSidebar = function toggleSidebar () {
|
|||||||
grid-area: main-content;
|
grid-area: main-content;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -60,6 +60,35 @@
|
|||||||
"option": {
|
"option": {
|
||||||
"ariaLabel": "Wählt die Option {option} aus"
|
"ariaLabel": "Wählt die Option {option} aus"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"appearance": {
|
||||||
|
"title": "Erscheinungsbild",
|
||||||
|
"contents": {
|
||||||
|
"colorScheme": {
|
||||||
|
"title": "Farbschema",
|
||||||
|
"options": {
|
||||||
|
"auto": "An Systemfarbschema anpassen",
|
||||||
|
"light": "Hell",
|
||||||
|
"dark": "Dunkel"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"general": {
|
||||||
|
"title": "Allgemein",
|
||||||
|
"settings": {
|
||||||
|
"language": {
|
||||||
|
"title": "Sprache"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"legal": {
|
||||||
|
"notice": {
|
||||||
|
"title": "Impressum",
|
||||||
|
"loadError": "Das Impressum konnte nicht geladen werden."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,35 @@
|
|||||||
"option": {
|
"option": {
|
||||||
"ariaLabel": "Selects option {option}"
|
"ariaLabel": "Selects option {option}"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"appearance": {
|
||||||
|
"title": "Appearance",
|
||||||
|
"contents": {
|
||||||
|
"colorScheme": {
|
||||||
|
"title": "Color Scheme",
|
||||||
|
"options": {
|
||||||
|
"auto": "Adapt to system color scheme",
|
||||||
|
"light": "Light",
|
||||||
|
"dark": "Dark"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"general": {
|
||||||
|
"title": "General",
|
||||||
|
"settings": {
|
||||||
|
"language": {
|
||||||
|
"title": "Language"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"legal": {
|
||||||
|
"notice": {
|
||||||
|
"title": "Legal Notice",
|
||||||
|
"loadError": "The legal notice could not be loaded."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,4 +62,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,4 +62,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,4 +62,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,4 +62,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,21 +15,23 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { getAssetsUrl } from './config/env';
|
import { getAssetsUrl } from './config/env';
|
||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue';
|
||||||
import { createPinia } from 'pinia';
|
import { createPinia } from 'pinia';
|
||||||
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';
|
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';
|
||||||
import App from './App.vue'
|
import App from './App.vue';
|
||||||
import { i18n, loadLanguage, fallbackLocale } from './i18n';
|
import { i18n, loadLanguage, fallbackLocale } from './i18n';
|
||||||
import getCurrentLanguage from './utils/currentLanguage';
|
import router from './router';
|
||||||
import router from './router'
|
import './styles/common.css';
|
||||||
import './styles/common.css'
|
import './styles/variables/colors.css';
|
||||||
import './styles/variables/colors.css'
|
|
||||||
import './styles/variables/dimensions.css';
|
import './styles/variables/dimensions.css';
|
||||||
|
|
||||||
import rawFonts from './styles/fonts.json';
|
import rawFonts from './styles/fonts.json';
|
||||||
import './styles/common.css';
|
import './styles/common.css';
|
||||||
import './styles/variables/colors.css';
|
import './styles/variables/colors.css';
|
||||||
|
|
||||||
|
import settings from './features/settings/config.js';
|
||||||
|
import { validateSettingsConfig } from './features/settings/utils/settingsValidator';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const fonts = rawFonts.map((font) => new FontFace(
|
const fonts = rawFonts.map((font) => new FontFace(
|
||||||
font.family ?? '',
|
font.family ?? '',
|
||||||
@@ -50,11 +52,12 @@ import './styles/variables/colors.css';
|
|||||||
fonts.forEach((font) => document.fonts.add(font));
|
fonts.forEach((font) => document.fonts.add(font));
|
||||||
|
|
||||||
await loadLanguage(fallbackLocale);
|
await loadLanguage(fallbackLocale);
|
||||||
await loadLanguage(getCurrentLanguage());
|
|
||||||
|
|
||||||
const pinia = createPinia();
|
const pinia = createPinia();
|
||||||
pinia.use(piniaPluginPersistedstate);
|
pinia.use(piniaPluginPersistedstate);
|
||||||
|
|
||||||
|
validateSettingsConfig(settings);
|
||||||
|
|
||||||
createApp(App)
|
createApp(App)
|
||||||
.use(router)
|
.use(router)
|
||||||
.use(i18n)
|
.use(i18n)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { createRouter, createWebHistory } from 'vue-router';
|
|||||||
import { i18n } from '@/i18n';
|
import { i18n } from '@/i18n';
|
||||||
|
|
||||||
import SearchView from '../views/SearchView.vue';
|
import SearchView from '../views/SearchView.vue';
|
||||||
|
import LegalNoticeView from '@/features/legal/views/LegalNoticeView.vue';
|
||||||
import SearchResultsView from '@/features/search/views/SearchResultsView.vue';
|
import SearchResultsView from '@/features/search/views/SearchResultsView.vue';
|
||||||
import SettingsView from '@/features/settings/views/SettingsView.vue';
|
import SettingsView from '@/features/settings/views/SettingsView.vue';
|
||||||
import NotFound from '../views/NotFound.vue';
|
import NotFound from '../views/NotFound.vue';
|
||||||
@@ -39,6 +40,14 @@ const routes = [
|
|||||||
title: (route) => route.query.q
|
title: (route) => route.query.q
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/legal/notice',
|
||||||
|
name: 'legalNotice',
|
||||||
|
component: LegalNoticeView,
|
||||||
|
meta: {
|
||||||
|
title: () => i18n.global.t('legal.notice.title')
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/settings/:rest(.*)*',
|
path: '/settings/:rest(.*)*',
|
||||||
name: 'settings',
|
name: 'settings',
|
||||||
@@ -69,7 +78,7 @@ export const updatePageTitle = function updatePageTitle (route) {
|
|||||||
document.title = `${title} - Seekra`;
|
document.title = `${title} - Seekra`;
|
||||||
} else {
|
} else {
|
||||||
document.title = 'Seekra';
|
document.title = 'Seekra';
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// remove trailing slash(es)
|
// remove trailing slash(es)
|
||||||
@@ -81,7 +90,7 @@ router.beforeEach((route) => {
|
|||||||
hash: route.hash,
|
hash: route.hash,
|
||||||
replace: true
|
replace: true
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ body {
|
|||||||
|
|
||||||
.link {
|
.link {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
color: var(--dark);
|
||||||
}
|
}
|
||||||
|
|
||||||
.link:hover:not(.button-link), .link:focus-visible:not(.button-link) {
|
.link:hover:not(.button-link), .link:focus-visible:not(.button-link) {
|
||||||
@@ -91,4 +92,12 @@ input {
|
|||||||
/* Temporary until a custom tap highlight is implemented. */
|
/* Temporary until a custom tap highlight is implemented. */
|
||||||
* {
|
* {
|
||||||
-webkit-tap-highlight-color: transparent;
|
-webkit-tap-highlight-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
background-color: var(--color-negative-bg);
|
||||||
|
border: 1px solid var(--color-negative-border);
|
||||||
|
padding: 1em 2em;
|
||||||
|
border-radius: 1.2em;
|
||||||
|
color: var(--white);
|
||||||
|
}
|
||||||
|
|||||||
@@ -84,6 +84,9 @@ body {
|
|||||||
--light-hover: var(--light-d-2);
|
--light-hover: var(--light-d-2);
|
||||||
|
|
||||||
--invert: invert(0);
|
--invert: invert(0);
|
||||||
|
|
||||||
|
--color-negative-bg: oklch(59% 0.22706 29.244);
|
||||||
|
--color-negative-border: oklch(51% 0.22706 29.244);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
@@ -152,4 +155,4 @@ body.dark {
|
|||||||
--light-hover: var(--light-d-5);
|
--light-hover: var(--light-d-5);
|
||||||
|
|
||||||
--invert: invert(1);
|
--invert: invert(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
:root {
|
:root {
|
||||||
--input-padding: 0.7em;
|
--input-padding: 0.7em;
|
||||||
--input-height: 1em;
|
--input-height: 1em;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,4 +59,4 @@ export const mountComponent = function mountComponent (component, options = {},
|
|||||||
},
|
},
|
||||||
...options
|
...options
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -121,4 +121,4 @@ describe('cssDimensions', () => {
|
|||||||
])('ensureUnit returns $expected with input $dimension', ({ dimension, expected }) => {
|
])('ensureUnit returns $expected with input $dimension', ({ dimension, expected }) => {
|
||||||
expect(ensureUnit(dimension)).toBe(expected);
|
expect(ensureUnit(dimension)).toBe(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2026 Seekra
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { describe, expect, test } from 'vitest';
|
|
||||||
import getCurrentLanguage from '../currentLanguage';
|
|
||||||
|
|
||||||
describe('currentLanguage', () => {
|
|
||||||
test.for([
|
|
||||||
{ navigatorLanguage: 'en', localStorageLanguage: null, expected: 'en'},
|
|
||||||
{ navigatorLanguage: 'de', localStorageLanguage: null, expected: 'de'},
|
|
||||||
{ navigatorLanguage: 'fr', localStorageLanguage: null, expected: 'fr'},
|
|
||||||
|
|
||||||
{ navigatorLanguage: 'en-US', localStorageLanguage: null, expected: 'en'},
|
|
||||||
{ navigatorLanguage: 'en-AU', localStorageLanguage: null, expected: 'en'},
|
|
||||||
{ navigatorLanguage: 'de-DE', localStorageLanguage: null, expected: 'de'},
|
|
||||||
{ navigatorLanguage: 'fr-FR', localStorageLanguage: null, expected: 'fr'},
|
|
||||||
|
|
||||||
{ navigatorLanguage: 'en-us', localStorageLanguage: null, expected: 'en'},
|
|
||||||
{ navigatorLanguage: 'en-au', localStorageLanguage: null, expected: 'en'},
|
|
||||||
{ navigatorLanguage: 'de-de', localStorageLanguage: null, expected: 'de'},
|
|
||||||
{ navigatorLanguage: 'fr-fr', localStorageLanguage: null, expected: 'fr'},
|
|
||||||
|
|
||||||
{ navigatorLanguage: 'zh-Hans-CN', localStorageLanguage: null, expected: 'zh'},
|
|
||||||
{ navigatorLanguage: 'zh-Hant-TW', localStorageLanguage: null, expected: 'zh'},
|
|
||||||
{ navigatorLanguage: 'uz-Latn-UZ', localStorageLanguage: null, expected: 'uz'},
|
|
||||||
|
|
||||||
{ navigatorLanguage: 'en-US-u-ca-gregory', localStorageLanguage: null, expected: 'en'},
|
|
||||||
{ navigatorLanguage: 'de-DE-u-co-phonebk', localStorageLanguage: null, expected: 'de'},
|
|
||||||
{ navigatorLanguage: 'zh-Hant-TW-u-co-phonebk', localStorageLanguage: null, expected: 'zh'},
|
|
||||||
|
|
||||||
{ navigatorLanguage: 'en', localStorageLanguage: 'de', expected: 'de'},
|
|
||||||
{ navigatorLanguage: 'de-DE', localStorageLanguage: 'en', expected: 'en'},
|
|
||||||
{ navigatorLanguage: 'de-de', localStorageLanguage: 'en', expected: 'en'},
|
|
||||||
{ navigatorLanguage: 'zh-Hans-CN', localStorageLanguage: 'fr', expected: 'fr'},
|
|
||||||
{ navigatorLanguage: 'en-US-u-ca-gregory', localStorageLanguage: 'zh', expected: 'zh'}
|
|
||||||
])('returns the language $expected (navigator: $navigatorLanguage; local storage: $localStorageLanguage)', ({ navigatorLanguage, localStorageLanguage, expected }) => {
|
|
||||||
Object.defineProperty(navigator, 'language', {
|
|
||||||
value: navigatorLanguage,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
|
|
||||||
if (localStorageLanguage) {
|
|
||||||
localStorage.setItem('locale', localStorageLanguage);
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(getCurrentLanguage()).toBe(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -25,7 +25,7 @@ export const ensureUnit = function (d) {
|
|||||||
// if it ends with a number
|
// if it ends with a number
|
||||||
if (/\d$/.test(d)) {
|
if (/\d$/.test(d)) {
|
||||||
d += 'px';
|
d += 'px';
|
||||||
};
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -53,4 +53,4 @@ const { t } = useI18n();
|
|||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ const submitSearch = function () {
|
|||||||
{{ t('slogan') }}
|
{{ t('slogan') }}
|
||||||
</span>
|
</span>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="search-container">
|
<div class="search-container">
|
||||||
<Searchbar v-model="searchQuery" ref="searchbar" class="search-bar" auto-submit />
|
<Searchbar v-model="searchQuery" ref="searchbar" class="search-bar" auto-submit />
|
||||||
</div>
|
</div>
|
||||||
@@ -83,4 +83,4 @@ const submitSearch = function () {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite';
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { createHtmlPlugin } from 'vite-plugin-html';
|
import { createHtmlPlugin } from 'vite-plugin-html';
|
||||||
|
|
||||||
@@ -39,4 +39,4 @@ export default defineConfig({
|
|||||||
globals: false,
|
globals: false,
|
||||||
environment: 'jsdom'
|
environment: 'jsdom'
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|||||||