-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/chronology/application/DateConverterFormChange.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
}) |