Skip to content

Commit

Permalink
Findspot display (#404)
Browse files Browse the repository at this point in the history
* add DateRange interface

* implement Findspot interface

* use lodash capitalize

* prepare findspot class display

* update schema with findspot id

* pass findspotService through app

* add FindspotService

* refactor findspot from dto

* add findspot route

* remove debug log

* wrap ArchaeologyEditor in withData
to fetch findspot options

* add updateFindspot and renderFindspot

* add findspotServiceMock

* add findspotFactory

* update object dto conversions

* update tests

* extend dto transformation functions

* extend findspot factories

* add tests for dto functions

* change date datatype

* new date display logic

* refactoring, bug fixes

* add findspot display tests

* add helper functions, refactor

* better levelLayer mock

* better levelLayer mock

* add findspotService mocks

* refactor JsonApiClient

* refactor type

* make site optional

* add FindspotService test

* extract FindspotRepository

* fix typo

* add FindspotRepository test

* refactoring

* fix findspot update

* add findspots selection test

* shorter test values

* fix missing key

* longer test list

* prevent double whitespace
  • Loading branch information
fsimonjetz authored Nov 8, 2023
1 parent bbc9747 commit 50175bb
Show file tree
Hide file tree
Showing 22 changed files with 622 additions and 47 deletions.
6 changes: 1 addition & 5 deletions src/corpus/ui/ChapterViewSideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import { ChapterDisplay } from 'corpus/domain/chapter'

import './ChapterViewSideBar.sass'

function capitalize(word: string): string {
return word[0].toUpperCase() + word.substring(1)
}

function Switch({
target,
label = '',
Expand All @@ -24,7 +20,7 @@ function Switch({
return (
<Form.Switch
className="settings__switch"
label={label || capitalize(target)}
label={label || _.capitalize(target)}
id={_.uniqueId('sidebar-text-toggle-')}
onClick={() => {
dispatchRows({ target: target, type: isExpanded ? 'close' : 'expand' })
Expand Down
22 changes: 22 additions & 0 deletions src/fragmentarium/application/FindspotService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { findspotFactory } from 'test-support/fragment-fixtures'
import { FindspotService } from './FindspotService'
import { testDelegation, TestData } from 'test-support/utils'

const findspotRepository = {
fetchFindspots: jest.fn(),
}
const findspotService = new FindspotService(findspotRepository)
const expectedFindspots = findspotFactory.buildList(3)

const testData: TestData<FindspotService>[] = [
new TestData(
'fetchFindspots',
[],
findspotRepository.fetchFindspots,
expectedFindspots,
null,
Promise.resolve(expectedFindspots)
),
]

testDelegation(findspotService, testData)
11 changes: 11 additions & 0 deletions src/fragmentarium/application/FindspotService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Bluebird from 'bluebird'
import { Findspot } from 'fragmentarium/domain/archaeology'
import { FindspotRepository } from 'fragmentarium/infrastructure/FindspotRepository'

export class FindspotService {
constructor(private readonly findspotRepository: FindspotRepository) {}

fetchFindspots(): Bluebird<Findspot[]> {
return this.findspotRepository.fetchFindspots()
}
}
5 changes: 5 additions & 0 deletions src/fragmentarium/domain/Date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export interface DateField {
isUncertain?: boolean
}

export interface DateRange {
start: Date
end: Date
}

export interface MonthField extends DateField {
isIntercalary?: boolean
}
Expand Down
144 changes: 137 additions & 7 deletions src/fragmentarium/domain/archaeology.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,158 @@
import { archaeologyFactory } from 'test-support/fragment-fixtures'
import { SiteKey, createArchaeology, toArchaeologyDto } from './archaeology'
import _ from 'lodash'
import {
archaeologyFactory,
dateRangeFactory,
findspotFactory,
} from 'test-support/fragment-fixtures'
import {
BuildingType,
Findspot,
FindspotDto,
SiteKey,
createArchaeology,
excavationSites,
fromFindspotDto,
fromPlanDto,
toArchaeologyDto,
toFindspotDto,
toPlanDto,
} from './archaeology'
import MuseumNumber, { museumNumberToString } from './MuseumNumber'
import {
cslDataFactory,
referenceDtoFactory,
} from 'test-support/bibliography-fixtures'
import createReference from 'bibliography/application/createReference'

const excavationNumber: MuseumNumber = {
prefix: 'A',
number: '38',
suffix: '',
}
const archaeology = archaeologyFactory.build({
excavationNumber: museumNumberToString(excavationNumber),
const site: SiteKey = 'Assyria'

const cslData = cslDataFactory.build()
const referenceDto = referenceDtoFactory.build(
{ id: cslData.id },
{ associations: { document: cslData } }
)
const reference = createReference(referenceDto)
const planDto = {
svg: '<svg></svg>',
references: [referenceDto],
}
const plan = { svg: '<svg></svg>', references: [reference] }
const dateRange = dateRangeFactory.build()
const findspot = findspotFactory.build({
site: excavationSites[site],
dateRange: dateRange,
plans: [plan],
})
const findspotDto: FindspotDto = {
..._.pick(
findspot,
'area',
'building',
'buildingType',
'levelLayerPhase',
'room',
'context',
'primaryContext',
'notes',
'dateRange'
),
_id: findspot.id,
site: site,
plans: [planDto],
}
const displayParams: Partial<Findspot> = {
area: '',
building: 'a house',
buildingType: 'RESIDENTIAL' as BuildingType,
levelLayerPhase: 'II',
dateRange: {
start: -1200,
end: -1150,
notes: '',
},
notes: '',
}
const archaeology = archaeologyFactory.build(
{
excavationNumber: museumNumberToString(excavationNumber),
},
{
associations: {
findspot,
},
}
)

test('fromPlanDto', () => {
expect(fromPlanDto(planDto)).toEqual(plan)
})
test('toPlanDto', () => {
expect(toPlanDto(plan)).toEqual(planDto)
})
test('fromFindspotDto', () => {
expect(fromFindspotDto(findspotDto)).toEqual(findspot)
})
test('toFindspotDto', () => {
expect(toFindspotDto(findspot)).toEqual(findspotDto)
})
test('fromPlanDto', () => {
expect(fromPlanDto(planDto)).toEqual(plan)
})
test('toArchaeologyDto', () => {
expect(toArchaeologyDto(archaeology)).toEqual({
...archaeology,
site: archaeology.site?.name,
findspot: archaeology.findspot ? toFindspotDto(archaeology.findspot) : null,
})
})
test('createArchaeology', () => {
expect(
createArchaeology({
...archaeology,
excavationNumber: excavationNumber,
site: (archaeology.site?.name || '') as SiteKey,
...toArchaeologyDto(archaeology),
excavationNumber,
})
).toEqual(archaeology)
})
test.each([
[
'with area and notes',
{ ...displayParams, area: 'some area', notes: 'general notes' },
'some area > a house (Residential), II (1200 BCE - 1150 BCE), general notes.',
],
[
'no area and notes',
{ ...displayParams, area: '' },
'a house (Residential), II (1200 BCE - 1150 BCE).',
],
[
'no notes',
{ ...displayParams, notes: '' },
'a house (Residential), II (1200 BCE - 1150 BCE).',
],
[
'no buildingType',
{ ...displayParams, buildingType: null },
'a house, II (1200 BCE - 1150 BCE).',
],
[
'no levelLayerPhase and date',
{ ...displayParams, levelLayerPhase: '', dateRange: null },
'a house (Residential).',
],
[
'with date notes',
{
...displayParams,
dateRange: { ...displayParams.dateRange, notes: 'date notes' },
},
'a house (Residential), II (1200 BCE - 1150 BCE, date notes).',
],
])('Correctly builds findspot info %s', (_info, params, expected) => {
const findspot = findspotFactory.build(params)
expect(findspot.toString()).toEqual(expected)
})
Loading

0 comments on commit 50175bb

Please sign in to comment.