diff --git a/src/afo-register/application/AfoRegisterService.test.ts b/src/afo-register/application/AfoRegisterService.test.ts index e69de29bb..ac96c87f3 100644 --- a/src/afo-register/application/AfoRegisterService.test.ts +++ b/src/afo-register/application/AfoRegisterService.test.ts @@ -0,0 +1,48 @@ +import { testDelegation, TestData } from 'test-support/utils' +import AfoRegisterService from 'afo-register/application/AfoRegisterService' +import AfoRegisterRepository from 'afo-register/infrastructure/AfoRegisterRepository' +import { stringify } from 'query-string' + +jest.mock('afo-register/infrastructure/AfoRegisterRepository', () => { + return function () { + return { + search: jest.fn(), + } + } +}) + +const resultStub = { + afoNumber: 'AfO 1', + page: '2', + text: 'some text', + textNumber: '5', +} +const afoRegisterRepository = new (AfoRegisterRepository as jest.Mock)() +const afoRegisterService = new AfoRegisterService(afoRegisterRepository) + +const testData: TestData[] = [ + new TestData( + 'search', + [ + stringify({ + afoNumber: 'AfO 1', + page: '2', + }), + ], + afoRegisterRepository.search, + [resultStub] + ), + new TestData( + 'search', + [ + stringify({ + text: 'some text', + textNumber: '5', + }), + ], + afoRegisterRepository.search, + [resultStub] + ), +] +describe('afoRegisterService', () => + testDelegation(afoRegisterService, testData)) diff --git a/src/afo-register/application/AfoRegisterService.ts b/src/afo-register/application/AfoRegisterService.ts index e69de29bb..cb0bd3266 100644 --- a/src/afo-register/application/AfoRegisterService.ts +++ b/src/afo-register/application/AfoRegisterService.ts @@ -0,0 +1,19 @@ +import Promise from 'bluebird' +import AfoRegisterRecord from 'afo-register/domain/Record' +import AfoRegisterRepository from 'afo-register/infrastructure/AfoRegisterRepository' + +export interface afoRegisterSearch { + search(query: string): Promise +} + +export default class AfoRegisterService implements afoRegisterSearch { + private readonly afoRegisterRepository: AfoRegisterRepository + + constructor(afoRegisterRepository: AfoRegisterRepository) { + this.afoRegisterRepository = afoRegisterRepository + } + + search(query: string): Promise { + return this.afoRegisterRepository.search(query) + } +} diff --git a/src/afo-register/infrastructure/AfoRegisterRepository.test.ts b/src/afo-register/infrastructure/AfoRegisterRepository.test.ts index 3528eacd8..c1c241da1 100644 --- a/src/afo-register/infrastructure/AfoRegisterRepository.test.ts +++ b/src/afo-register/infrastructure/AfoRegisterRepository.test.ts @@ -26,7 +26,7 @@ const testData: TestData[] = [ apiClient.fetchJson, [entry], [`/afo-register?${encodeURIComponent(query)}`, false], - Promise.resolve(entry) + Promise.resolve([entry]) ), ] diff --git a/src/afo-register/infrastructure/AfoRegisterRepository.ts b/src/afo-register/infrastructure/AfoRegisterRepository.ts index 7e04e6413..9b992d7c2 100644 --- a/src/afo-register/infrastructure/AfoRegisterRepository.ts +++ b/src/afo-register/infrastructure/AfoRegisterRepository.ts @@ -9,9 +9,10 @@ export default class BibliographyRepository { this.apiClient = apiClient } - search(query: string): Promise { - return this.apiClient - .fetchJson(`/afo-register?${encodeURIComponent(query)}`, false) - .then((result) => new AfoRegisterRecord(result)) + search(query: string): Promise { + return this.apiClient.fetchJson( + `/afo-register?${encodeURIComponent(query)}`, + false + ) } } diff --git a/src/bibliography/ui/Bibliography.tsx b/src/bibliography/ui/Bibliography.tsx index 4104753db..07d9ed956 100644 --- a/src/bibliography/ui/Bibliography.tsx +++ b/src/bibliography/ui/Bibliography.tsx @@ -1,7 +1,7 @@ import React from 'react' import { parse } from 'query-string' import { LinkContainer } from 'react-router-bootstrap' -import { Button } from 'react-bootstrap' +import { Button, Tab, Tabs } from 'react-bootstrap' import _ from 'lodash' import AppContent from 'common/AppContent' @@ -10,9 +10,10 @@ import BibliographySearch from './BibliographySearch' import SessionContext from 'auth/SessionContext' import './Bibliography.css' -import { SectionCrumb } from 'common/Breadcrumbs' +import { TextCrumb } from 'common/Breadcrumbs' import { Session } from 'auth/Session' -import { RouteComponentProps } from 'react-router-dom' +import { RouteComponentProps, useHistory } from 'react-router-dom' +import BibliographyService from 'bibliography/application/BibliographyService' function CreateButton({ session }: { session: Session }): JSX.Element { return ( @@ -27,31 +28,83 @@ function CreateButton({ session }: { session: Session }): JSX.Element { ) } -export default function Bibliography({ +function BibliographyReferences({ bibliographyService, location, }: { - bibliographyService + bibliographyService: BibliographyService } & RouteComponentProps): JSX.Element { const rawQuery = parse(location.search).query || '' const query = _.isArray(rawQuery) ? rawQuery.join('') : rawQuery + return ( + <> +
+ +
+ + + ) +} + +export default function Bibliography({ + bibliographyService, + location, + activeTab, + ...props +}: { + bibliographyService: BibliographyService + activeTab: 'references' | 'afo-register' +} & RouteComponentProps): JSX.Element { + const history = useHistory() return ( {(session: Session): JSX.Element => ( } + crumbs={[ + new TextCrumb('Bibliography'), + new TextCrumb( + { 'afo-register': 'AfO Register', references: 'References' }[ + activeTab + ] + ), + ]} + actions={ + activeTab === 'references' && + } > {session.isAllowedToReadBibliography() ? ( - <> -
- -
- - + { + if (eventKey !== activeTab) { + history.push(`${eventKey}`) + } + }} + id={_.uniqueId('Bibliography-')} + > + + + + +
AfO Register Here
+
+
) : (

Please log in to browse the Bibliography.

)} diff --git a/src/bibliography/ui/BibliographySearch.tsx b/src/bibliography/ui/BibliographySearch.tsx index 31ea8f42d..1b3778baf 100644 --- a/src/bibliography/ui/BibliographySearch.tsx +++ b/src/bibliography/ui/BibliographySearch.tsx @@ -2,12 +2,12 @@ import React from 'react' import { Link } from 'react-router-dom' import _ from 'lodash' import { Parser } from 'html-to-react' -import Promise from 'bluebird' import withData from 'http/withData' import './BibliographySearch.css' import BibliographyEntry from 'bibliography/domain/BibliographyEntry' +import BibliographyService from 'bibliography/application/BibliographyService' function BibliographySearch({ data }: { data: readonly BibliographyEntry[] }) { const parser = new Parser() @@ -16,7 +16,7 @@ function BibliographySearch({ data }: { data: readonly BibliographyEntry[] }) { {data.map((entry) => (
  • @@ -31,7 +31,7 @@ function BibliographySearch({ data }: { data: readonly BibliographyEntry[] }) { export default withData< unknown, { - bibliographyService: { search(query: string): Promise } + bibliographyService: BibliographyService query: string }, readonly BibliographyEntry[] diff --git a/src/fragmentarium/domain/FragmentDtos.ts b/src/fragmentarium/domain/FragmentDtos.ts index 684cf357f..975f89484 100644 --- a/src/fragmentarium/domain/FragmentDtos.ts +++ b/src/fragmentarium/domain/FragmentDtos.ts @@ -51,6 +51,8 @@ interface UncuratedReferenceDto { pages: readonly number[] } +type TraditionalReference = string + type RecordEntryDto = Pick type FolioDto = Pick @@ -85,6 +87,7 @@ export default interface FragmentDto { notes: Notes references: readonly ReferenceDto[] uncuratedReferences: readonly UncuratedReferenceDto[] | null + traditionalReferences: readonly TraditionalReference[] atf: string hasPhoto: boolean genres: readonly GenreDto[] diff --git a/src/fragmentarium/infrastructure/FragmentRepository.ts b/src/fragmentarium/infrastructure/FragmentRepository.ts index 891a7df9e..74cf02b0b 100644 --- a/src/fragmentarium/infrastructure/FragmentRepository.ts +++ b/src/fragmentarium/infrastructure/FragmentRepository.ts @@ -92,6 +92,7 @@ function createFragment(dto: FragmentDto): Fragment { text: createTransliteration(dto.text), references: dto.references.map(createReference), uncuratedReferences: dto.uncuratedReferences, + traditionalReferences: dto.traditionalReferences, genres: Genres.fromJson(dto.genres), script: createScript(dto.script), projects: dto.projects.map(createResearchProject), diff --git a/src/router/bibliographyRoutes.tsx b/src/router/bibliographyRoutes.tsx index 2c3b58ca1..3fd27757e 100644 --- a/src/router/bibliographyRoutes.tsx +++ b/src/router/bibliographyRoutes.tsx @@ -1,5 +1,5 @@ import React, { ReactNode } from 'react' -import { Route } from 'react-router-dom' +import { Redirect, Route } from 'react-router-dom' import Bibliography from 'bibliography/ui/Bibliography' import BibliographyEditor from 'bibliography/ui/BibliographyEditor' import BibliographyService from 'bibliography/application/BibliographyService' @@ -18,7 +18,7 @@ export default function BibliographyRoutes({ return [ ( , ( - + )} {...(sitemap && sitemapDefaults)} />, + ( + + + + )} + {...(sitemap && sitemapDefaults)} + />, + , ] } diff --git a/src/test-support/fragment-fixtures.ts b/src/test-support/fragment-fixtures.ts index f58fda8f4..22cd774fd 100644 --- a/src/test-support/fragment-fixtures.ts +++ b/src/test-support/fragment-fixtures.ts @@ -210,6 +210,7 @@ export const fragmentFactory = Factory.define( associations.references ?? referenceFactory.buildList(2, {}, { transient: { chance } }), associations.uncuratedReferences ?? null, + [], '', chance.bool(), associations.genres ?? diff --git a/src/test-support/test-fragment.ts b/src/test-support/test-fragment.ts index 9e84ffc7e..42a47041d 100644 --- a/src/test-support/test-fragment.ts +++ b/src/test-support/test-fragment.ts @@ -379,6 +379,7 @@ export const fragmentDto: FragmentDto = { }, ], uncuratedReferences: null, + traditionalReferences: [], atf: '10. sal/: š[im {gu}[...].GA\n10. ::/sal ši]m\n10. šim | šim\n10. ...+ku {KA.G[A} ... ....ku x', hasPhoto: true, @@ -481,6 +482,7 @@ export const fragment = new Fragment( ), ], null, + [], '10. sal/: š[im {gu}[...].GA\n10. ::/sal ši]m\n10. šim | šim\n10. ...+ku {KA.G[A} ... ....ku x', true, Genres.fromJson([ diff --git a/src/test-support/utils.ts b/src/test-support/utils.ts index 1a109cad9..759d91170 100644 --- a/src/test-support/utils.ts +++ b/src/test-support/utils.ts @@ -163,8 +163,6 @@ export function testDelegation( it('Returns', async () => { if (result instanceof Bluebird || result instanceof Promise) { const resolvedResult = await result - console.log('!!!', resolvedResult.afoNumber) - console.log('!11', expectedResult.afoNumber) await expect(resolvedResult).toEqual(expectedResult) } else { expect(result).toEqual(expectedResult)