-
Notifications
You must be signed in to change notification settings - Fork 3
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
9 changed files
with
633 additions
and
13 deletions.
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
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,78 @@ | ||
import { useConfig } from '@dhis2/app-runtime' | ||
import { render as testingLibraryRender } from '@testing-library/react' | ||
import React from 'react' | ||
import { useLockedContext } from '../shared/locked-status/use-locked-context.js' | ||
import { render } from '../test-utils/render.js' | ||
import FormExpiryInfo from './form-expiry-info.js' | ||
|
||
jest.mock('@dhis2/app-runtime', () => ({ | ||
...jest.requireActual('@dhis2/app-runtime'), | ||
useConfig: jest.fn(() => ({ | ||
systemInfo: { serverTimeZoneId: 'Etc/UTC', calendar: 'gregory' }, | ||
})), | ||
})) | ||
|
||
jest.mock('../shared/locked-status/use-locked-context.js', () => ({ | ||
...jest.requireActual('../shared/locked-status/use-locked-context.js'), | ||
useLockedContext: jest.fn(() => ({ | ||
locked: false, | ||
lockStatus: { lockDate: '2024-03-15T14:15:00' }, | ||
})), | ||
})) | ||
|
||
describe('FormExpiryInfo', () => { | ||
beforeEach(() => { | ||
jest.useFakeTimers('modern') | ||
jest.setSystemTime(new Date('2024-03-15T12:15:00')) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.useRealTimers() | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('shows nothing if locked', () => { | ||
useLockedContext.mockImplementationOnce(() => ({ | ||
locked: true, | ||
lockStatus: { lockDate: '2024-03-15T14:15:00' }, | ||
})) | ||
// render without the wrapper as we just want to test this element is empty and wrapper introduces some extra divs | ||
const { container } = testingLibraryRender(<FormExpiryInfo />) | ||
|
||
expect(container).toBeEmptyDOMElement() | ||
}) | ||
|
||
it('shows relative time for lockedDate, if not locked, there is a lockDate, and calendar:gregory', () => { | ||
const { getByText } = render(<FormExpiryInfo />) | ||
|
||
expect(getByText('Closes in 2 hours')).toBeInTheDocument() | ||
}) | ||
|
||
it('shows absolute time for lockedDate, if not locked, there is a lockDate, and calendar not gregory', () => { | ||
useConfig.mockImplementation(() => ({ | ||
systemInfo: { | ||
serverTimeZoneId: 'Africa/Addis_Ababa', | ||
calendar: 'ethiopian', | ||
}, | ||
})) | ||
const { getByText } = render(<FormExpiryInfo />) | ||
|
||
expect( | ||
getByText('Closes 2024-03-15T14:15:00 (Africa/Addis_Ababa)') | ||
).toBeInTheDocument() | ||
}) | ||
|
||
it('corrects relative time for time zone differences', () => { | ||
useConfig.mockImplementation(() => ({ | ||
systemInfo: { | ||
serverTimeZoneId: 'America/Port-au-Prince', | ||
calendar: 'gregory', | ||
}, | ||
})) | ||
const { getByText } = render(<FormExpiryInfo />) | ||
|
||
// current browser time: 2024-03-15T12:15:00 UTC | ||
// which is 2024-03-15T08:15:00 Port-au-Prince (GMT-4 due to DST) | ||
expect(getByText('Closes in 6 hours')).toBeInTheDocument() | ||
}) | ||
}) |
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
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
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
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
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
Oops, something went wrong.