-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
bbc9747
commit 50175bb
Showing
22 changed files
with
622 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |
Oops, something went wrong.