Skip to content

Add missing test coverage for compareThought.ts#3976

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-missing-test-coverage
Draft

Add missing test coverage for compareThought.ts#3976
Copilot wants to merge 2 commits intomainfrom
copilot/add-missing-test-coverage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 19, 2026

src/util/__tests__/compareThought.ts had zero direct tests for 9 exported functions and significant gaps in edge case coverage for partially-tested functions.

New coverage

Entirely untested exports:

  • compareThought (ascending) — basic, meta-attributes, emojis, empty string
  • compareReasonableDescending — formatting floats first, empty near top, plain text before punctuation, Z→A, dates/numbers descending
  • compareStringsWithMetaAttributes — meta vs non-meta, both meta, neither meta
  • compareThoughtByCreated / compareThoughtByCreatedDescending — timestamp ordering + compareReasonable tiebreak fallback
  • compareThoughtByUpdated / compareThoughtByUpdatedDescending — same pattern
  • compareThoughtByNoteAndRank / compareThoughtByNoteDescendingAndRank — notes-before-no-notes, note value ordering, rank tiebreaker; uses reducerFlow + importText for real state setup

Gap-filling for partially tested functions:

  • compareReasonable: empty string priority, punctuation/formatting/meta/emoji hierarchy, dates and numbers above plain text, full end-to-end priority interplay
  • compareThoughtDescending: empty string behavior, formatted text to top, date/number descending order
  • compareDateStrings: dash-format with year (6-21-2025), year-based numeric ordering, cross-format cross-year comparison
  • compareNumbers: / currencies, decimal numbers
  • compareFormatting: tags with HTML attributes, mismatched tag behavior (documents that the regex does not enforce matching open/close tag names)
  • comparePunctuationAndOther: !, #, $, (, . characters
  • makeOrderedComparator: empty array base case ([] → always 0)

Test count: 21 → 65.

Original prompt

Add Missing Test Coverage for src/util/compareThought.ts

The file src/util/__tests__/compareThought.ts is missing significant test coverage for the exported functions in src/util/compareThought.ts. Please add tests to fill in the gaps identified below.


🔴 Entirely Untested Exports

These are exported from compareThought.ts but never imported or tested:

  • compareThought (ascending) — compares two Thought objects by value ascending. Only compareThoughtDescending is currently tested.
  • compareThoughtByCreated — sort by created timestamp ascending, with compareReasonable fallback for ties.
  • compareThoughtByCreatedDescending — sort by created timestamp descending, with compareReasonable fallback for ties.
  • compareThoughtByUpdated — sort by lastUpdated ascending, with compareReasonable fallback for ties.
  • compareThoughtByUpdatedDescending — sort by lastUpdated descending, with compareReasonable fallback for ties.
  • compareThoughtByNoteAndRank — sort by note value ascending, falling back to rank when notes are absent or equal.
  • compareThoughtByNoteDescendingAndRank — sort by note value descending, falling back to rank when notes are absent or equal.
  • compareStringsWithMetaAttributes — meta-attribute sort (only tested indirectly via compareThoughtDescending).
  • compareReasonableDescending — only tested indirectly via compareThoughtDescending; no direct unit tests.

🟡 Partially Tested / Missing Cases

compareReasonable

  • Missing: empty string priority'' should sort first
  • Missing: punctuation prioritycomparePunctuationAndOther has standalone tests, but compareReasonable never tests that punctuation-starting strings (=, #, !, etc.) sort above plain text
  • Missing: formatted text priority — no test in the compareReasonable suite for HTML-formatted strings sorting above plain text
  • Missing: meta-attribute priority — no test in the compareReasonable ascending suite
  • Missing: dates sort above plain text — e.g. "3/3" should sort before "apple"
  • Missing: numbers sort above plain text — e.g. "5" should sort before "apple"
  • Missing: full priority interplay — end-to-end test that the full ordering (empty < punctuation < formatting < meta-attribute < emoji < date < number < text) is respected

compareThoughtDescending

  • Missing: empty string behavior
  • Missing: formatted text floats to top — this is a key behavioral difference vs. ascending
  • Missing: date/number descending order

compareDateStrings

  • Missing: dash-format dates with year — e.g. "6-21-2025" (only slash format used in compareDateStrings tests)
  • Missing: year-based ordering in numeric format — e.g. "3/3/2020" vs "3/3/2021"
  • Missing: cross-format, cross-year comparison — e.g. "3/3/2020" vs "March 3, 2021"

compareNumbers

  • Missing: and currency symbols — present in the source regex but untested
  • Missing: decimal numbers — e.g. "1.5" vs "2.3" (isNumber uses !isNaN which accepts decimals)

compareFormatting

  • Missing: formatting tags with HTML attributes — e.g. <span class="x">text</span> (the regex uses [^>]* to allow attributes)
  • Missing: mismatched open/close tags — e.g. <b>text</i> should NOT be detected as valid formatting

comparePunctuationAndOther

  • Missing: other punctuation characters — only = is tested; !, #, $, (, . etc. are in the regex but never tested

makeOrderedComparator

  • Missing: empty comparator array — the base case ([] → always returns 0) is not tested

Implementation Notes

  • Use the existing thought() helper at the top of the test file to construct Thought objects for thought-level comparator tests.
  • For compareThoughtByNoteAndRank and compareThoughtByNoteDescendingAndRank, these require a State object and look up note values via noteValue(state, thoughtToPath(state, id)). Use the existing test infrastructure in the repo (look at other test files that use createTestApp or similar state helpers) to construct state with notes if needed, or mock/stub at a simpler level if state setup is complex.
  • For timestamp-based comparators (ByCreated, ByUpdated), construct Thought objects with different created/lastUpdated values. The timestamp() utility returns an ISO string — you can pass explicit strings like '2020-01-01T00:00:00.000Z' directly.
  • Import all newly tested functions from '../compareThought'.
  • Do not remove or modify any existing tests.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Summarize all the sort rules for the QA person in plain English.

Assistant: Here's a plain-English summary of all the sort rules, organized by sort mode:


How Thoughts Are Sorted

🔤 Text Normalization (applied before any...

This pull request was created from Copilot chat.


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Co-authored-by: raineorshine <750276+raineorshine@users.noreply.github.com>
Copilot AI changed the title [WIP] Add missing test coverage for compareThought.ts Add missing test coverage for compareThought.ts Mar 19, 2026
Copilot AI requested a review from raineorshine March 19, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants