Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jest): increase coverage for time utilities #4903

Merged
merged 3 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions utilities/Timezone.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import * as Timezone from './Timezone'

describe('init', () => {
test.skip('getTimezoneDropdowns', () => {
describe('Test utilities/timezone', () => {
test('getTimezoneDropdowns for Western Indonesia', () => {
const result = Timezone.getTimezoneDropdowns()
const nonDaylightTimezone = result.find((obj) => {
return obj.alternativeName === 'Singapore Time'
return obj.alternativeName === 'Western Indonesia Time'
})

expect(result.length).not.toBeNull()
expect(result.length).toBeGreaterThan(0)
expect(nonDaylightTimezone.currentTimeFormat).toEqual(
'+08:00 Singapore Time - Singapore, Woodlands, Geylang, Marine Parade',
) // Make sure that the nonDaylightTimezone exists.
expect(nonDaylightTimezone.abbreviation).toEqual('WIB') // Make sure that the nonDaylightTimezone exists.

expect(nonDaylightTimezone.continentCode).toEqual('AS')
expect(nonDaylightTimezone.continentName).toEqual('Asia')
expect(nonDaylightTimezone.countryCode).toEqual('ID')
expect(nonDaylightTimezone.countryName).toEqual('Indonesia')
})

test('getUtfOffsetInMins for an existing timezone', () => {
Expand Down
25 changes: 25 additions & 0 deletions utilities/duration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { formatDuration } from '~/utilities/duration'

Date.now = jest.fn(() => 1656069280)
// Date.setSeconds = jest.fn(() => 1656069280)
let localDate: number

describe('Test utilities/duration', () => {
beforeAll(() => {
localDate = Date.now()
})
test('call with latest date', () => {
// const argument = localDate.now() // Get unix timestamp

const result: any = formatDuration(localDate)
expect(result).toEqual('59:14:40')
})
test('call with 45 seconds date', () => {
const rawDate = new Date()
const argument = rawDate.setSeconds(45) // Returns unix timestamp

const result: any = formatDuration(argument)
expect(result).not.toEqual('59:14:40') // Because date is not what we defaulted above
expect(typeof result).toBe('string')
})
})