Skip to content

Commit

Permalink
Correct tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ejimsan committed Nov 14, 2024
1 parent 03ff85f commit ba1393f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
11 changes: 10 additions & 1 deletion src/fragmentarium/domain/archaeology.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ test.each([
},
'some area > a house (Residential), II (1200 BCE - 1150 BCE), ' +
'Room 42, On the floor (primary context). General notes.',
'de-DE',
],
[
'with secondary context',
Expand All @@ -144,43 +145,51 @@ test.each([
date: null,
},
'a house (Residential), II, in shelf (secondary context).',
'de-DE',
],
[
'with area and notes',
{ area: 'some area', notes: 'General notes.' },
'some area > a house (Residential), II (1200 BCE - 1150 BCE). General notes.',
'de-DE',
],
[
'without area or notes',
{ area: '' },
'a house (Residential), II (1200 BCE - 1150 BCE).',
'en-US',
],
[
'without notes',
{ notes: '' },
'a house (Residential), II (1200 BCE - 1150 BCE).',
'en-US',
],
[
'without building',
{ building: '' },
'(Residential), II (1200 BCE - 1150 BCE).',
'de-DE',
],
[
'without buildingType',
{ buildingType: null },
'a house, II (1200 BCE - 1150 BCE).',
'en-US',
],
[
'without levelLayerPhase and date',
{ levelLayerPhase: '', date: null },
'a house (Residential).',
'de-DE',
],
[
'with date notes',
{
date: { ...defaultParams.date, notes: 'date notes' },
},
'a house (Residential), II (1200 BCE - 1150 BCE, date notes).',
'en-US',
],
[
'with CE date (en-US)',
Expand Down Expand Up @@ -214,6 +223,6 @@ test.each([
...overrideParams,
})

expect(findspot.toString(locale)).toEqual(expected)
expect(findspot.toString()).toEqual(expected)
}
)
26 changes: 15 additions & 11 deletions src/fragmentarium/ui/info/Details.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,42 +171,47 @@ describe('All details', () => {
})

describe('ExcavationDate', () => {
beforeEach(() => {
fragmentService.fetchGenres.mockResolvedValue([])
fragmentService.fetchPeriods.mockResolvedValue([])
Object.defineProperty(navigator, 'language', {
value: 'en-US',
writable: true,
})
})

it('renders excavation date when isRegularExcavation is true', async () => {
const excavationDate = {
start: new PartialDate(2024, 10, 5),
start: new PartialDate(2024, 5, 10),
end: new PartialDate(2024, 10, 10),
}

fragment = fragmentFactory.build({
archaeology: {
isRegularExcavation: true,
date: excavationDate,
},
})

await renderDetails()

expect(screen.getByText('Regular Excavation')).toBeInTheDocument()
expect(screen.getByText('2024.10.052024.10.10')).toBeInTheDocument() // or use the specific date format
expect(screen.getByText('05/10/202410/10/2024')).toBeInTheDocument()
})

it('renders only start date when end date is missing', async () => {
const excavationDate = {
start: new PartialDate(2024, 10, 5),
start: new PartialDate(2024, 5, 10),
end: null,
}

fragment = fragmentFactory.build({
archaeology: {
isRegularExcavation: true,
date: excavationDate,
},
})

await renderDetails()

expect(screen.getByText('Regular Excavation')).toBeInTheDocument()
expect(screen.getByText('2024.10.05')).toBeInTheDocument()
expect(screen.getByText('05/10/2024')).toBeInTheDocument()
})

it('does not render excavation date when isRegularExcavation is false', async () => {
Expand All @@ -216,11 +221,10 @@ describe('ExcavationDate', () => {
date: undefined,
},
})

await renderDetails()

expect(screen.queryByText('Regular Excavation')).not.toBeInTheDocument()
expect(screen.queryByText('2024.10.05')).not.toBeInTheDocument()
expect(screen.queryByText(/Regular Excavation/)).not.toBeInTheDocument()
expect(screen.queryByText(/10\/05\/2024/)).not.toBeInTheDocument()
})
})

Expand Down

0 comments on commit ba1393f

Please sign in to comment.