generated from Seekra/repository-template
Merge pull request 'Fix(settings): selection reactivity' (#184) from fix/selection-setting-reactivity into main
Deploy on dev / Deploy on dev (push) Successful in 38s
Deploy on dev / Deploy on dev (push) Successful in 38s
Reviewed-on: #184 Reviewed-by: Jakob Gregory
This commit was merged in pull request #184.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user