diff --git a/src/App.test.ts b/src/App.test.ts index e0a7dc246..ef8aad741 100644 --- a/src/App.test.ts +++ b/src/App.test.ts @@ -1,6 +1,6 @@ import AppDriver from 'test-support/AppDriver' import FakeApi from 'test-support/FakeApi' -import { statisticsFactory } from 'test-support/fragment-fixtures' +import { statisticsFactory } from 'test-support/fragment-data-fixtures' import { tabIds as aboutTabIds } from 'about/ui/about' test.each([ diff --git a/src/colophons/domain/Colophons.ts b/src/colophons/domain/Colophons.ts deleted file mode 100644 index 0f01d939a..000000000 --- a/src/colophons/domain/Colophons.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { Provenance } from 'corpus/domain/provenance' - -enum ColophonStatus { - Yes = 'Yes', - No = 'No', - Broken = 'Broken', - OnlyColophon = 'Only Colophon', -} - -enum ColophonType { - AsbA = 'Asb a', - AsbB = 'Asb b', - AsbC = 'Asb c', - AsbD = 'Asb d', - AsbE = 'Asb e', - AsbF = 'Asb f', - AsbG = 'Asb g', // BAK 321 - AsbH = 'Asb h', - AsbI = 'Asb i', - AsbK = 'Asb k', - AsbL = 'Asb l', - AsbM = 'Asb m', - AsbN = 'Asb n', - AsbO = 'Asb o', - AsbP = 'Asb p', - AsbQ = 'Asb q', - AsbRS = 'Asb r/s', - AsbT = 'Asb t', - AsbU = 'Asb u', - AsbV = 'Asb v', - AsbW = 'Asb w', - AsbUnclear = 'Asb Unclear', - NzkBAK293 = 'Nzk BAK 293', - NzkBAK294 = 'Nzk BAK 294', - NzkBAK295 = 'Nzk BAK 295', - NzkBAK296 = 'Nzk BAK 296', - NzkBAK297 = 'Nzk BAK 297', -} - -enum ColophonOwnership { - Library = 'Library', - Private = 'Private', - Individual = 'Individual', -} - -enum IndividualType { - Owner = 'Owner', - Scribe = 'Scribe', - Other = 'Other', -} - -interface Name { - value: string - isBroken: boolean - isUncertain: boolean -} - -interface Individual { - name: Name - sonOf: Name - grandsonOf: Name - family: Name - nativeOf: Provenance - type: IndividualType -} - -export interface Colophon { - colophonStatus: ColophonStatus - colophonOwnership: ColophonOwnership - colophonType: ColophonType[] - originalFrom: Provenance - writtenIn: Provenance - notesToScribalProcess: string - individuals: Individual[] -} diff --git a/src/fragmentarium/application/FindspotService.test.ts b/src/fragmentarium/application/FindspotService.test.ts index 18704766c..fecb7673b 100644 --- a/src/fragmentarium/application/FindspotService.test.ts +++ b/src/fragmentarium/application/FindspotService.test.ts @@ -1,4 +1,4 @@ -import { findspotFactory } from 'test-support/fragment-fixtures' +import { findspotFactory } from 'test-support/fragment-data-fixtures' import { FindspotService } from './FindspotService' import { testDelegation, TestData } from 'test-support/utils' diff --git a/src/fragmentarium/application/FragmentService.test.ts b/src/fragmentarium/application/FragmentService.test.ts index 4fe09546c..9e928dccc 100644 --- a/src/fragmentarium/application/FragmentService.test.ts +++ b/src/fragmentarium/application/FragmentService.test.ts @@ -17,10 +17,10 @@ import LemmatizationFactory from './LemmatizationFactory' import BibliographyService from 'bibliography/application/BibliographyService' import WordRepository from 'dictionary/infrastructure/WordRepository' import { - archaeologyFactory, fragmentFactory, manuscriptAttestationFactory, } from 'test-support/fragment-fixtures' +import { archaeologyFactory } from 'test-support/fragment-data-fixtures' import { bibliographyEntryFactory, referenceFactory, diff --git a/src/fragmentarium/domain/archaeology.test.ts b/src/fragmentarium/domain/archaeology.test.ts index 65d57c9e7..4b371f485 100644 --- a/src/fragmentarium/domain/archaeology.test.ts +++ b/src/fragmentarium/domain/archaeology.test.ts @@ -3,7 +3,7 @@ import { archaeologyFactory, dateRangeFactory, findspotFactory, -} from 'test-support/fragment-fixtures' +} from 'test-support/fragment-data-fixtures' import { BuildingType, Findspot, diff --git a/src/fragmentarium/infrastructure/FindspotRepository.test.ts b/src/fragmentarium/infrastructure/FindspotRepository.test.ts index 374905926..edd524cd3 100644 --- a/src/fragmentarium/infrastructure/FindspotRepository.test.ts +++ b/src/fragmentarium/infrastructure/FindspotRepository.test.ts @@ -1,4 +1,4 @@ -import { findspotFactory } from 'test-support/fragment-fixtures' +import { findspotFactory } from 'test-support/fragment-data-fixtures' import { ApiFindspotRepository } from './FindspotRepository' import { testDelegation, TestData } from 'test-support/utils' import { toFindspotDto } from 'fragmentarium/domain/archaeologyDtos' diff --git a/src/fragmentarium/infrastructure/FragmentRepository.test.ts b/src/fragmentarium/infrastructure/FragmentRepository.test.ts index 8619d3aa9..482f8e1d0 100644 --- a/src/fragmentarium/infrastructure/FragmentRepository.test.ts +++ b/src/fragmentarium/infrastructure/FragmentRepository.test.ts @@ -12,7 +12,7 @@ import { queryItemFactory } from 'test-support/query-item-factory' import { museumNumberToString } from 'fragmentarium/domain/MuseumNumber' import { Genre, Genres } from 'fragmentarium/domain/Genres' import { mesopotamianDateFactory } from 'test-support/date-fixtures' -import { archaeologyFactory } from 'test-support/fragment-fixtures' +import { archaeologyFactory } from 'test-support/fragment-data-fixtures' import { FragmentInfo, FragmentInfoDto } from 'fragmentarium/domain/fragment' const apiClient = { diff --git a/src/fragmentarium/infrastructure/ImageRepository.test.ts b/src/fragmentarium/infrastructure/ImageRepository.test.ts index f8bfe5d55..2f40d4d44 100644 --- a/src/fragmentarium/infrastructure/ImageRepository.test.ts +++ b/src/fragmentarium/infrastructure/ImageRepository.test.ts @@ -1,7 +1,7 @@ import Promise from 'bluebird' import ApiImageRepository from './ImageRepository' import Folio from 'fragmentarium/domain/Folio' -import { folioFactory } from 'test-support/fragment-fixtures' +import { folioFactory } from 'test-support/fragment-data-fixtures' const image = new Blob([''], { type: 'image/jpeg' }) diff --git a/src/fragmentarium/ui/createFragmentUrl.test.tsx b/src/fragmentarium/ui/createFragmentUrl.test.tsx index 3c56841bd..dfde09b1a 100644 --- a/src/fragmentarium/ui/createFragmentUrl.test.tsx +++ b/src/fragmentarium/ui/createFragmentUrl.test.tsx @@ -1,7 +1,7 @@ import Chance from 'chance' import { createFragmentUrl, createFragmentUrlWithFolio } from './FragmentLink' import { parseUrl } from 'query-string' -import { folioFactory } from 'test-support/fragment-fixtures' +import { folioFactory } from 'test-support/fragment-data-fixtures' const chance = new Chance() diff --git a/src/fragmentarium/ui/fragment/ArchaeologyEditor.test.tsx b/src/fragmentarium/ui/fragment/ArchaeologyEditor.test.tsx index 4f598a074..e849e17c2 100644 --- a/src/fragmentarium/ui/fragment/ArchaeologyEditor.test.tsx +++ b/src/fragmentarium/ui/fragment/ArchaeologyEditor.test.tsx @@ -7,7 +7,7 @@ import ArchaeologyEditor from './ArchaeologyEditor' import { archaeologyFactory, findspotFactory, -} from 'test-support/fragment-fixtures' +} from 'test-support/fragment-data-fixtures' import { Archaeology, Findspot, diff --git a/src/fragmentarium/ui/fragment/ColophonEditor.tsx b/src/fragmentarium/ui/fragment/ColophonEditor.tsx new file mode 100644 index 000000000..fef02f9e8 --- /dev/null +++ b/src/fragmentarium/ui/fragment/ColophonEditor.tsx @@ -0,0 +1,175 @@ +import React, { FormEvent, useState } from 'react' +import { Form, Button, Row } from 'react-bootstrap' +import { Provenance } from 'corpus/domain/provenance' +import { Fragment } from 'fragmentarium/domain/fragment' +import { + ColophonIndividualsInput, + ColophonOwnershipInput, + ColophonStatusInput, + ColophonTypeInput, +} from './ColophonEditorInputs' + +export enum ColophonStatus { + Yes = 'Yes', + No = 'No', + Broken = 'Broken', + OnlyColophon = 'Only Colophon', +} + +export enum ColophonType { + AsbA = 'Asb a', + AsbB = 'Asb b', + AsbC = 'Asb c', + AsbD = 'Asb d', + AsbE = 'Asb e', + AsbF = 'Asb f', + AsbG = 'Asb g', // BAK 321 + AsbH = 'Asb h', + AsbI = 'Asb i', + AsbK = 'Asb k', + AsbL = 'Asb l', + AsbM = 'Asb m', + AsbN = 'Asb n', + AsbO = 'Asb o', + AsbP = 'Asb p', + AsbQ = 'Asb q', + AsbRS = 'Asb r/s', + AsbT = 'Asb t', + AsbU = 'Asb u', + AsbV = 'Asb v', + AsbW = 'Asb w', + AsbUnclear = 'Asb Unclear', + NzkBAK293 = 'Nzk BAK 293', + NzkBAK294 = 'Nzk BAK 294', + NzkBAK295 = 'Nzk BAK 295', + NzkBAK296 = 'Nzk BAK 296', + NzkBAK297 = 'Nzk BAK 297', +} + +export enum ColophonOwnership { + Library = 'Library', + Private = 'Private', + Individual = 'Individual', +} + +export enum IndividualType { + Owner = 'Owner', + Scribe = 'Scribe', + Other = 'Other', +} + +export interface Name { + value: string + isBroken: boolean + isUncertain: boolean +} + +export interface Individual { + name?: Name + sonOf?: Name + grandsonOf?: Name + family?: Name + nativeOf?: Provenance + type?: IndividualType +} + +export interface Colophon { + colophonStatus: ColophonStatus + colophonOwnership?: ColophonOwnership + colophonType?: ColophonType + originalFrom?: Provenance + writtenIn?: Provenance + notesToScribalProcess?: string + individuals?: Individual[] +} + +interface Props { + fragment: Fragment + updateColophon: (colophon: Colophon) => Promise + disabled?: boolean +} + +const ColophonEditor: React.FC = ({ + fragment, + disabled, + updateColophon, +}) => { + // ToDo: Implement commented out + //const { colophon } = fragment + const [formData, setFormData] = useState({ + colophonStatus: ColophonStatus.No, //colophon?.colophonStatus || ColophonStatus.No, + colophonOwnership: ColophonOwnership.Library, //fragment.colophon?.colophonOwnership || ColophonOwnership.Library, + colophonType: ColophonType.AsbA, //fragment.colophon?.colophonType, + originalFrom: undefined, //colophon?.originalFrom, + writtenIn: undefined, //colophon?.writtenIn, + notesToScribalProcess: undefined, //colophon?.notesToScribalProcess, + individuals: [], //colophon?.individuals, + }) + const [error, setError] = useState(null) + + /* + const handleInputChange = ( + event: ChangeEvent + ) => { + const { name, value } = event.target + setFormData((prevState) => ({ + ...prevState, + [name]: value, + })) + } + */ + + const handleSelectChange = (name: string) => (selectedOption: any) => { + setFormData((prevState) => ({ + ...prevState, + [name]: selectedOption?.value, + })) + } + + const submit = async (event: FormEvent): Promise => { + event.preventDefault() + try { + await updateColophon(formData) + } catch (error) { + setError(error as Error) + } + } + + return ( +
+ + + + + + + + + + + + + +
+ ) +} + +export default ColophonEditor diff --git a/src/colophons/ui/ColophonEditor.tsx b/src/fragmentarium/ui/fragment/ColophonEditorInputs.tsx similarity index 51% rename from src/colophons/ui/ColophonEditor.tsx rename to src/fragmentarium/ui/fragment/ColophonEditorInputs.tsx index 250aed4f8..110fe5a95 100644 --- a/src/colophons/ui/ColophonEditor.tsx +++ b/src/fragmentarium/ui/fragment/ColophonEditorInputs.tsx @@ -1,97 +1,21 @@ -import React, { FormEvent, useState } from 'react' +import React from 'react' import { Form, Col, Button, Row } from 'react-bootstrap' import Select from 'react-select' - -import { Provenance } from 'corpus/domain/provenance' -import { Fragment } from 'fragmentarium/domain/fragment' - -enum ColophonStatus { - Yes = 'Yes', - No = 'No', - Broken = 'Broken', - OnlyColophon = 'Only Colophon', -} - -enum ColophonType { - AsbA = 'Asb a', - AsbB = 'Asb b', - AsbC = 'Asb c', - AsbD = 'Asb d', - AsbE = 'Asb e', - AsbF = 'Asb f', - AsbG = 'Asb g', // BAK 321 - AsbH = 'Asb h', - AsbI = 'Asb i', - AsbK = 'Asb k', - AsbL = 'Asb l', - AsbM = 'Asb m', - AsbN = 'Asb n', - AsbO = 'Asb o', - AsbP = 'Asb p', - AsbQ = 'Asb q', - AsbRS = 'Asb r/s', - AsbT = 'Asb t', - AsbU = 'Asb u', - AsbV = 'Asb v', - AsbW = 'Asb w', - AsbUnclear = 'Asb Unclear', - NzkBAK293 = 'Nzk BAK 293', - NzkBAK294 = 'Nzk BAK 294', - NzkBAK295 = 'Nzk BAK 295', - NzkBAK296 = 'Nzk BAK 296', - NzkBAK297 = 'Nzk BAK 297', -} - -enum ColophonOwnership { - Library = 'Library', - Private = 'Private', - Individual = 'Individual', -} - -enum IndividualType { - Owner = 'Owner', - Scribe = 'Scribe', - Other = 'Other', -} - -interface Name { - value: string - isBroken: boolean - isUncertain: boolean -} - -interface Individual { - name?: Name - sonOf?: Name - grandsonOf?: Name - family?: Name - nativeOf?: Provenance - type?: IndividualType -} - -export interface Colophon { - colophonStatus: ColophonStatus - colophonOwnership?: ColophonOwnership - colophonType?: ColophonType - originalFrom?: Provenance - writtenIn?: Provenance - notesToScribalProcess?: string - individuals?: Individual[] -} - -interface Props { - fragment: Fragment - updateColophon: (colophon: Colophon) => Promise - disabled?: boolean -} - -const ColophonStatusInput = ({ +import { + ColophonOwnership, + ColophonStatus, + ColophonType, + Individual, + IndividualType, +} from './ColophonEditor' + +export const ColophonStatusInput = ({ colophonStatus, onChange, }: { colophonStatus: ColophonStatus onChange -}) => { +}): JSX.Element => { const options = Object.values(ColophonStatus).map((status) => ({ value: status, label: status, @@ -109,13 +33,13 @@ const ColophonStatusInput = ({ ) } -const ColophonOwnershipInput = ({ +export const ColophonOwnershipInput = ({ colophonOwnership, onChange, }: { colophonOwnership?: ColophonOwnership onChange -}) => { +}): JSX.Element => { const options = Object.values(ColophonOwnership).map((ownership) => ({ value: ownership, label: ownership, @@ -138,13 +62,13 @@ const ColophonOwnershipInput = ({ ) } -const ColophonTypeInput = ({ +export const ColophonTypeInput = ({ colophonType, onChange, }: { colophonType?: ColophonType onChange -}) => { +}): JSX.Element => { const options = Object.values(ColophonType).map((type) => ({ value: type, label: type, @@ -162,13 +86,13 @@ const ColophonTypeInput = ({ ) } -const ColophonIndividualsInput = ({ +export const ColophonIndividualsInput = ({ individuals, onChange, }: { individuals: Individual[] onChange: (newIndividuals: Individual[]) => void -}) => { +}): JSX.Element => { const handleAddIndividual = () => { onChange([ ...individuals, @@ -193,7 +117,7 @@ const ColophonIndividualsInput = ({ field: keyof Individual, key: string, value: any - ) => { + ): void => { console.log(index, field, key, value) } @@ -224,7 +148,7 @@ const IndividualInput = ({ individual: Individual onUpdate: (field: keyof Individual, key: string, value: any) => void onRemove: () => void -}) => { +}): JSX.Element => { return ( @@ -267,88 +191,3 @@ const IndividualInput = ({ ) } - -const ColophonEditor: React.FC = ({ - fragment, - disabled, - updateColophon, -}) => { - // ToDo: Implement commented out - //const { colophon } = fragment - const [formData, setFormData] = useState({ - colophonStatus: ColophonStatus.No, //colophon?.colophonStatus || ColophonStatus.No, - colophonOwnership: ColophonOwnership.Library, //fragment.colophon?.colophonOwnership || ColophonOwnership.Library, - colophonType: ColophonType.AsbA, //fragment.colophon?.colophonType, - originalFrom: undefined, //colophon?.originalFrom, - writtenIn: undefined, //colophon?.writtenIn, - notesToScribalProcess: undefined, //colophon?.notesToScribalProcess, - individuals: [], //colophon?.individuals, - }) - const [error, setError] = useState(null) - - /* - const handleInputChange = ( - event: ChangeEvent - ) => { - const { name, value } = event.target - setFormData((prevState) => ({ - ...prevState, - [name]: value, - })) - } - */ - - const handleSelectChange = (name: string) => (selectedOption: any) => { - setFormData((prevState) => ({ - ...prevState, - [name]: selectedOption?.value, - })) - } - - const submit = async (event: FormEvent): Promise => { - event.preventDefault() - try { - await updateColophon(formData) - } catch (error) { - setError(error as Error) - } - } - - return ( -
- - - - - - - - - - - - - -
- ) -} - -export default ColophonEditor diff --git a/src/fragmentarium/ui/fragment/CuneiformFragment.test.tsx b/src/fragmentarium/ui/fragment/CuneiformFragment.test.tsx index 614fb12b5..9a3ab2e9f 100644 --- a/src/fragmentarium/ui/fragment/CuneiformFragment.test.tsx +++ b/src/fragmentarium/ui/fragment/CuneiformFragment.test.tsx @@ -13,10 +13,8 @@ import FragmentService from 'fragmentarium/application/FragmentService' import FragmentSearchService from 'fragmentarium/application/FragmentSearchService' import MemorySession, { Session } from 'auth/Session' import { referenceFactory } from 'test-support/bibliography-fixtures' -import { - folioPagerFactory, - fragmentFactory, -} from 'test-support/fragment-fixtures' +import { fragmentFactory } from 'test-support/fragment-fixtures' +import { folioPagerFactory } from 'test-support/fragment-data-fixtures' import { Fragment } from 'fragmentarium/domain/fragment' import { FindspotService } from 'fragmentarium/application/FindspotService' import AfoRegisterService from 'afo-register/application/AfoRegisterService' diff --git a/src/fragmentarium/ui/fragment/CuneiformFragmentEditor.tsx b/src/fragmentarium/ui/fragment/CuneiformFragmentEditor.tsx index 6e1fed4a2..3240b9127 100644 --- a/src/fragmentarium/ui/fragment/CuneiformFragmentEditor.tsx +++ b/src/fragmentarium/ui/fragment/CuneiformFragmentEditor.tsx @@ -18,7 +18,9 @@ import ArchaeologyEditor from 'fragmentarium/ui/fragment/ArchaeologyEditor' import { ArchaeologyDto } from 'fragmentarium/domain/archaeologyDtos' import { FindspotService } from 'fragmentarium/application/FindspotService' import { Session } from 'auth/Session' -import ColophonEditor, { Colophon } from 'colophons/ui/ColophonEditor' +import ColophonEditor, { + Colophon, +} from 'fragmentarium/ui/fragment/ColophonEditor' const ContentSection: FunctionComponent = ({ children, diff --git a/src/fragmentarium/ui/fragment/FragmentView.test.tsx b/src/fragmentarium/ui/fragment/FragmentView.test.tsx index 837099d8b..19da8ca6e 100644 --- a/src/fragmentarium/ui/fragment/FragmentView.test.tsx +++ b/src/fragmentarium/ui/fragment/FragmentView.test.tsx @@ -13,11 +13,11 @@ import FragmentSearchService from 'fragmentarium/application/FragmentSearchServi import MemorySession from 'auth/Session' import { DictionaryContext } from 'dictionary/ui/dictionary-context' import { referenceFactory } from 'test-support/bibliography-fixtures' +import { fragmentFactory } from 'test-support/fragment-fixtures' import { - folioFactory, folioPagerFactory, - fragmentFactory, -} from 'test-support/fragment-fixtures' + folioFactory, +} from 'test-support/fragment-data-fixtures' import { FragmentPagerData } from 'fragmentarium/domain/pager' import { wordFactory } from 'test-support/word-fixtures' import { Fragment } from 'fragmentarium/domain/fragment' diff --git a/src/fragmentarium/ui/front-page/Fragmentarium.test.tsx b/src/fragmentarium/ui/front-page/Fragmentarium.test.tsx index 75f4cf3c9..176fcbc22 100644 --- a/src/fragmentarium/ui/front-page/Fragmentarium.test.tsx +++ b/src/fragmentarium/ui/front-page/Fragmentarium.test.tsx @@ -11,8 +11,8 @@ import Bluebird from 'bluebird' import { fragmentFactory, fragmentInfoFactory, - statisticsFactory, } from 'test-support/fragment-fixtures' +import { statisticsFactory } from 'test-support/fragment-data-fixtures' import { Fragment, FragmentInfo } from 'fragmentarium/domain/fragment' import WordService from 'dictionary/application/WordService' import { queryItemOf } from 'test-support/utils' diff --git a/src/fragmentarium/ui/front-page/Statistics.test.tsx b/src/fragmentarium/ui/front-page/Statistics.test.tsx index 2a6997d46..e67e74545 100644 --- a/src/fragmentarium/ui/front-page/Statistics.test.tsx +++ b/src/fragmentarium/ui/front-page/Statistics.test.tsx @@ -3,7 +3,7 @@ import { render, screen } from '@testing-library/react' import { waitForSpinnerToBeRemoved } from 'test-support/waitForSpinnerToBeRemoved' import Promise from 'bluebird' import Statistics from './Statistics' -import { statisticsFactory } from 'test-support/fragment-fixtures' +import { statisticsFactory } from 'test-support/fragment-data-fixtures' let fragmentService let statistics diff --git a/src/fragmentarium/ui/images/FolioPager.test.tsx b/src/fragmentarium/ui/images/FolioPager.test.tsx index 92e180c63..cd85c10b2 100644 --- a/src/fragmentarium/ui/images/FolioPager.test.tsx +++ b/src/fragmentarium/ui/images/FolioPager.test.tsx @@ -3,10 +3,8 @@ import { render, screen } from '@testing-library/react' import { MemoryRouter } from 'react-router-dom' import { Promise } from 'bluebird' import FolioPager from './FolioPager' -import { - folioPagerFactory, - fragmentFactory, -} from 'test-support/fragment-fixtures' +import { fragmentFactory } from 'test-support/fragment-fixtures' +import { folioPagerFactory } from 'test-support/fragment-data-fixtures' import { Fragment } from 'fragmentarium/domain/fragment' import Folio from 'fragmentarium/domain/Folio' import { FolioPagerData } from 'fragmentarium/domain/pager' diff --git a/src/fragmentarium/ui/images/Images.test.tsx b/src/fragmentarium/ui/images/Images.test.tsx index 62d3f1f26..fa896068d 100644 --- a/src/fragmentarium/ui/images/Images.test.tsx +++ b/src/fragmentarium/ui/images/Images.test.tsx @@ -9,11 +9,11 @@ import Promise from 'bluebird' import Images from './Images' import Folio from 'fragmentarium/domain/Folio' import { Fragment } from 'fragmentarium/domain/fragment' +import { fragmentFactory } from 'test-support/fragment-fixtures' import { folioFactory, folioPagerFactory, - fragmentFactory, -} from 'test-support/fragment-fixtures' +} from 'test-support/fragment-data-fixtures' import { FolioPagerData } from 'fragmentarium/domain/pager' const photoUrl = 'http://example.com/folio.jpg' diff --git a/src/fragmentarium/ui/info/Details.test.tsx b/src/fragmentarium/ui/info/Details.test.tsx index deae494e4..fc9697510 100644 --- a/src/fragmentarium/ui/info/Details.test.tsx +++ b/src/fragmentarium/ui/info/Details.test.tsx @@ -9,12 +9,12 @@ import { Museums } from 'fragmentarium/domain/museum' import { Fragment } from 'fragmentarium/domain/fragment' import Promise from 'bluebird' import { Genres } from 'fragmentarium/domain/Genres' +import { fragmentFactory } from 'test-support/fragment-fixtures' import { archaeologyFactory, externalNumbersFactory, - fragmentFactory, measuresFactory, -} from 'test-support/fragment-fixtures' +} from 'test-support/fragment-data-fixtures' import { joinFactory } from 'test-support/join-fixtures' import { Periods } from 'common/period' import FragmentService from 'fragmentarium/application/FragmentService' diff --git a/src/fragmentarium/ui/info/ExternalResources.test.tsx b/src/fragmentarium/ui/info/ExternalResources.test.tsx index cc45c79c3..bd31ca6c9 100644 --- a/src/fragmentarium/ui/info/ExternalResources.test.tsx +++ b/src/fragmentarium/ui/info/ExternalResources.test.tsx @@ -2,10 +2,8 @@ import React from 'react' import { render, screen } from '@testing-library/react' import ExternalResources from './ExternalResources' -import { - externalNumbersFactory, - fragmentFactory, -} from 'test-support/fragment-fixtures' +import { fragmentFactory } from 'test-support/fragment-fixtures' +import { externalNumbersFactory } from 'test-support/fragment-data-fixtures' import { Fragment } from 'fragmentarium/domain/fragment' const cdliNumber = 'P 0000+q' diff --git a/src/fragmentarium/ui/info/Record.test.tsx b/src/fragmentarium/ui/info/Record.test.tsx index 5fe734f10..c7c9299e5 100644 --- a/src/fragmentarium/ui/info/Record.test.tsx +++ b/src/fragmentarium/ui/info/Record.test.tsx @@ -2,7 +2,7 @@ import React from 'react' import { render, screen } from '@testing-library/react' import { DateTime } from 'luxon' import Record from './Record' -import { recordFactory } from 'test-support/fragment-fixtures' +import { recordFactory } from 'test-support/fragment-data-fixtures' import { RecordEntry } from 'fragmentarium/domain/RecordEntry' let record: RecordEntry[] diff --git a/src/fragmentarium/ui/info/UncuratedReferences.test.tsx b/src/fragmentarium/ui/info/UncuratedReferences.test.tsx index ee8f681ba..d4a66eb0f 100644 --- a/src/fragmentarium/ui/info/UncuratedReferences.test.tsx +++ b/src/fragmentarium/ui/info/UncuratedReferences.test.tsx @@ -1,7 +1,7 @@ import React from 'react' import { render, screen } from '@testing-library/react' import UncuratedReferences from './UncuratedReferences' -import { uncuratedReferenceFactory } from 'test-support/fragment-fixtures' +import { uncuratedReferenceFactory } from 'test-support/fragment-data-fixtures' import { UncuratedReference } from 'fragmentarium/domain/fragment' let references: UncuratedReference[] diff --git a/src/fragmentarium/ui/line-to-vec/FragmentLineToVecRanking.test.tsx b/src/fragmentarium/ui/line-to-vec/FragmentLineToVecRanking.test.tsx index fc50c5ffc..ef33cd109 100644 --- a/src/fragmentarium/ui/line-to-vec/FragmentLineToVecRanking.test.tsx +++ b/src/fragmentarium/ui/line-to-vec/FragmentLineToVecRanking.test.tsx @@ -7,7 +7,7 @@ import Promise from 'bluebird' import { LineToVecRanking } from 'fragmentarium/domain/lineToVecRanking' import SessionContext from 'auth/SessionContext' import { Session } from 'auth/Session' -import { scriptFactory } from 'test-support/fragment-fixtures' +import { scriptFactory } from 'test-support/fragment-data-fixtures' import { Periods } from 'common/period' import { HelmetProvider } from 'react-helmet-async' import { helmetContext } from 'router/head' diff --git a/src/test-support/fragment-data-fixtures.tsx b/src/test-support/fragment-data-fixtures.tsx new file mode 100644 index 000000000..62849e626 --- /dev/null +++ b/src/test-support/fragment-data-fixtures.tsx @@ -0,0 +1,246 @@ +import { Factory } from 'fishery' +import { Chance } from 'chance' +import { + Measures, + Script, + UncuratedReference, +} from 'fragmentarium/domain/fragment' +import { RecordEntry } from 'fragmentarium/domain/RecordEntry' +import Folio from 'fragmentarium/domain/Folio' +import { referenceFactory } from './bibliography-fixtures' +import { periodModifiers, periods } from 'common/period' +import { ExternalNumbers } from 'fragmentarium/domain/FragmentDtos' +import { + Archaeology, + DateRange, + ExcavationPlan, + Findspot, + PartialDate, + excavationSites, +} from 'fragmentarium/domain/archaeology' +import { FolioPagerData, FragmentAndFolio } from 'fragmentarium/domain/pager' + +const defaultChance = new Chance() + +export function fragmentDate(chance: Chance.Chance = defaultChance): string { + return chance.date().toISOString() +} + +function fragmentDateRange(): string { + return `${fragmentDate()}/${fragmentDate()}` +} + +export function fragmentDescription( + chance: Chance.Chance = defaultChance +): string { + return `${chance.sentence()}\n${chance.sentence()}` +} + +export function fragmentCollection( + chance: Chance.Chance = defaultChance +): string { + return chance.pickone([ + 'Babylon', + 'Kuyunjik', + 'Nippur', + '', + 'Sippar', + 'Nimrud', + 'Ur', + 'Iraq', + 'Girsu', + 'Larsa', + 'Bābili', + 'Umma', + 'Kanesh', + 'uncertain', + 'Puzriš', + 'Shuruppak', + 'Kisurra', + 'Ešnunna', + 'Uruk', + 'Shibaniba', + 'Kalhu', + 'Tutub', + 'Susa', + 'Kish', + 'Anšan', + 'Lagash', + 'Assur', + 'Huzirina', + ]) +} + +export const statisticsFactory = Factory.define<{ + transliteratedFragments: number + lines: number +}>(() => ({ + transliteratedFragments: defaultChance.natural(), + lines: defaultChance.natural(), +})) + +class RecordFactory extends Factory { + historical(date: string | null = null) { + return this.params({ + date: date ?? fragmentDateRange(), + type: 'HistoricalTransliteration', + }) + } +} + +export const recordFactory = RecordFactory.define(({ transientParams }) => { + const chance = transientParams.chance ?? defaultChance + + return new RecordEntry({ + user: chance.last(), + date: fragmentDate(chance), + type: chance.pickone(['Transliteration', 'Collation', 'Revision']), + }) +}) + +export const measuresFactory = Factory.define( + ({ transientParams }) => { + const chance = transientParams.chance ?? defaultChance + return { + length: chance.floating({ min: 0, max: 100 }), + width: chance.floating({ min: 0, max: 100 }), + thickness: chance.floating({ min: 0, max: 100 }), + } + } +) + +export const folioFactory = Factory.define( + ({ associations, transientParams }) => { + const chance = transientParams.chance ?? defaultChance + + return new Folio({ + name: + associations.name ?? chance.pickone(['WGL', 'FWG', 'EL', 'AKG', 'MJG']), + number: associations.number ?? chance.string(), + }) + } +) + +export const folioPagerEntryFactory = Factory.define(() => ({ + fragmentNumber: defaultChance.string(), + folioNumber: defaultChance.string(), +})) + +export const folioPagerFactory = Factory.define( + ({ associations }) => ({ + previous: associations.previous ?? folioPagerEntryFactory.build(), + next: associations.next ?? folioPagerEntryFactory.build(), + }) +) + +export const uncuratedReferenceFactory = Factory.define( + () => ({ + document: defaultChance.sentence(), + pages: defaultChance.n(defaultChance.natural, 5), + }) +) + +export const scriptFactory = Factory.define