Skip to content

Commit

Permalink
feat(jest): increase coverage for time utilities (#4903)
Browse files Browse the repository at this point in the history
  • Loading branch information
drepram committed Sep 20, 2022
1 parent 7e553da commit 1d89e61
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
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')
})
})

0 comments on commit 1d89e61

Please sign in to comment.