From 702cf8704324faedad4ef977b24c57553f677992 Mon Sep 17 00:00:00 2001 From: Tini Tran <tinit@stud.ntnu.no> Date: Mon, 29 Apr 2024 15:44:32 +0200 Subject: [PATCH] build fix --- .../__tests__/create-form/BaseInput.spec.ts | 11 +++-- .../create-form/BaseTextArea.spec.ts | 10 ++++- .../__tests__/economy/ToggleButton.spec.ts | 16 +++---- .../economy/TransactionComponent.spec.ts | 42 +++++++++++++++---- .../milestonePath/MilestoneButton.spec.ts | 4 +- 5 files changed, 62 insertions(+), 21 deletions(-) diff --git a/src/components/__tests__/create-form/BaseInput.spec.ts b/src/components/__tests__/create-form/BaseInput.spec.ts index dbbe24e..abf5a60 100644 --- a/src/components/__tests__/create-form/BaseInput.spec.ts +++ b/src/components/__tests__/create-form/BaseInput.spec.ts @@ -29,8 +29,13 @@ describe('BaseInput', () => { const newValue = 'New Value' await input.setValue(newValue) - // Assert emitted event - expect(wrapper.emitted()['update:modelValue']).toBeTruthy() - expect(wrapper.emitted()['update:modelValue'][0][0]).toBe(newValue) + const emittedEvents = wrapper.emitted() + expect(emittedEvents).toBeTruthy() + + const updateModelValueEvents = emittedEvents['update:modelValue'] as any[] + expect(updateModelValueEvents).toBeTruthy() + + const newValueEmitted = updateModelValueEvents[0][0] + expect(newValueEmitted).toBe(newValue) }) }) diff --git a/src/components/__tests__/create-form/BaseTextArea.spec.ts b/src/components/__tests__/create-form/BaseTextArea.spec.ts index fbead70..07c9a5e 100644 --- a/src/components/__tests__/create-form/BaseTextArea.spec.ts +++ b/src/components/__tests__/create-form/BaseTextArea.spec.ts @@ -25,7 +25,13 @@ describe('BaseTextArea', () => { const newValue = 'New Value' await textarea.setValue(newValue) - expect(wrapper.emitted()['update:modelValue']).toBeTruthy() - expect(wrapper.emitted()['update:modelValue'][0][0]).toBe(newValue) + const emittedEvents = wrapper.emitted() + expect(emittedEvents).toBeTruthy() + + const updateModelValueEvents = emittedEvents['update:modelValue'] as any[] + expect(updateModelValueEvents).toBeTruthy() + + const newValueEmitted = updateModelValueEvents[0][0] + expect(newValueEmitted).toBe(newValue) }) }) diff --git a/src/components/__tests__/economy/ToggleButton.spec.ts b/src/components/__tests__/economy/ToggleButton.spec.ts index e2addb1..30d04e0 100644 --- a/src/components/__tests__/economy/ToggleButton.spec.ts +++ b/src/components/__tests__/economy/ToggleButton.spec.ts @@ -4,25 +4,27 @@ import ToggleButton from '@/components/economy/ToggleButton.vue' describe('ToggleButton', () => { it('toggles chart visibility when clicked', async () => { - const wrapper = mount(ToggleButton) + + const wrapper = mount(ToggleButton) as any expect(wrapper.vm.chartVisible).toBe(false) await wrapper.find('input[type="checkbox"]').trigger('change') expect(wrapper.vm.chartVisible).toBe(true) - }) it('emits toggle-chart event when clicked', async () => { - const wrapper = mount(ToggleButton) - + const wrapper = mount(ToggleButton) as any // Simulate clicking the toggle button await wrapper.find('input[type="checkbox"]').trigger('change') - - expect(wrapper.emitted('toggle-chart')).toBeTruthy() + const emittedEvents = wrapper.emitted() + expect(emittedEvents).toBeTruthy() + const toggleChartEmit = emittedEvents['toggle-chart'] as any[] // Type assertion to any[] + expect(toggleChartEmit).toBeTruthy() expect(wrapper.vm.chartVisible).toBe(true) await wrapper.find('input[type="checkbox"]').trigger('change') + expect(wrapper.emitted('toggle-chart')).toBeTruthy() - expect(wrapper.emitted('toggle-chart')[1][0]).toBe(false) + expect(toggleChartEmit[1][0]).toBe(false) }) }) diff --git a/src/components/__tests__/economy/TransactionComponent.spec.ts b/src/components/__tests__/economy/TransactionComponent.spec.ts index 2e9b91b..9e21ac4 100644 --- a/src/components/__tests__/economy/TransactionComponent.spec.ts +++ b/src/components/__tests__/economy/TransactionComponent.spec.ts @@ -20,16 +20,44 @@ describe('TransactionComponent', () => { }) // title rendering - expect(wrapper.find('.component-title').text()).toContain(title) + const titleElement = wrapper.find('.component-title') + if (titleElement.exists()) { + expect(titleElement.text()).toContain(title) + } else { + throw new Error('Title element not found'); + } - // date rendering - expect(wrapper.findAll('.component-right-field').at(0).text()).toContain(date) + // Find all component-right-field elements + const rightFieldElements = wrapper.findAll('.component-right-field') - // amount rendering - expect(wrapper.findAll('.component-right-field').at(1).text()).toContain(`${amount}kr`) + // Check if elements exist and have expected text content + if (rightFieldElements.length >= 3) { + // date rendering + const dateElement = rightFieldElements.at(0) + if (dateElement) { + expect(dateElement.text()).toContain(date) + } else { + throw new Error('Date element not found'); + } + + // amount rendering + const amountElement = rightFieldElements.at(1) + if (amountElement) { + expect(amountElement.text()).toContain(`${amount}kr`) + } else { + throw new Error('Amount element not found'); + } - // category rendering - expect(wrapper.findAll('.component-right-field').at(2).text()).toContain(category) + // category rendering + const categoryElement = rightFieldElements.at(2) + if (categoryElement) { + expect(categoryElement.text()).toContain(category) + } else { + throw new Error('Category element not found'); + } + } else { + throw new Error('Expected elements not found'); + } }) }) diff --git a/src/components/__tests__/milestonePath/MilestoneButton.spec.ts b/src/components/__tests__/milestonePath/MilestoneButton.spec.ts index a8b488b..523f41f 100644 --- a/src/components/__tests__/milestonePath/MilestoneButton.spec.ts +++ b/src/components/__tests__/milestonePath/MilestoneButton.spec.ts @@ -18,7 +18,7 @@ describe('MilestoneButton', () => { expect(wrapper.text()).toBe('Save') // button color - const buttonElement = wrapper.find('.save-button').element - expect(buttonElement.style.backgroundColor).toBe(buttonColor) + const buttonElement = wrapper.find('.save-button').element as HTMLElement + expect(buttonElement.style?.backgroundColor).toBe(buttonColor) }) }) -- GitLab