Skip to content

Commit

Permalink
fix format (apparently autoformat don't work on test file?)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangohjw committed Oct 19, 2024
1 parent afd71a8 commit 25767ea
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions packages/components/src/utils/__tests__/getParsedData.test.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
import { describe, expect, it } from "vitest"

import { getParsedDate } from '../getParsedDate'
import { getParsedDate } from "../getParsedDate"

describe('getParsedDate', () => {
it('parses dd/MM/yyyy format correctly', () => {
const result = getParsedDate('25/12/2023')
describe("getParsedDate", () => {
it("parses dd/MM/yyyy format correctly", () => {
const result = getParsedDate("25/12/2023")
expect(result).toStrictEqual(new Date(2023, 11, 25))
})

it('parses d MMM yyyy format correctly', () => {
const result = getParsedDate('5 Jan 2023')
it("parses d MMM yyyy format correctly", () => {
const result = getParsedDate("5 Jan 2023")
expect(result).toStrictEqual(new Date(2023, 0, 5))
})

it('parses d MMMM yyyy format correctly', () => {
const result = getParsedDate('15 March 2023')
it("parses d MMMM yyyy format correctly", () => {
const result = getParsedDate("15 March 2023")
expect(result).toStrictEqual(new Date(2023, 2, 15))
})

it('parses dd MMM yyyy format correctly', () => {
const result = getParsedDate('05 Apr 2023')
it("parses dd MMM yyyy format correctly", () => {
const result = getParsedDate("05 Apr 2023")
expect(result).toStrictEqual(new Date(2023, 3, 5))
})

it('parses dd MMMM yyyy format correctly', () => {
const result = getParsedDate('30 November 2023')
it("parses dd MMMM yyyy format correctly", () => {
const result = getParsedDate("30 November 2023")
expect(result).toStrictEqual(new Date(2023, 10, 30))
})

it('parses yyyy-MM-dd format correctly', () => {
const result = getParsedDate('2023-06-15')
it("parses yyyy-MM-dd format correctly", () => {
const result = getParsedDate("2023-06-15")
expect(result).toStrictEqual(new Date(2023, 5, 15))
})

it('parses ISO 8601 format correctly', () => {
it("parses ISO 8601 format correctly", () => {
const result = getParsedDate("2023-07-20T14:30:45.123Z")
expect(result).toStrictEqual(new Date(2023, 6, 20, 14, 30, 45, 123))
})

it('returns current date for unsupported format', () => {
const result = getParsedDate('unsupported format')
it("returns current date for unsupported format", () => {
const result = getParsedDate("unsupported format")
expect(result).toBeInstanceOf(Date)
expect(result.getTime()).toBeCloseTo(new Date().getTime(), -3) // Allow 1 second difference
})

it('returns current date for invalid date', () => {
const result = getParsedDate('32/13/2023') // Invalid date
it("returns current date for invalid date", () => {
const result = getParsedDate("32/13/2023") // Invalid date
expect(result).toBeInstanceOf(Date)
expect(result.getTime()).toBeCloseTo(new Date().getTime(), -3) // Allow 1 second difference
})
})
})

0 comments on commit 25767ea

Please sign in to comment.