-
Notifications
You must be signed in to change notification settings - Fork 0
fix(frontend): keep missing sort values last #8
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
Merged
Leonard-Don
merged 1 commit into
main
from
agent/yieldwise-ui-fake-zero-20260514-173506
May 14, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { test } from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
|
|
||
| import { sortItems } from "../../frontend/user/modules/opportunity-board.js"; | ||
|
|
||
| test("sortItems: descending sort orders numeric values from high to low", () => { | ||
| const items = [ | ||
| { id: "a", yield: 3 }, | ||
| { id: "b", yield: 7 }, | ||
| { id: "c", yield: 5 }, | ||
| ]; | ||
| const sorted = sortItems(items, { key: "yield", direction: "desc" }); | ||
| assert.deepEqual(sorted.map((i) => i.id), ["b", "c", "a"]); | ||
| }); | ||
|
|
||
| test("sortItems: explicit 0 is a real value, not a missing marker", () => { | ||
| // The board sorts by yield/score; rows with an explicit zero should keep | ||
| // their numeric position relative to other numbers — not be lumped in with | ||
| // null/undefined as "no data". | ||
| const items = [ | ||
| { id: "neg", yield: -1 }, | ||
| { id: "zero", yield: 0 }, | ||
| { id: "pos", yield: 4 }, | ||
| { id: "missing", yield: null }, | ||
| ]; | ||
| const desc = sortItems(items, { key: "yield", direction: "desc" }); | ||
| assert.deepEqual( | ||
| desc.map((i) => i.id), | ||
| ["pos", "zero", "neg", "missing"], | ||
| "desc: 0 sits between positive and negative; null goes to the end", | ||
| ); | ||
| const asc = sortItems(items, { key: "yield", direction: "asc" }); | ||
| assert.deepEqual( | ||
| asc.map((i) => i.id), | ||
| ["neg", "zero", "pos", "missing"], | ||
| "asc: 0 sits between negative and positive; null still goes to the end", | ||
| ); | ||
| }); | ||
|
|
||
| test("sortItems: null and undefined values sort to the end regardless of direction", () => { | ||
| const items = [ | ||
| { id: "n", yield: null }, | ||
| { id: "u", yield: undefined }, | ||
| { id: "a", yield: 4 }, | ||
| { id: "b", yield: 1 }, | ||
| ]; | ||
| const desc = sortItems(items, { key: "yield", direction: "desc" }); | ||
| assert.deepEqual(desc.slice(0, 2).map((i) => i.id), ["a", "b"]); | ||
| assert.ok(["n", "u"].includes(desc[2].id) && ["n", "u"].includes(desc[3].id)); | ||
|
|
||
| const asc = sortItems(items, { key: "yield", direction: "asc" }); | ||
| assert.deepEqual(asc.slice(0, 2).map((i) => i.id), ["b", "a"]); | ||
| assert.ok(["n", "u"].includes(asc[2].id) && ["n", "u"].includes(asc[3].id)); | ||
| }); | ||
|
|
||
| test("sortItems: NaN values sort to the end like null (no silent reordering)", () => { | ||
| // NaN sneaks through Number() when upstream data is malformed; the board | ||
| // should treat it as 'no data' and push it to the end, not float it to the | ||
| // top because of how IEEE-754 NaN comparisons return false. | ||
| const items = [ | ||
| { id: "nan", yield: Number.NaN }, | ||
| { id: "low", yield: 1 }, | ||
| { id: "high", yield: 9 }, | ||
| ]; | ||
| const desc = sortItems(items, { key: "yield", direction: "desc" }); | ||
| assert.deepEqual( | ||
| desc.map((i) => i.id), | ||
| ["high", "low", "nan"], | ||
| "desc: NaN must go to the end, not the top", | ||
| ); | ||
| const asc = sortItems(items, { key: "yield", direction: "asc" }); | ||
| assert.deepEqual( | ||
| asc.map((i) => i.id), | ||
| ["low", "high", "nan"], | ||
| "asc: NaN must go to the end, not the top", | ||
| ); | ||
| }); | ||
|
|
||
| test("sortItems: mixed null/NaN/numbers — all missing markers cluster at the end", () => { | ||
| const items = [ | ||
| { id: "a", score: 50 }, | ||
| { id: "nan", score: Number.NaN }, | ||
| { id: "null", score: null }, | ||
| { id: "b", score: 10 }, | ||
| { id: "undef", score: undefined }, | ||
| { id: "zero", score: 0 }, | ||
| ]; | ||
| const sorted = sortItems(items, { key: "score", direction: "desc" }); | ||
| // First three are the numeric values, in desc order; last three are the | ||
| // missing markers (any order is fine). | ||
| assert.deepEqual(sorted.slice(0, 3).map((i) => i.id), ["a", "b", "zero"]); | ||
| const tail = sorted.slice(3).map((i) => i.id).sort(); | ||
| assert.deepEqual(tail, ["nan", "null", "undef"]); | ||
| }); | ||
|
|
||
| test("sortItems: returns the original list when no sortSpec is supplied", () => { | ||
| const items = [{ id: "a" }, { id: "b" }]; | ||
| assert.equal(sortItems(items, null), items); | ||
| assert.equal(sortItems(items, undefined), items); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When both rows have missing values, the comparator should return
0, but this code returns1as soon asavis missing. That becomes a real regression forNaN:NaN === NaNis false, so comparing twoNaNrows now yields1in both directions, which violates comparator anti-symmetry and makesArray.prototype.sortbehavior implementation-dependent (potentially unstable ordering across runtimes). Add aif (isMissingSortValue(av) && isMissingSortValue(bv)) return 0;check before the single-sided missing checks.Useful? React with 👍 / 👎.