generated from Seekra/repository-template
Compare commits
31
Commits
a01abe67e1
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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
|
+34
@@ -21,8 +21,42 @@ limitations under the License.
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="theme-color" content="#0158D2" />
|
||||
<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>
|
||||
<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>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
|
||||
+12
-10
@@ -19,34 +19,36 @@ import Navbar from './features/nav/components/Navbar.vue';
|
||||
import Footer from './features/footer/components/Footer.vue';
|
||||
|
||||
import { updatePageTitle } from './router';
|
||||
import { useColorScheme } from './features/colorScheme/composables/useColorScheme';
|
||||
import { ref, provide, watch, watchEffect } from 'vue';
|
||||
import { useSettings } from './features/settings/composables/useSettings.js';
|
||||
import { computed, watch, watchEffect } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
const { getColorScheme, updateColorScheme } = useColorScheme();
|
||||
const colorScheme = ref('auto');
|
||||
provide('colorScheme', colorScheme);
|
||||
watch(colorScheme, (newValue) => {
|
||||
updateColorScheme(newValue);
|
||||
const { getSetting } = useSettings();
|
||||
const colorScheme = computed(() => getSetting(['appearance', 'colorScheme']));
|
||||
|
||||
const updateColorScheme = function updateColorScheme (newColorScheme) {
|
||||
document.body.style.setProperty(colorScheme, {
|
||||
auto: 'normal',
|
||||
dark: 'dark',
|
||||
light: 'light'
|
||||
});
|
||||
if (newValue === 'dark') {
|
||||
if (newColorScheme === 'dark') {
|
||||
document.body.classList.add('dark');
|
||||
} else {
|
||||
document.body.classList.remove('dark');
|
||||
}
|
||||
if (newValue === 'auto') {
|
||||
if (newColorScheme === 'auto') {
|
||||
document.body.classList.add('color-scheme-auto');
|
||||
} else {
|
||||
document.body.classList.remove('color-scheme-auto');
|
||||
}
|
||||
}
|
||||
watch(colorScheme, (newColorScheme) => {
|
||||
updateColorScheme(newColorScheme);
|
||||
});
|
||||
colorScheme.value = getColorScheme();
|
||||
updateColorScheme(colorScheme.value);
|
||||
|
||||
watchEffect(() => updatePageTitle(route));
|
||||
</script>
|
||||
|
||||
@@ -17,12 +17,14 @@ limitations under the License.
|
||||
<script setup>
|
||||
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';
|
||||
|
||||
const { t } = useI18n();
|
||||
const { getSetting, setSetting } = useSettings();
|
||||
|
||||
const colorScheme = inject('colorScheme');
|
||||
const colorScheme = computed(() => getSetting(['appearance', 'colorScheme']));
|
||||
|
||||
const colorSchemeNextMapper = {
|
||||
'light': 'dark',
|
||||
@@ -39,11 +41,15 @@ const colorSchemeIconMapper = {
|
||||
const getTooltipTranslation = function (colorScheme) {
|
||||
return t(`preferences.colorScheme.switch.${colorSchemeNextMapper[colorScheme]}`);
|
||||
};
|
||||
|
||||
const setColorScheme = function setColorScheme (newColorScheme) {
|
||||
setSetting(['appearance', 'colorScheme'], newColorScheme);
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<button class="color-scheme-button"
|
||||
@click="colorScheme = colorSchemeNextMapper[colorScheme]"
|
||||
@click="setColorScheme(colorSchemeNextMapper[colorScheme])"
|
||||
:aria-label="getTooltipTranslation(colorScheme)"
|
||||
:title="getTooltipTranslation(colorScheme)"
|
||||
>
|
||||
|
||||
@@ -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
|
||||
};
|
||||
};
|
||||
@@ -40,8 +40,20 @@ const copyrightPeriod =
|
||||
</RouterLink>
|
||||
<LanguageSwitchButton />
|
||||
</div>
|
||||
<div class="footer-segment">
|
||||
© {{ copyrightPeriod }} Seekra
|
||||
<div class="footer-segment legal-segment">
|
||||
<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>
|
||||
</footer>
|
||||
</template>
|
||||
@@ -64,4 +76,31 @@ const copyrightPeriod =
|
||||
.global-footer a {
|
||||
color: var(--dark);
|
||||
}
|
||||
|
||||
.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>
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -54,10 +54,9 @@ const props = defineProps({
|
||||
const store = useSettingsStore();
|
||||
|
||||
const optionType = computed(() => props.setting.allowMultiple ? 'checkbox' : 'radio');
|
||||
const selected = ref(normalizeSelectedValue(store.get(props.path) ?? props.setting.default));
|
||||
|
||||
watch(selected, (newValue) => {
|
||||
store.set(props.path, newValue);
|
||||
const selected = computed({
|
||||
get: () => normalizeSelectedValue(store.get(props.path) ?? props.setting.default),
|
||||
set: (value) => store.set(props.path, value)
|
||||
});
|
||||
|
||||
const labelId = useId();
|
||||
|
||||
@@ -90,6 +90,32 @@ describe('Selection', () => {
|
||||
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', () => {
|
||||
const wrapper = getWrapper({
|
||||
options: exampleOptions,
|
||||
|
||||
@@ -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('../../settings.json', () => ({
|
||||
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
|
||||
})
|
||||
);
|
||||
});
|
||||
@@ -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 '../settings.json';
|
||||
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,
|
||||
};
|
||||
}
|
||||
@@ -1,3 +1,30 @@
|
||||
{
|
||||
"contents": []
|
||||
}
|
||||
"contents": [
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -20,18 +20,10 @@ import { validateSettingsConfig, validateEntry, validateSelectionOptions, assert
|
||||
describe('settingsValidator', () => {
|
||||
describe('validateSettingsConfig', () => {
|
||||
test.for([
|
||||
{ raw: false, expected: false },
|
||||
{ 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: {
|
||||
{ settings: {
|
||||
contents: []
|
||||
}, expected: true },
|
||||
{ raw: {
|
||||
} },
|
||||
{ settings: {
|
||||
contents: [
|
||||
{
|
||||
name: 'general',
|
||||
@@ -45,8 +37,8 @@ describe('settingsValidator', () => {
|
||||
]
|
||||
}
|
||||
]
|
||||
}, expected: true },
|
||||
{ raw: {
|
||||
} },
|
||||
{ settings: {
|
||||
contents: [
|
||||
{
|
||||
name: 'general',
|
||||
@@ -71,8 +63,8 @@ describe('settingsValidator', () => {
|
||||
]
|
||||
},
|
||||
]
|
||||
}, expected: true },
|
||||
{ raw: {
|
||||
} },
|
||||
{ settings: {
|
||||
contents: [
|
||||
{
|
||||
name: 'general',
|
||||
@@ -128,12 +120,12 @@ describe('settingsValidator', () => {
|
||||
default: 'str'
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
]
|
||||
}, expected: true },
|
||||
{ raw: {
|
||||
} },
|
||||
{ settings: {
|
||||
contents: [
|
||||
{
|
||||
name: 'general',
|
||||
@@ -190,12 +182,283 @@ describe('settingsValidator', () => {
|
||||
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: [
|
||||
{
|
||||
type: 'bool',
|
||||
@@ -258,276 +521,14 @@ describe('settingsValidator', () => {
|
||||
default: 'str'
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
]
|
||||
}, expected: false },
|
||||
{ raw: {
|
||||
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
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
}, 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);
|
||||
});
|
||||
} }
|
||||
])('throws error', ({ settings }) => {
|
||||
expect(() => validateSettingsConfig(settings)).toThrow(Error)
|
||||
})
|
||||
});
|
||||
|
||||
describe('validateEntry', () => {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -117,18 +117,13 @@ export const validateFirstLevelSection = function validateFirstLevelSection (sec
|
||||
* @returns {{ valid: true, config: import('../types/settingsConfig').SettingsConfig } | { valid: false, error: string }}
|
||||
*/
|
||||
export function validateSettingsConfig(raw) {
|
||||
try {
|
||||
if (!raw || typeof raw !== '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 (!raw || typeof raw !== '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}]`)
|
||||
);
|
||||
}
|
||||
@@ -18,9 +18,9 @@ limitations under the License.
|
||||
import LeftSidebarLayout from '@/layouts/LeftSidebarLayout.vue';
|
||||
import SettingsPage from '../components/SettingsPage.vue';
|
||||
|
||||
import settingsConfiguration from '../settings.json';
|
||||
import { getSettingRecursively } from '../utils/getSetting.js';
|
||||
import { loadSettingsConfig } from '../utils/settingsParser';
|
||||
import { onMounted, ref, watchEffect } from 'vue';
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
|
||||
@@ -28,39 +28,27 @@ const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const settingsLoaded = ref(false)
|
||||
const settings = ref([]);
|
||||
const activeSectionContent = ref({});
|
||||
const activeSection = ref(null);
|
||||
const settings = settingsConfiguration.contents;
|
||||
|
||||
watchEffect(() => {
|
||||
const activePath = computed(() => {
|
||||
const segments = route.path
|
||||
.split('/')
|
||||
.filter(Boolean);
|
||||
|
||||
activeSection.value = segments.slice(1, segments.length).join('.');
|
||||
return segments.slice(1, segments.length);
|
||||
});
|
||||
|
||||
const updateSettings = function updateSettings () {
|
||||
if (activeSection.value) {
|
||||
const setting = getSettingRecursively(activeSection.value.split('.'), settings.value);
|
||||
if (!setting) {
|
||||
router.push('/settings');
|
||||
} else {
|
||||
activeSectionContent.value = setting;
|
||||
};
|
||||
const activeSection = ref(null);
|
||||
const updateSettings = async function updateSettings () {
|
||||
const setting = getSettingRecursively(activePath.value, settings);
|
||||
if (setting) {
|
||||
activeSection.value = setting;
|
||||
} else {
|
||||
activeSectionContent.value = { content: [] };
|
||||
};
|
||||
await router.push('/settings');
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
settings.value = (await loadSettingsConfig()).contents;
|
||||
watchEffect(() => {
|
||||
updateSettings();
|
||||
});
|
||||
settingsLoaded.value = true;
|
||||
});
|
||||
watch(route, (newRoute) => updateSettings(newRoute));
|
||||
onMounted(updateSettings);
|
||||
|
||||
const toggleSidebarIfSmallScreen = function toggleSidebarIfSmallScreen (toggleSidebarFunction) {
|
||||
if (matchMedia('(max-width: 48rem)').matches) toggleSidebarFunction();
|
||||
@@ -81,7 +69,7 @@ const toggleSidebarIfSmallScreen = function toggleSidebarIfSmallScreen (toggleSi
|
||||
<RouterLink
|
||||
:to="`/settings/${section.name}`"
|
||||
class="button button-link link sidebar-section"
|
||||
:class="{ active: activeSection === section.name }"
|
||||
:class="{ active: activeSection && activeSection.name === section.name }"
|
||||
@click="toggleSidebarIfSmallScreen(toggleSidebar)"
|
||||
>
|
||||
{{ t(section.i18n) }}
|
||||
@@ -89,12 +77,9 @@ const toggleSidebarIfSmallScreen = function toggleSidebarIfSmallScreen (toggleSi
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
<div v-if="!settingsLoaded" class="main-content--loading">
|
||||
{{ t('loading') }}
|
||||
</div>
|
||||
<div v-else-if="activeSection" class="main-content--loaded">
|
||||
<div v-if="activeSection">
|
||||
<div class="settings-main-content">
|
||||
<SettingsPage :setting="activeSectionContent" :path="activeSection" />
|
||||
<SettingsPage :setting="activeSection" :path="activePath" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="main-content--no-section">
|
||||
|
||||
@@ -16,8 +16,8 @@ limitations under the License.
|
||||
|
||||
import SettingsView from '../SettingsView.vue';
|
||||
import { mountComponent } from '@/test-utils/mountComponent.js';
|
||||
import { flushPromises } from '@vue/test-utils';
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
import { nextTick } from 'vue';
|
||||
|
||||
const settingsHoisted = vi.hoisted(() => [
|
||||
{
|
||||
@@ -197,10 +197,8 @@ const settings = settingsHoisted.values();
|
||||
const originalCurrentSection = 's0';
|
||||
let currentSection = originalCurrentSection;
|
||||
|
||||
vi.mock('../../utils/settingsParser', () => ({
|
||||
loadSettingsConfig: vi.fn().mockResolvedValue({
|
||||
contents: settingsHoisted
|
||||
})
|
||||
vi.mock('../../settings.json', () => ({
|
||||
default: { contents: settingsHoisted }
|
||||
}));
|
||||
|
||||
vi.mock('vue-router', async (importOriginal) => {
|
||||
@@ -235,9 +233,7 @@ describe('SettingsView', () => {
|
||||
describe('sidebar', () => {
|
||||
test('shows all top-level sections', async () => {
|
||||
const wrapper = getWrapper();
|
||||
|
||||
await flushPromises();
|
||||
await wrapper.vm.$nextTick();
|
||||
await nextTick();
|
||||
|
||||
const sidebarItems = wrapper.findAll('.sidebar-sections-list > li');
|
||||
settings.forEach((setting, index) => {
|
||||
@@ -254,47 +250,27 @@ describe('SettingsView', () => {
|
||||
|
||||
describe('main', () => {
|
||||
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 () => {
|
||||
currentSection = '';
|
||||
|
||||
const wrapper = getWrapper();
|
||||
await nextTick();
|
||||
|
||||
await flushPromises();
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
const mainContentLoading = wrapper.find('.main-content--loading');
|
||||
const mainContentLoaded = wrapper.find('.main-content--loaded');
|
||||
const mainContent = wrapper.find('.settings-main-content');
|
||||
const mainContentNoSection = wrapper.find('.main-content--no-section');
|
||||
|
||||
expect(mainContentLoading.exists()).toBe(false);
|
||||
expect(mainContentLoaded.exists()).toBe(false);
|
||||
expect(mainContent.exists()).toBe(false);
|
||||
expect(mainContentNoSection.exists()).toBe(true);
|
||||
});
|
||||
|
||||
test('shows main content', async () => {
|
||||
const wrapper = getWrapper();
|
||||
await nextTick();
|
||||
|
||||
await flushPromises();
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
const mainContentLoading = wrapper.find('.main-content--loading');
|
||||
const mainContentLoaded = wrapper.find('.main-content--loaded');
|
||||
const mainContent = wrapper.find('.settings-main-content');
|
||||
const mainContentNoSection = wrapper.find('.main-content--no-section');
|
||||
|
||||
expect(mainContentLoading.exists()).toBe(false);
|
||||
expect(mainContentLoaded.exists()).toBe(true);
|
||||
expect(mainContent.exists()).toBe(true);
|
||||
expect(mainContentNoSection.exists()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,6 +60,27 @@
|
||||
"option": {
|
||||
"ariaLabel": "Wählt die Option {option} aus"
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
"appearance": {
|
||||
"title": "Erscheinungsbild",
|
||||
"contents": {
|
||||
"colorScheme": {
|
||||
"title": "Farbschema",
|
||||
"options": {
|
||||
"auto": "An Systemfarbschema anpassen",
|
||||
"light": "Hell",
|
||||
"dark": "Dunkel"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"legal": {
|
||||
"notice": {
|
||||
"title": "Impressum",
|
||||
"loadError": "Das Impressum konnte nicht geladen werden."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,27 @@
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"legal": {
|
||||
"notice": {
|
||||
"title": "Legal Notice",
|
||||
"loadError": "The legal notice could not be loaded."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,9 @@ import rawFonts from './styles/fonts.json';
|
||||
import './styles/common.css';
|
||||
import './styles/variables/colors.css';
|
||||
|
||||
import settings from './features/settings/settings.json';
|
||||
import { validateSettingsConfig } from './features/settings/utils/settingsValidator';
|
||||
|
||||
(async () => {
|
||||
const fonts = rawFonts.map((font) => new FontFace(
|
||||
font.family ?? '',
|
||||
@@ -54,6 +57,8 @@ import './styles/variables/colors.css';
|
||||
|
||||
const pinia = createPinia();
|
||||
pinia.use(piniaPluginPersistedstate);
|
||||
|
||||
validateSettingsConfig(settings);
|
||||
|
||||
createApp(App)
|
||||
.use(router)
|
||||
|
||||
@@ -18,6 +18,7 @@ import { createRouter, createWebHistory } from 'vue-router';
|
||||
import { i18n } from '@/i18n';
|
||||
|
||||
import SearchView from '../views/SearchView.vue';
|
||||
import LegalNoticeView from '@/features/legal/views/LegalNoticeView.vue';
|
||||
import SearchResultsView from '@/features/search/views/SearchResultsView.vue';
|
||||
import SettingsView from '@/features/settings/views/SettingsView.vue';
|
||||
import NotFound from '../views/NotFound.vue';
|
||||
@@ -39,6 +40,14 @@ const routes = [
|
||||
title: (route) => route.query.q
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/legal/notice',
|
||||
name: 'legalNotice',
|
||||
component: LegalNoticeView,
|
||||
meta: {
|
||||
title: () => i18n.global.t('legal.notice.title')
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/settings/:rest(.*)*',
|
||||
name: 'settings',
|
||||
|
||||
+10
-1
@@ -24,6 +24,7 @@ body {
|
||||
|
||||
.link {
|
||||
text-decoration: none;
|
||||
color: var(--dark);
|
||||
}
|
||||
|
||||
.link:hover:not(.button-link), .link:focus-visible:not(.button-link) {
|
||||
@@ -91,4 +92,12 @@ input {
|
||||
/* Temporary until a custom tap highlight is implemented. */
|
||||
* {
|
||||
-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);
|
||||
|
||||
--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) {
|
||||
|
||||
Reference in New Issue
Block a user