From 99ae2725cdb7943ea5f5ab98737fc4d76ac174dc Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Tue, 28 Jul 2026 12:51:32 +0200 Subject: [PATCH] test(settings): refactor switch component test Added and used getWrapper function to switch component test to mount the component and avoid repeating code. --- .../components/__tests__/Switch.test.js | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/features/settings/components/__tests__/Switch.test.js b/src/features/settings/components/__tests__/Switch.test.js index 267929f..7edd6eb 100644 --- a/src/features/settings/components/__tests__/Switch.test.js +++ b/src/features/settings/components/__tests__/Switch.test.js @@ -20,6 +20,19 @@ import { useSettingsStore } from '../../stores/settingsStore.js'; import { expect, describe, test } from 'vitest'; import { nextTick } from 'vue'; +const getWrapper = function getWrapper ({ i18n = 'switch1', translations = {} } = {}) { + return mountComponent(Switch, { + attrs: { + setting: { + type: 'bool', + name: 'switch', + i18n + }, + path: 'switch' + } + }, translations); +}; + describe('Switch', () => { test('shows value from store', async () => { const wrapper = mountComponent(Switch, { @@ -50,16 +63,7 @@ describe('Switch', () => { }); test('toggles value in store', async () => { - const wrapper = mountComponent(Switch, { - attrs: { - setting: { - name: 'switch', - i18n: 'switch1', - type: 'bool' - }, - path: 'switch' - } - }); + const wrapper = getWrapper(); const switchElement = wrapper.find('.switch-wrapper'); @@ -78,18 +82,9 @@ describe('Switch', () => { test('shows correct translation', () => { const translation = 'Switch'; - const wrapper = mountComponent(Switch, { - attrs: { - setting: { - name: 'switch', - i18n: 'switch1', - type: 'bool' - }, - path: 'switch' - } - }, { - switch1: translation - }); + const wrapper = getWrapper({ + translations: { switch1: translation } + }) const label = wrapper.find('label'); expect(label.text()).toBe(translation);