Skip to content

test : added unit tests for date utility functions - #2079

Merged
riteshbonthalakoti merged 1 commit into
riteshbonthalakoti:gssocfrom
tmdeveloper007:#2057
Jun 7, 2026
Merged

test : added unit tests for date utility functions#2079
riteshbonthalakoti merged 1 commit into
riteshbonthalakoti:gssocfrom
tmdeveloper007:#2057

Conversation

@tmdeveloper007

@tmdeveloper007 tmdeveloper007 commented Jun 7, 2026

Copy link
Copy Markdown

Closes #2057.

Summary of What Has Been Done:
Added comprehensive unit tests for all three date utility functions in Frontend/src/utils/dateUtils.js: formatTimelineDate, getTimeZoneAbbr, and formatFullTimestamp.

Changes Made:

  • Created Frontend/src/utils/dateUtils.test.js with 17 test cases
  • Tests cover: null/undefined/empty inputs, ISO strings with/without timezone, invalid strings, numeric timestamps, epoch, far future dates
  • Tests getTimeZoneAbbr returns non-empty string and has fallback behavior
  • Tests formatFullTimestamp appends timezone abbreviation and handles invalid inputs

Impact it Made:

  • Guards against timezone shift bugs when date handling is modified
  • Documents actual behavior including edge cases discovered during testing
  • All 17 tests pass (verified with vitest run)

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for date utility functions, including validation of formatting, timezone handling, and edge cases such as null inputs, invalid dates, and timestamp edge scenarios.

@vercel

vercel Bot commented Jun 7, 2026

Copy link
Copy Markdown

@tmdeveloper007 is attempting to deploy a commit to the ritesh Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

New Vitest test suite for dateUtils.js covering three utilities: formatTimelineDate, getTimeZoneAbbr, and formatFullTimestamp. Tests validate null/undefined/empty input handling, ISO timestamp formatting with and without timezone, invalid data behavior, numeric millisecond parsing, edge dates, timezone abbreviation generation, and error fallbacks.

Changes

DateUtils Unit Tests

Layer / File(s) Summary
Test coverage for date utility functions
Frontend/src/utils/dateUtils.test.js
Vitest suite for formatTimelineDate asserts null/undefined/empty return null, ISO timestamps with/without Z format correctly, garbage input returns 'Invalid Date', numeric milliseconds parse correctly, and epoch/far-future dates format properly. getTimeZoneAbbr tests verify non-empty, minimum-length string with truthy fallback behavior. formatFullTimestamp tests verify formatted output with timezone abbreviation in parentheses for valid input, 'Processing...' for nullish/empty, and 'Invalid Date' with timezone for garbage input.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • ritesh-1918/HELPDESK.AI#677: Directly validates Safari normalization and fallback behavior in dateUtils functions introduced in that PR.
  • ritesh-1918/HELPDESK.AI#1902: Test expectations align with date utility behavior changes (formatTimelineDate, getTimeZoneAbbr, formatFullTimestamp) including Safari-safe parsing and 'Invalid Date' handling.
  • ritesh-1918/HELPDESK.AI#1741: Extends coverage for formatTimelineDate's timezone-less and invalid date input parsing behavior modified in that PR.

Suggested labels

type:testing, level:intermediate, quality:clean

Poem

🐰 A rabbit hops through dateUtils bold,
With tests for timestamps, new and old!
Null and undefined, they find their place,
While timezones format with utmost grace.
Now edge cases can't hide their face!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely summarizes the main change: adding unit tests for date utility functions, which aligns with the primary changeset objective.
Linked Issues check ✅ Passed The pull request successfully addresses all coding requirements from issue #2057: creates dateUtils.test.js with 17 test cases covering all required scenarios for formatTimelineDate, getTimeZoneAbbr, and formatFullTimestamp functions.
Out of Scope Changes check ✅ Passed All changes are directly within scope: only a new test file (dateUtils.test.js) was added to test three specific date utility functions as required by issue #2057, with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Frontend/src/utils/dateUtils.test.js`:
- Around line 73-78: The test for getTimeZoneAbbr doesn't exercise the catch
branch; modify the test to force Intl to throw and assert the function returns
the 'IST' fallback. Specifically, in the test for "returns IST as fallback on
Intl error" stub or mock the global Intl (or
Intl.DateTimeFormat.prototype.resolvedOptions) to throw an error when called,
call getTimeZoneAbbr(), expect exactly 'IST', and then restore the original Intl
implementation so other tests are unaffected; reference getTimeZoneAbbr and the
test block to locate where to apply the mock and restore.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 68b53806-12aa-483f-8d2c-5fd87984f7b5

📥 Commits

Reviewing files that changed from the base of the PR and between da8faf2 and f069e03.

📒 Files selected for processing (1)
  • Frontend/src/utils/dateUtils.test.js

Comment on lines +73 to +78
it('returns IST as fallback on Intl error', () => {
// The function has a try-catch that returns 'IST' on error
const result = getTimeZoneAbbr();
// Either a real abbreviation or 'IST' fallback
expect(result).toBeTruthy();
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fallback-path test does not validate the actual 'IST' error branch

Line 73’s test never induces an Intl failure, so it only re-checks truthiness and can’t catch regressions in the catch/fallback path.

Suggested fix
 it('returns IST as fallback on Intl error', () => {
-    // The function has a try-catch that returns 'IST' on error
-    const result = getTimeZoneAbbr();
-    // Either a real abbreviation or 'IST' fallback
-    expect(result).toBeTruthy();
+    const original = Intl.DateTimeFormat;
+    vi.spyOn(Intl, 'DateTimeFormat').mockImplementation(() => {
+        throw new Error('Intl failure');
+    });
+    expect(getTimeZoneAbbr()).toBe('IST');
+    Intl.DateTimeFormat = original;
 });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('returns IST as fallback on Intl error', () => {
// The function has a try-catch that returns 'IST' on error
const result = getTimeZoneAbbr();
// Either a real abbreviation or 'IST' fallback
expect(result).toBeTruthy();
});
it('returns IST as fallback on Intl error', () => {
const original = Intl.DateTimeFormat;
vi.spyOn(Intl, 'DateTimeFormat').mockImplementation(() => {
throw new Error('Intl failure');
});
expect(getTimeZoneAbbr()).toBe('IST');
Intl.DateTimeFormat = original;
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Frontend/src/utils/dateUtils.test.js` around lines 73 - 78, The test for
getTimeZoneAbbr doesn't exercise the catch branch; modify the test to force Intl
to throw and assert the function returns the 'IST' fallback. Specifically, in
the test for "returns IST as fallback on Intl error" stub or mock the global
Intl (or Intl.DateTimeFormat.prototype.resolvedOptions) to throw an error when
called, call getTimeZoneAbbr(), expect exactly 'IST', and then restore the
original Intl implementation so other tests are unaffected; reference
getTimeZoneAbbr and the test block to locate where to apply the mock and
restore.

@riteshbonthalakoti
riteshbonthalakoti changed the base branch from main to gssoc June 7, 2026 16:02
@riteshbonthalakoti riteshbonthalakoti added gssoc GirlScript Summer of Code gssoc:approved GSSoC Approved PR level:beginner Beginner level difficulty quality:clean Clean code quality type:testing Testing suites, mock coverages, CI/CD integrations labels Jun 7, 2026
@riteshbonthalakoti

Copy link
Copy Markdown
Owner

Superb implementation, @tmdeveloper007! I've successfully resolved all conflicts in your PR and queued it for merging into gssoc.

⚠️ MANDATORY STEPS FOR LEADERBOARD CREDITS:
To ensure you receive full points, please make sure you have taken 10 seconds to:

Keep up the outstanding work! Let's build together! 🔥

@riteshbonthalakoti
riteshbonthalakoti merged commit c3cdf68 into riteshbonthalakoti:gssoc Jun 7, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC Approved PR gssoc GirlScript Summer of Code level:beginner Beginner level difficulty quality:clean Clean code quality type:testing Testing suites, mock coverages, CI/CD integrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test : add unit tests for date utility functions

2 participants