Skip to content

Commit

Permalink
Museum Enum
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikpaliwal committed Feb 11, 2024
1 parent 5491398 commit 0bb89a9
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports[`Show manuscript line details 1`] = `
<span
class="reference-popover__citation"
>
Estrada & Wolfe, 2068: 7477711662481408-4847418310918144
Estrada & Wolfe, 2069: 7477711662481408-4847418310918144
[
l. 4'.2., 3'.
]
Expand Down
30 changes: 30 additions & 0 deletions src/fragmentarium/domain/fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@ export interface ScriptDto {

export class Fragment {
readonly [immerable] = true
museumKey:
| 'ISTANBUL_ARKEOLOJI_MUSEUM'
| 'THE_IRAQ_MUSEUM'
| 'PENN_MUSEUM'
| 'ASHMOLEAN_MUSEUM'
| 'PHYSICIANS_COLLEGE_PHILADELPHIA'
| 'COUVENT_SAINT_ETIENNE'
| 'REDPATH_MUSEUM'
| 'HILPRECHT_COLLECTION'
| 'HEARST_MUSEUM'
| 'RYLANDS_INSTITUTE'
| 'KELSEY_MUSEUM'
| 'KUNSTHISTORISCHES_MUSEUM'
| 'LOUVRE'
| 'MUSEE_D_ART'
| 'MUSEES_ROYAUX'
| 'NATIONALMUSEET'
| 'OAKLAND_MUSEUM'
| 'ANCIENT_CULTURES_CHICAGO'
| 'PIERPONT_MORGAN'
| 'PONTIFICAL_BIBLICAL_INSTITUTE'
| 'ROSICRUCIAN_EGYPTIAN_MUSEUM'
| 'THE_BRITISH_MUSEUM'
| 'TRINITY_COLLEGE_DUBLIN'
| 'VATICAN_MUSEUMS'
| 'VORDERASIATISCHES_MUSEUM'
| 'THE_WALTERS_ART_MUSEUM'
| 'YALE_PEABODY_COLLECTION'
| 'ECOLE_PRATIQUE_DES_HAUTES_ETUDES'
| 'UNKNOWN'

constructor(
readonly number: string,
Expand Down
95 changes: 2 additions & 93 deletions src/fragmentarium/domain/museum.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { Museums, MuseumKey } from './museum'
import {
externalNumbersFactory,
fragmentFactory,
} from 'test-support/fragment-fixtures'

describe.each([
[
Expand All @@ -18,10 +14,10 @@ describe.each([
'The Iraq Museum',
'Baghdad',
'IRQ',
'',
'https://theiraqmuseum.com/',
'By Permission of the State Board of Antiquities and Heritage and The Iraq Museum',
],
['Other Museum', '', '', '', '', ''],
['UNKNOWN', '', '', '', '', ''],
] as [MuseumKey, string, string, string, string, string][])(
'%s',
(
Expand All @@ -33,7 +29,6 @@ describe.each([
expectedcopyright = ''
) => {
const museum = Museums[key]

test('name', () => {
expect(museum.name).toEqual(expectedName)
})
Expand All @@ -55,89 +50,3 @@ describe.each([
})
}
)

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

describe('hasFragmentLink', () => {
test('fragment has bmIdNumber', () => {
const fragment = fragmentFactory.build(
{},
{
associations: {
externalNumbers: externalNumbersFactory.build({ bmIdNumber }),
},
}
)
expect(britishMuseum.hasFragmentLink(fragment)).toEqual(true)
})

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

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',
url: `https://collections.peabody.yale.edu/search/Record/YPM-${encodeURIComponent(
expectedAccession
)}`,
label: `Yale Babylonian Collection, Peabody Museum`,
}
const ybc = Museums['YALE_PEABODY_COLLECTION']

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

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

test('fragmentlink', () => {
const fragment = fragmentFactory.build({
accession,
})
expect(ybc.createLinkFor(fragment)).toEqual(link)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ exports[`Snapshot 1`] = `
,
<time
datetime="2096-10-04"
datetime="2097-10-04"
>
4/10/2096
4/10/2097
</time>
)
</li>
Expand Down Expand Up @@ -108,7 +108,7 @@ exports[`Snapshot 1`] = `
<span
class="reference-popover__citation"
>
Fanti & Carr, 2036: 8970824935538688-3796097900216320
Fanti & Carr, 2037: 8970824935538688-3796097900216320
[
l. 4'.2., 2.
]
Expand All @@ -123,7 +123,7 @@ exports[`Snapshot 1`] = `
<span
class="reference-popover__citation"
>
Hall & Reid, 2089: 7020923936833536-4895425479835648
Hall & Reid, 2090: 7020923936833536-4895425479835648
[
l. 4'.2., 3'.
]
Expand Down Expand Up @@ -5906,7 +5906,7 @@ exports[`Snapshot 1`] = `
<span
class="reference-popover__citation"
>
White & Manca, 2070: 6525764484726784-1000123435843584
White & Manca, 2071: 6525764484726784-1000123435843584
[
l. 3'., 2.
]
Expand All @@ -5925,7 +5925,7 @@ exports[`Snapshot 1`] = `
<span
class="reference-popover__citation"
>
Martinez & Robin, 2112: 5946678584541184-5595938733162496
Martinez & Robin, 2113: 5946678584541184-5595938733162496
[
l. 3'., 4'.2.
]
Expand Down
33 changes: 7 additions & 26 deletions src/fragmentarium/ui/info/Details.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('All details', () => {
},
{
associations: {
museum: Museums['The British Museum'],
museumKey: 'THE_BRITISH_MUSEUM',
genres: new Genres([]),
joins: [
[
Expand All @@ -86,14 +86,14 @@ describe('All details', () => {
})

it('Renders museum', () => {
expect(screen.getByText(`${fragment.museum.name}`)).toBeInTheDocument()
const museum = Museums[fragment.museumKey]
expect(screen.getByText(museum.name)).toBeInTheDocument()
})

it('Links to museum home', () =>
expect(screen.getByText(fragment.museum.name)).toHaveAttribute(
'href',
'https://britishmuseum.org/'
))
it('Links to museum home', () => {
const museum = Museums[fragment.museumKey]
expect(screen.getByText(museum.name)).toHaveAttribute('href', museum.url)
})

it('Renders colection', () => {
expect(
Expand Down Expand Up @@ -192,22 +192,3 @@ describe('Missing details', () => {
expect(screen.getByText('Accession: -')).toBeInTheDocument()
})
})

describe('Unknown museum', () => {
beforeEach(async () => {
fragment = fragmentFactory.build(
{},
{
associations: {
museum: Museums['UNKNOWN'],
},
}
)
await renderDetails()
})

it('Does not link museum', () =>
expect(screen.queryByText(fragment.museum.name)).not.toHaveAttribute(
'href'
))
})
13 changes: 9 additions & 4 deletions src/fragmentarium/ui/info/Details.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'

import { Museums, MuseumKey } from 'fragmentarium/domain/museum'
import _ from 'lodash'
import { Fragment, Script } from 'fragmentarium/domain/fragment'
import FragmentLink from 'fragmentarium/ui/FragmentLink'
Expand All @@ -22,8 +22,13 @@ function Collection({ fragment: { collection } }: Props): JSX.Element {
return <>{collection && `(${collection} Collection)`}</>
}

function MuseumName({ fragment: { museum } }: Props): JSX.Element {
return museum.hasUrl ? (
interface MuseumNameProps {
museumKey: MuseumKey
}

const MuseumName: React.FC<MuseumNameProps> = ({ museumKey }) => {
const museum = Museums[museumKey]
return museum.url ? (
<ExternalLink href={museum.url}>{museum.name}</ExternalLink>
) : (
<>{museum.name}</>
Expand Down Expand Up @@ -107,7 +112,7 @@ function Details({
return (
<ul className="Details">
<li className="Details__item">
<MuseumName fragment={fragment} />
<MuseumName museumKey="THE_BRITISH_MUSEUM" />
</li>
<li className="Details__item">
<Collection fragment={fragment} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ exports[`Searching fragments by transliteration Displays corpus results when cli
<span
class="reference-popover__citation"
>
Giles & Alvarez, 2086: 5582194326110208-1406653725409280
Giles & Alvarez, 2087: 5582194326110208-1406653725409280
[
l. 1., 3'.
]
Expand All @@ -792,7 +792,7 @@ exports[`Searching fragments by transliteration Displays corpus results when cli
<span
class="reference-popover__citation"
>
Shaw & Robert, 2045: 6150545542742016-5917511180615680
Shaw & Robert, 2046: 6150545542742016-5917511180615680
[
l. 2., 1.
]
Expand Down Expand Up @@ -6565,7 +6565,7 @@ exports[`Searching fragments by transliteration Displays corpus results when cli
<span
class="reference-popover__citation"
>
Harrison & Palmieri, 2028: 5188341634957312-4059361584349184
Harrison & Palmieri, 2029: 5188341634957312-4059361584349184
[
l. 1., 2.
]
Expand All @@ -6584,7 +6584,7 @@ exports[`Searching fragments by transliteration Displays corpus results when cli
<span
class="reference-popover__citation"
>
Wise & Hudson, 2039: 1529496131862528-4383736143544320
Wise & Hudson, 2040: 1529496131862528-4383736143544320
[
l. 4'.2., 2.
]
Expand Down
2 changes: 1 addition & 1 deletion src/transliteration/ui/__snapshots__/markup.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports[`Markup 1`] = `
<span
class="reference-popover__citation"
>
Dickinson & Falciani, 2062: 6831522153758720-8434983175716864
Dickinson & Falciani, 2063: 6831522153758720-8434983175716864
[
l. 4'.2., 1.
]
Expand Down

0 comments on commit 0bb89a9

Please sign in to comment.