Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor museum #431

Merged
merged 18 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/fragmentarium/domain/Fragment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
year2017,
year2018,
} from 'test-support/record-fixtures'
import Museum from './museum'
import { Museums } from './museum'
import { LooseDollarLine } from 'transliteration/domain/dollar-lines'
import { Genres } from 'fragmentarium/domain/Genres'
import Reference from 'bibliography/domain/Reference'
Expand Down Expand Up @@ -84,7 +84,7 @@ const config: Parameters<typeof Fragment['create']>[0] = {
text: 'Some notes',
parts: [{ text: 'Some notes', type: 'StringPart' }],
},
museum: Museum.of('The museum'),
museum: Museums['THE_BRITISH_MUSEUM'],
references: [
new Reference(
'DISCUSSION',
Expand Down
3 changes: 2 additions & 1 deletion src/fragmentarium/domain/FragmentDtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Ur3Calendar,
} from 'chronology/domain/DateBase'
import { ArchaeologyDto } from './archaeologyDtos'
import { MuseumKey } from './museum'

interface MeasureDto {
value?: number
Expand Down Expand Up @@ -91,7 +92,7 @@ export default interface FragmentDto {
description: string
collection: string
legacyScript: string
museum: string
museum: MuseumKey
width: MeasureDto
length: MeasureDto
thickness: MeasureDto
Expand Down
10 changes: 1 addition & 9 deletions src/fragmentarium/domain/fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import produce, { castDraft, Draft, immerable } from 'immer'

import Reference from 'bibliography/domain/Reference'
import { Text } from 'transliteration/domain/text'
import Museum, { FragmentLink } from './museum'
import { Museum } from './museum'
import Folio from './Folio'
import { Genres } from 'fragmentarium/domain/Genres'
import { Joins } from './join'
Expand Down Expand Up @@ -218,14 +218,6 @@ export class Fragment {
})
}

get hasLink(): boolean {
return this.museum.hasFragmentLink(this)
}

getLink(): FragmentLink {
return this.museum.createLinkFor(this)
}

filterFolios(session: Session): Fragment {
return produce(this, (draft: Draft<Fragment>) => {
draft.folios = this.folios.filter((folio) =>
Expand Down
161 changes: 34 additions & 127 deletions src/fragmentarium/domain/museum.test.ts
Original file line number Diff line number Diff line change
@@ -1,145 +1,52 @@
import Museum from './museum'
import bmLogo from './The_British_Museum.png'
import ybcLogo from './YBC_small.jpg'
import {
externalNumbersFactory,
fragmentFactory,
} from 'test-support/fragment-fixtures'
import { Museum, Museums } from './museum'

describe.each([
[
'THE_BRITISH_MUSEUM',
'The British Museum',
bmLogo,
'https://britishmuseum.org/',
'London',
'GBR',
'https://www.britishmuseum.org/',
'© [The Trustees of the British Museum](https://www.britishmuseum.org/about_this_site/terms_of_use/copyright_and_permissions.aspx)',
],
[
'The Iraq Museum, Baghdad',
'',
'',
'THE_IRAQ_MUSEUM',
'The Iraq Museum',
'Baghdad',
'IRQ',
'https://theiraqmuseum.com/',
'By Permission of the State Board of Antiquities and Heritage and The Iraq Museum',
null,
null,
],
[
'Yale Babylonian Collection, Peabody Museum',
ybcLogo,
'https://babylonian-collection.yale.edu/',
'Courtesy of the [Yale Babylonian Collection](https://peabody.yale.edu/about-us/terms-use-what-you-need-know)',
],
['Other Museum', '', '', '', null, null],
] as [string, string, string, string][])('%s', (name, logo, url, copyright) => {
const museum: Museum = Museum.of(name)

test('name', () => {
expect(museum.name).toEqual(name)
})

test('logo', () => {
expect(museum.logo).toEqual(logo)
})

test('hasUrl', () => {
expect(museum.hasUrl).toEqual(url !== '')
})

test('url', () => {
expect(museum.url).toEqual(url)
})

test('hasCopyright', () => {
expect(museum.hasCopyright).toEqual(copyright !== '')
})

test('copyright', () => {
expect(museum.copyright).toEqual(copyright)
})
})

describe('BritishMuseum', () => {
const bmIdNumber = 'A 1234+43'
const link = {
name: 'The British Museum',
logo: bmLogo,
url: `https://www.britishmuseum.org/collection/object/${encodeURIComponent(
bmIdNumber
)}`,
label: `The British Museum object ${bmIdNumber}`,
}
const britishMuseum = Museum.of(link.name)

describe('hasFragmentLink', () => {
test('fragment has bmIdNumber', () => {
const fragment = fragmentFactory.build(
{},
{
associations: {
externalNumbers: externalNumbersFactory.build({ bmIdNumber }),
},
}
)
expect(britishMuseum.hasFragmentLink(fragment)).toEqual(true)
['UNKNOWN', '', '', '', '', ''],
])(
'%s',
(
key,
expectedName,
expectedcity,
expectedcountry,
expectedurl,
expectedcopyright = ''
) => {
const museum: Museum = Museums[key]
test('name', () => {
expect(museum.name).toEqual(expectedName)
})

test('fragment does not have bmIdNumber', () => {
const fragment = fragmentFactory.build(
{},
{
associations: {
externalNumbers: externalNumbersFactory.build({ bmIdNumber: '' }),
},
}
)
expect(britishMuseum.hasFragmentLink(fragment)).toEqual(false)
test('city', () => {
expect(museum.city).toEqual(expectedcity)
})
})

test('fragmentlink', () => {
const fragment = fragmentFactory.build(
{},
{
associations: {
externalNumbers: externalNumbersFactory.build({ bmIdNumber }),
},
}
)
expect(britishMuseum.createLinkFor(fragment)).toEqual(link)
})
})

describe('YaleBabylonianCollectionhMuseum', () => {
const accession = 'A 1234+4.3'
const expectedAccession = 'A 1234+4-3'
const link = {
name: 'Yale Babylonian Collection, Peabody Museum',
logo: ybcLogo,
url: `https://collections.peabody.yale.edu/search/Record/YPM-${encodeURIComponent(
expectedAccession
)}`,
label: `Yale Babylonian Collection, Peabody Museum`,
}
const ybc = Museum.of(link.name)

describe('hasFragmentLink', () => {
test('fragment has accession', () => {
const fragment = fragmentFactory.build({
accession,
})
expect(ybc.hasFragmentLink(fragment)).toEqual(true)
test('country', () => {
expect(museum.country).toEqual(expectedcountry)
})

test('fragment does not have accession', () => {
const fragment = fragmentFactory.build({
accession: '',
})
expect(ybc.hasFragmentLink(fragment)).toEqual(false)
test('url', () => {
expect(museum.url).toEqual(expectedurl)
})
})

test('fragmentlink', () => {
const fragment = fragmentFactory.build({
accession,
test('copyright', () => {
expect(museum?.copyright || '').toEqual(expectedcopyright)
})
expect(ybc.createLinkFor(fragment)).toEqual(link)
})
})
}
)
Loading
Loading