Skip to content

Commit

Permalink
RISDEV-6042 Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-deazevedo committed Jan 14, 2025
1 parent 0f30427 commit e65f9c5
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions frontend/src/components/EditableList.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import type EditableListItem from '@/domain/editableListItem'
import DummyInputGroupVue from '@/kitchensink/components/DummyInputGroup.vue'
import DummyListItem from '@/kitchensink/domain/dummyListItem'
import { describe, it, expect, vi } from 'vitest'
import Reference from '@/domain/reference.ts'
import DocumentUnitReferenceInput from '@/components/periodical/DocumentUnitReferenceInput.vue'
import ReferenceSummary from '@/components/periodical/ReferenceSummary.vue'
import LegalPeriodical from '@/domain/legalPeriodical.ts'

const listWithEntries = ref<DummyListItem[]>([
new DummyListItem({ text: 'foo', uuid: '123' }),
Expand Down Expand Up @@ -211,4 +215,58 @@ describe('EditableList', () => {
expect(scrollIntoViewMock).toHaveBeenCalledTimes(1)
})
})

describe('EditableList with DocumentUnitInputReference', () => {
it('add reference', async () => {
// Arrange
await renderComponent({
editComponent: DocumentUnitReferenceInput,
summaryComponent: ReferenceSummary,
modelValue: [],
defaultValue: new Reference(),
})
const user = userEvent.setup()

// Act
const openDropdownContainer = screen.getByLabelText('Dropdown öffnen')
await user.click(openDropdownContainer)
const dropdownItems = screen.getAllByLabelText('dropdown-option')
await user.click(dropdownItems[0])
const citationInput = screen.getByLabelText('Zitatstelle')
await user.type(citationInput, 'abcde')
await user.click(screen.getByLabelText('Fundstelle speichern'))

// Assert
expect(screen.getByText('BAnz abcde')).toBeInTheDocument()
})

it('edit reference', async () => {
// Arrange
await renderComponent<Reference>({
editComponent: DocumentUnitReferenceInput,
summaryComponent: ReferenceSummary,
modelValue: [
new Reference({
legalPeriodical: new LegalPeriodical({
title: 'Arbeitsrecht aktiv',
abbreviation: 'AA',
}),
citation: '12345',
}),
],
defaultValue: new Reference(),
})
const user = userEvent.setup()

// Act
await user.click(screen.getByTestId('list-entry-0'))
const citationInput = screen.getByLabelText('Zitatstelle')
await user.clear(citationInput)
await user.type(citationInput, 'abcde')
await user.click(screen.getByLabelText('Fundstelle speichern'))

// Assert
expect(screen.getByText('AA abcde')).toBeInTheDocument()
})
})
})

0 comments on commit e65f9c5

Please sign in to comment.