Skip to content

Commit

Permalink
Added provenance search tab for fragmentarium
Browse files Browse the repository at this point in the history
Added tests for proveance search tab ui
  • Loading branch information
Vas9ka committed Feb 19, 2024
1 parent 9477e45 commit c42440f
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/fragmentarium/application/FragmentService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const fragmentRepository = {
updateNotes: jest.fn(),
updateLemmatization: jest.fn(),
fetchGenres: jest.fn(),
fetchArchaeologies: jest.fn(),
updateGenres: jest.fn(),
updateScript: jest.fn(),
updateDate: jest.fn(),
Expand Down
4 changes: 4 additions & 0 deletions src/fragmentarium/application/FragmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface FragmentRepository {
): Bluebird<Fragment>
findInCorpus(number: string): Bluebird<ReadonlyArray<ManuscriptAttestation>>
fetchGenres(): Bluebird<string[][]>
fetchArchaeologies(): Bluebird<string[][]>
fetchPeriods(): Bluebird<string[]>
updateGenres(number: string, genres: Genres): Bluebird<Fragment>
updateScript(number: string, script: Script): Bluebird<Fragment>
Expand Down Expand Up @@ -176,6 +177,9 @@ export class FragmentService {
fetchGenres(): Bluebird<string[][]> {
return this.fragmentRepository.fetchGenres()
}
fetchArchaeologies(): Bluebird<string[][]> {
return this.fragmentRepository.fetchArchaeologies()
}

fetchPeriods(): Bluebird<string[]> {
return this.fragmentRepository.fetchPeriods()
Expand Down
3 changes: 3 additions & 0 deletions src/fragmentarium/infrastructure/FragmentRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ class ApiFragmentRepository
fetchGenres(): Promise<string[][]> {
return this.apiClient.fetchJson('/genres', false)
}
fetchArchaeologies(): Promise<string[][]> {
return this.apiClient.fetchJson('/provenances', false)
}

fetchPeriods(): Promise<string[]> {
return this.apiClient.fetchJson('/periods', false)
Expand Down
3 changes: 3 additions & 0 deletions src/fragmentarium/ui/ArchaeologySearchForm.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.archaeology-selector
&__menu
z-index: 99 !important
38 changes: 38 additions & 0 deletions src/fragmentarium/ui/ArchaeologySearchForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react'
import withData from 'http/withData'
import Select from 'react-select'
import FragmentService from 'fragmentarium/application/FragmentService'
import './ArchaeologySearchForm.sass'

export default withData<
{
onChange: (value: string | null) => void
value?: string | null
},
{ fragmentService: FragmentService },
ReadonlyArray<ReadonlyArray<string>>
>(
({ data, value, onChange }) => {
const options = data.map((archaeology) => ({
value: archaeology[0],
label: archaeology[0],
}))
const defaultOption = value ? { value: value, label: value } : null

return (
<Select
aria-label="select-archaeology"
placeholder="Provenance"
options={options}
value={defaultOption}
onChange={(selection) => {
onChange(selection?.value || null)
}}
isSearchable={true}
classNamePrefix={'archaeology-selector'}
isClearable
/>
)
},
(props) => props.fragmentService.fetchArchaeologies()
)
36 changes: 36 additions & 0 deletions src/fragmentarium/ui/SearchForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ const genres = [
['MONUMENTAL'],
]

const provenances = [
['Standard Text'],
['Assyria'],
['Aššur'],
['Dūr-Katlimmu'],
]

let query: FragmentQuery

let history: MemoryHistory
Expand Down Expand Up @@ -82,6 +89,9 @@ beforeEach(async () => {
Promise.resolve(Object.keys(Periods))
)
fragmentService.fetchGenres.mockReturnValue(Promise.resolve(genres))
fragmentService.fetchArchaeologies.mockReturnValue(
Promise.resolve(provenances)
)
wordService.searchLemma.mockReturnValue(Promise.resolve([word]))
wordService.findAll.mockReturnValue(Promise.resolve([]))
session.isAllowedToReadFragments.mockReturnValue(true)
Expand Down Expand Up @@ -213,6 +223,32 @@ describe('Script period selection form', () => {
})
})

describe('Provenance selection form', () => {
beforeEach(() => {
userEvent.type(screen.getByLabelText('select-archaeology'), 'Assur')
})
it('displays user input', async () => {
await waitFor(() =>
expect(screen.getByLabelText('select-archaeology')).toHaveValue('Assur')
)
})

it('shows options', async () => {
await waitFor(() => {
expect(screen.getByText('Aššur')).toBeVisible()
})
})

it('selects option when clicked', async () => {
userEvent.click(screen.getByText('Aššur'))
userEvent.click(screen.getByText('Search'))
await waitFor(() =>
expect(history.push).toHaveBeenCalledWith(
`/fragmentarium/search/?site=${encodeURIComponent('Aššur')}`
)
)
})
})
describe('Genre selection form', () => {
beforeEach(() => {
userEvent.type(screen.getByLabelText('select-genre'), 'arch')
Expand Down
21 changes: 21 additions & 0 deletions src/fragmentarium/ui/SearchForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import {
LemmaSearchHelp,
ScriptSearchHelp,
GenreSearchHelp,
ProvenanceSearchHelp,
} from './SearchHelp'
import GenreSearchForm from './GenreSearchForm'
import BibliographyService from 'bibliography/application/BibliographyService'
import { ResearchProjects } from 'research-projects/researchProject'
import ArchaeologySearchForm from './ArchaeologySearchForm'

interface State {
number: string | null
Expand All @@ -47,6 +49,7 @@ interface State {
scriptPeriodModifier: PeriodModifierString
genre: string | null
isValid: boolean
site: string | null
}

type Props = {
Expand Down Expand Up @@ -82,6 +85,7 @@ class SearchForm extends Component<Props, State> {
scriptPeriod: fragmentQuery.scriptPeriod || '',
scriptPeriodModifier: fragmentQuery.scriptPeriodModifier || '',
genre: fragmentQuery.genre || '',
site: fragmentQuery.archaeology || '',
isValid: isValidNumber(fragmentQuery.number),
}

Expand Down Expand Up @@ -137,6 +141,7 @@ class SearchForm extends Component<Props, State> {
: '',
scriptPeriod: state.scriptPeriod,
genre: state.genre,
site: state.site,
project: this.props.project,
},
(value) => !value
Expand Down Expand Up @@ -230,6 +235,22 @@ class SearchForm extends Component<Props, State> {
/>
</Col>
</Form.Group>
<Form.Group as={Row} controlId="site">
<Col
sm={2}
as={Form.Label}
className="TransliterationSearchForm__label"
>
<HelpTrigger overlay={ProvenanceSearchHelp()} />
</Col>
<Col>
<ArchaeologySearchForm
fragmentService={this.props.fragmentService}
onChange={this.onChange('site')}
value={this.state.site}
/>
</Col>
</Form.Group>
<Form.Group as={Row} controlId="genre">
<Col
sm={2}
Expand Down
10 changes: 10 additions & 0 deletions src/fragmentarium/ui/SearchHelp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,13 @@ export function GenreSearchHelp(): JSX.Element {
</Popover>
)
}

export function ProvenanceSearchHelp(): JSX.Element {
return (
<Popover id={_.uniqueId('ScriptSearchHelp-')} title="Search Period">
<Popover.Content>
Filter by provenance (only takes effect on fragment search)
</Popover.Content>
</Popover>
)
}
1 change: 1 addition & 0 deletions src/fragmentarium/ui/front-page/Fragmentarium.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ beforeEach(() => {
wordService.findAll.mockReturnValue(Promise.resolve([]))
fragmentService.fetchPeriods.mockReturnValueOnce(Promise.resolve([]))
fragmentService.fetchGenres.mockReturnValueOnce(Promise.resolve([]))
fragmentService.fetchArchaeologies.mockRejectedValueOnce(Promise.resolve([]))
})

describe('Statistics', () => {
Expand Down
1 change: 1 addition & 0 deletions src/fragmentarium/ui/search/FragmentariumSearch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ beforeEach(async () => {
session = new MemorySession(['read:fragments'])
fragmentService.fetchPeriods.mockReturnValueOnce(Promise.resolve([]))
fragmentService.fetchGenres.mockReturnValueOnce(Promise.resolve([]))
fragmentService.fetchArchaeologies.mockReturnValueOnce(Promise.resolve([]))
})

describe('Search', () => {
Expand Down
Loading

0 comments on commit c42440f

Please sign in to comment.