Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
khoidt committed Jan 16, 2024
1 parent 863c0cb commit 01df76d
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/afo-register/ui/AfoRegisterSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function AfoRegisterIntroduction(): JSX.Element {
<Markdown
className="AfoRegister__introduction"
text="The [AfO-Register](https://orientalistik.univie.ac.at/publikationen/afo/register/) (Archiv für Orientforschung: Register Assyriologie),
curated by the Department of Near Eastern Studies of the University of Vienna, is an essential bibliographic bibliographic tool for Ancient Near.
curated by the Department of Near Eastern Studies of the University of Vienna, is an essential bibliographic tool for Ancient Near
Eastern Studies. Starting with Volume 25 (1974–1977), it has published comprehensive bibliographies of new Assyriological literature and an
index in most volumes, categorized by subject areas, Akkadian and Sumerian words, and texts and passages. With the kind permission of the AfO
Redaktion, the Register has been digitized and made searchable by the eBL team, thus enhancing its accessibility for researchers,
Expand Down
112 changes: 112 additions & 0 deletions src/chronology/application/DateConverterFormChange.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { ChangeEvent } from 'react'
import { handleDateConverterFormChange } from './DateConverterFormChange'
import DateConverter from 'chronology/domain/DateConverter'

const createMockEvent = (
name: string,
value: string
): ChangeEvent<HTMLInputElement> => ({
target: ({
name,
value,
} as unknown) as HTMLInputElement,
nativeEvent: new Event('change'),
currentTarget: document.createElement('input'),
bubbles: true,
cancelable: true,
defaultPrevented: false,
eventPhase: Event.NONE,
isTrusted: false,
preventDefault: jest.fn(),
isDefaultPrevented: jest.fn(),
stopPropagation: jest.fn(),
isPropagationStopped: jest.fn(),
persist: jest.fn(),
timeStamp: Date.now(),
type: 'change',
})

const setScenario = jest.fn()
const dateConverter = new DateConverter()
let mockFormData, mockDateConverter, mockSetFormData

beforeEach(() => {
mockDateConverter = {
setToGregorianDate: jest.fn(),
setToJulianDate: jest.fn(),
setToSeBabylonianDate: jest.fn(),
setToMesopotamianDate: jest.fn(),
}
mockFormData = dateConverter.calendar
mockSetFormData = jest.fn()
})

it('handles setToGregorianDate scenario correctly', () => {
const mockEvent = createMockEvent('month', '12')
handleDateConverterFormChange({
event: mockEvent,
scenario: 'setToGregorianDate',
formData: mockFormData,
dateConverter: mockDateConverter,
setFormData: mockSetFormData,
setScenario,
})
expect(mockDateConverter.setToGregorianDate).toBeCalledWith(-309, 3, 29)
})

it('handles setToJulianDate scenario correctly', () => {
const mockEvent = createMockEvent('month', '12')
handleDateConverterFormChange({
event: mockEvent,
scenario: 'setToJulianDate',
formData: mockFormData,
dateConverter: mockDateConverter,
setFormData: mockSetFormData,
setScenario,
})
expect(mockDateConverter.setToJulianDate).toBeCalledWith(-310, 4, 3)
})

it('handles setToJulianDate scenario correctly', () => {
const mockEvent = createMockEvent('month', '12')
handleDateConverterFormChange({
event: mockEvent,
scenario: 'setToJulianDate',
formData: mockFormData,
dateConverter: mockDateConverter,
setFormData: mockSetFormData,
setScenario,
})
expect(mockDateConverter.setToJulianDate).toBeCalledWith(-310, 4, 3)
})

it('handles setToSeBabylonianDate scenario correctly', () => {
const mockEvent = createMockEvent('month', '12')
handleDateConverterFormChange({
event: mockEvent,
scenario: 'setToSeBabylonianDate',
formData: mockFormData,
dateConverter: mockDateConverter,
setFormData: mockSetFormData,
setScenario,
})
expect(mockDateConverter.setToSeBabylonianDate).toBeCalledWith(1, 1, 1)
})

it('handles setToMesopotamianDate scenario correctly', () => {
const mockEvent = createMockEvent('month', '12')
handleDateConverterFormChange({
event: mockEvent,
scenario: 'setToMesopotamianDate',
formData: mockFormData,
dateConverter: mockDateConverter,
setFormData: mockSetFormData,
setScenario,
})
expect(mockDateConverter.setToMesopotamianDate).toBeCalledWith(
'Seleucus I Nicator',
1,
1,
1
)
})

0 comments on commit 01df76d

Please sign in to comment.