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

Revise 'About' Section #426

Merged
merged 24 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
181 changes: 154 additions & 27 deletions src/about/ui/bibliography.tsx

Large diffs are not rendered by default.

761 changes: 523 additions & 238 deletions src/about/ui/fragmentarium.tsx

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/bibliography/application/BibliographyService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jest.mock('bibliography/infrastructure/BibliographyRepository', () => {
return function () {
return {
find: jest.fn(),
findMany: jest.fn(),
search: jest.fn(),
update: jest.fn(),
create: jest.fn(),
Expand All @@ -20,6 +21,9 @@ const bibliographyService = new BibliographyService(bibliographyRepository)

const testData: TestData<BibliographyService>[] = [
new TestData('find', ['RN2020'], bibliographyRepository.find, [resultStub]),
new TestData('findMany', [['RN2020']], bibliographyRepository.findMany, [
[resultStub],
]),
new TestData('update', [resultStub], bibliographyRepository.update, [
resultStub,
]),
Expand Down
4 changes: 4 additions & 0 deletions src/bibliography/application/BibliographyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export default class BibliographyService implements BibliographySearch {
return this.bibliographyRepository.find(id)
}

findMany(ids: readonly string[]): Promise<readonly BibliographyEntry[]> {
return this.bibliographyRepository.findMany(ids)
}

update(entry: BibliographyEntry): Promise<BibliographyEntry> {
return this.bibliographyRepository.update(entry)
}
Expand Down
15 changes: 15 additions & 0 deletions src/bibliography/infrastructure/BibliographyRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { testDelegation, TestData } from 'test-support/utils'
import BibliographyRepository from './BibliographyRepository'
import BibliographyEntry from 'bibliography/domain/BibliographyEntry'
import ApiClient from 'http/ApiClient'
import { stringify } from 'query-string'

jest.mock('http/ApiClient')

Expand All @@ -25,6 +26,20 @@ const testData: TestData<BibliographyRepository>[] = [
[`/bibliography/${encodeURIComponent(id)}`, false],
Promise.resolve(resultStub)
),
new TestData(
'findMany',
[[id]],
apiClient.fetchJson,
[entry],
[
`/bibliography/list?${stringify(
{ ids: [id] },
{ arrayFormat: 'comma' }
)}`,
false,
],
Promise.resolve([resultStub])
),
new TestData(
'search',
[query],
Expand Down
10 changes: 10 additions & 0 deletions src/bibliography/infrastructure/BibliographyRepository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BibliographyEntry from 'bibliography/domain/BibliographyEntry'
import Promise from 'bluebird'
import ApiClient from 'http/ApiClient'
import { stringify } from 'query-string'

function createEntry(cslData) {
return new BibliographyEntry(cslData)
Expand All @@ -19,6 +20,15 @@ export default class BibliographyRepository {
.then(createEntry)
}

findMany(ids: readonly string[]): Promise<readonly BibliographyEntry[]> {
return this.apiClient
.fetchJson(
`/bibliography/list?${stringify({ ids }, { arrayFormat: 'comma' })}`,
false
)
.then((result) => result.map(createEntry))
}

search(query: string): Promise<BibliographyEntry[]> {
return this.apiClient
.fetchJson(`/bibliography?query=${encodeURIComponent(query)}`, false)
Expand Down
6 changes: 6 additions & 0 deletions src/common/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ export function Markdown({
</ReactMarkdown>
)
}

export function MarkdownParagraph(
props: Omit<MarkdownProps, 'paragraph'>
): JSX.Element {
return <Markdown paragraph={'p'} {...props} />
}
45 changes: 33 additions & 12 deletions src/corpus/application/TextService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ChapterDisplay } from 'corpus/domain/chapter'
import textLineFixture, { textLineDto } from 'test-support/lines/text-line'
import { chapterDisplayDtoFactory } from 'test-support/chapter-fixtures'
import {
bibliographyEntryFactory,
cslDataFactory,
referenceDtoFactory,
referenceFactory,
Expand Down Expand Up @@ -582,8 +583,28 @@ test('inject ChapterDisplay', async () => {
}
}

const translationReference = referenceFactory.build()
const intertextReference = referenceFactory.build()
const translationReference = referenceFactory.build(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

{},
{
associations: {
document: bibliographyEntryFactory.build(
{},
{ associations: { id: 'XY1' } }
),
},
}
)
const intertextReference = referenceFactory.build(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

{},
{
associations: {
document: bibliographyEntryFactory.build(
{},
{ associations: { id: 'XY2' } }
),
},
}
)
const chapterWithReferences = produce(chapterDisplay, (draft) => {
draft.lines[0].translation[0].parts = [
createInjectedPart(translationReference),
Expand All @@ -607,11 +628,11 @@ test('inject ChapterDisplay', async () => {
]
})
apiClient.fetchJson.mockReturnValue(Bluebird.resolve(chapterWithReferences))
bibliographyServiceMock.find.mockReturnValueOnce(
Bluebird.resolve(translationReference.document)
bibliographyServiceMock.findMany.mockReturnValueOnce(
Bluebird.resolve([translationReference.document])
)
bibliographyServiceMock.find.mockReturnValueOnce(
Bluebird.resolve(intertextReference.document)
bibliographyServiceMock.findMany.mockReturnValueOnce(
Bluebird.resolve([intertextReference.document])
)
await expect(testService.findChapterDisplay(chapterId)).resolves.toEqual(
injectedChapter
Expand All @@ -620,12 +641,12 @@ test('inject ChapterDisplay', async () => {
`${chapterUrl}/display`,
false
)
expect(bibliographyServiceMock.find).toHaveBeenCalledWith(
translationReference.id
)
expect(bibliographyServiceMock.find).toHaveBeenCalledWith(
intertextReference.id
)
expect(bibliographyServiceMock.findMany).toHaveBeenCalledWith([
translationReference.id,
])
expect(bibliographyServiceMock.findMany).toHaveBeenCalledWith([
intertextReference.id,
])
})

test('listAllTexts', async () => {
Expand Down
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
5 changes: 4 additions & 1 deletion src/fragmentarium/application/FragmentService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jest.mock('./LemmatizationFactory')

jest.mock('bibliography/application/BibliographyService', () => {
return function () {
return { find: jest.fn(), search: jest.fn() }
return { find: jest.fn(), findMany: jest.fn(), search: jest.fn() }
}
})

Expand Down Expand Up @@ -229,6 +229,9 @@ describe('methods returning fragment', () => {
bibliographyService.find.mockImplementation((id: string) =>
Promise.reject(new Error(`${id} not found.`))
)
bibliographyService.findMany.mockImplementation((ids: string[]) =>
Promise.reject(new Error(`${ids} not found.`))
)
silenceConsoleErrors()
})

Expand Down
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
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
11 changes: 7 additions & 4 deletions src/test-support/bibliography-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ const authorFactory = Factory.define<
export const cslDataFactory = Factory.define<
CslData,
{ chance: Chance.Chance }
>(({ transientParams }) => {
>(({ transientParams, associations }) => {
const chance = transientParams.chance ?? defaultChance
const issuedDate = chance.date()
return {
id: chance.guid(),
id: associations.id ?? chance.guid(),
title: chance.sentence(),
type: chance.pickone(['article-journal', 'paper-conference']),
issued: {
Expand All @@ -65,10 +65,13 @@ export const cslDataWithContainerTitleShortFactory = cslDataFactory.params({
export const bibliographyEntryFactory = Factory.define<
BibliographyEntry,
CslData & { chance: Chance.Chance }
>(({ transientParams }) => {
>(({ transientParams, associations }) => {
const chance = transientParams.chance ?? defaultChance
return new BibliographyEntry(
cslDataFactory.build(transientParams, { transient: { chance } })
cslDataFactory.build(transientParams, {
transient: { chance },
associations,
})
)
})

Expand Down
27 changes: 22 additions & 5 deletions src/transliteration/application/ReferenceInjector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Text } from 'transliteration/domain/text'
import Promise from 'bluebird'
import { bibliographyEntryFactory } from 'test-support/bibliography-fixtures'
import Reference from 'bibliography/domain/Reference'
import { MarkupPart } from 'transliteration/domain/markup'
import { MarkupPart, TextPart } from 'transliteration/domain/markup'
import { NoteLine } from 'transliteration/domain/note-line'
import { ReferenceDto } from 'bibliography/domain/referenceDto'

Expand All @@ -16,11 +16,15 @@ const MockBibliographyService = BibliographyService as jest.Mock<
const bibliographyServiceMock = new MockBibliographyService()

const referenceInjector = new ReferenceInjector(bibliographyServiceMock)
const referenceId = 'RN1'

describe('ReferenceInjector', () => {
const entry = bibliographyEntryFactory.build()
const entry = bibliographyEntryFactory.build(
{},
{ associations: { id: referenceId } }
)
const referenceDto: ReferenceDto = {
id: 'RN1',
id: referenceId,
type: 'DISCUSSION',
pages: '5',
notes: '',
Expand All @@ -30,6 +34,14 @@ describe('ReferenceInjector', () => {
reference: referenceDto,
type: 'BibliographyPart',
}
const stringPart: TextPart = {
text: 'Lorem ipsum',
type: 'StringPart',
}
const emphasisPart: TextPart = {
text: 'Lorem ipsum',
type: 'EmphasisPart',
}
const reference = new Reference('DISCUSSION', '5', '', [], entry)
const injectedParts = [
{
Expand All @@ -44,6 +56,9 @@ describe('ReferenceInjector', () => {

beforeEach(() => {
bibliographyServiceMock.find.mockReturnValueOnce(Promise.resolve(entry))
bibliographyServiceMock.findMany.mockReturnValueOnce(
Promise.resolve([entry])
)
})

it('injects references to text', async () => {
Expand All @@ -58,8 +73,10 @@ describe('ReferenceInjector', () => {

it('injects references to MarkupParts', async () => {
return referenceInjector
.injectReferencesToMarkup([bibliographyPart])
.then((parts) => expect(parts).toEqual(injectedParts))
.injectReferencesToMarkup([emphasisPart, bibliographyPart, stringPart])
.then((parts) =>
expect(parts).toEqual([emphasisPart, ...injectedParts, stringPart])
)
})

it('injects references to OldLineNumbers', async () => {
Expand Down
Loading
Loading