-
Notifications
You must be signed in to change notification settings - Fork 0
PR8 — optional client group labels, no grand total #145
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
Open
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
17a9346
feat(clients): group all-client rows by optional label
lamemustafa f6744d0
fix(clients): fail closed on amounts and identity
lamemustafa b9a350e
chore(tally): reseal compatibility surface for F1X
lamemustafa 5587007
fix(clients): refuse destructive label rewrites
lamemustafa c31fe8d
chore(tally): reseal F4X PR8 compatibility surface
lamemustafa 1e5b8ab
fix(ui): roll back failed group label saves
lamemustafa e53f60b
chore(tally): reseal F5X PR8 compatibility surface
lamemustafa 24754c1
chore(tally): reseal F5X PR8 after clippy repair
lamemustafa 1daef38
chore(tally): reseal F5X PR8 after PR6 clippy repair
lamemustafa 808e057
chore(tally): reseal F5X PR8 after PR7 compile repair
lamemustafa f7f6fda
chore(tally): reseal RB1 PR8 compatibility surface
lamemustafa 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
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,92 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import assert from "node:assert/strict"; | ||
| import { readFile } from "node:fs/promises"; | ||
| import test from "node:test"; | ||
|
|
||
| import { applyClientGroupLabel, groupClientRows, rollbackFailedClientGroupLabel, sumExactDecimals } from "../src/client-grouping.ts"; | ||
|
|
||
| test("a failed optimistic label save restores only the value that actually failed", () => { | ||
| const persisted = { "synthetic-company-guid": "Original" }; | ||
| const optimistic = applyClientGroupLabel(persisted, "synthetic-company-guid", "North"); | ||
| assert.deepEqual( | ||
| rollbackFailedClientGroupLabel(optimistic, "synthetic-company-guid", "North", persisted), | ||
| persisted, | ||
| ); | ||
|
|
||
| const newerEdit = applyClientGroupLabel(optimistic, "synthetic-company-guid", "Newer edit"); | ||
| assert.deepEqual( | ||
| rollbackFailedClientGroupLabel(newerEdit, "synthetic-company-guid", "North", persisted), | ||
| newerEdit, | ||
| "a late failure must not erase typing that happened after the failed attempt", | ||
| ); | ||
| assert.deepEqual( | ||
| rollbackFailedClientGroupLabel({ "synthetic-company-guid": "North" }, "synthetic-company-guid", "North", {}), | ||
| {}, | ||
| "a failed first save returns the company to ungrouped", | ||
| ); | ||
| }); | ||
|
|
||
| test("applying a group label preserves every company figure byte-for-byte", () => { | ||
| const row = { | ||
| companyGuid: "synthetic-company-guid", | ||
| company: "Synthetic Components Ltd", | ||
| exactAmounts: { receivable: "482001.25", overdue: "120400.5", unallocated: "7580.75" }, | ||
| oldest: 97, | ||
| complete: true, | ||
| }; | ||
| const before = Buffer.from(JSON.stringify(row)); | ||
|
|
||
| const grouped = groupClientRows([row], { "synthetic-company-guid": "North practice" }); | ||
| const groupedRow = grouped.groups[0].rows[0]; | ||
|
|
||
| assert.deepEqual(Buffer.from(JSON.stringify(groupedRow)), before); | ||
| assert.deepEqual(grouped.groups[0].totals, { | ||
| receivable: "482001.25", | ||
| overdue: "120400.5", | ||
| unallocated: "7580.75", | ||
| }); | ||
| assert.equal(grouped.ungroupedRows.length, 0); | ||
| }); | ||
|
|
||
| test("ungrouped companies remain separate and receive no synthetic total", () => { | ||
| const rows = [ | ||
| { companyGuid: "synthetic-a", exactAmounts: { receivable: "10", overdue: "2", unallocated: "1" } }, | ||
| { companyGuid: "synthetic-b", exactAmounts: { receivable: "20", overdue: "3", unallocated: "4" } }, | ||
| ]; | ||
|
|
||
| const grouped = groupClientRows(rows, {}); | ||
|
|
||
| assert.deepEqual(grouped.groups, []); | ||
| assert.equal(grouped.ungroupedRows.length, 2); | ||
| }); | ||
|
|
||
| test("group totals preserve decimal precision without IEEE-754 rounding", () => { | ||
| assert.equal(sumExactDecimals(["9007199254740993", "0.01", "-1"]), "9007199254740992.01"); | ||
| assert.equal(sumExactDecimals(["42.00", "0.10"]), "42.1"); | ||
| assert.equal(sumExactDecimals(["10", "not-an-amount"]), undefined); | ||
| }); | ||
|
|
||
| test("client amount views fail visibly instead of coercing or flipping amounts", async () => { | ||
| const [allClients, outstandings] = await Promise.all([ | ||
| readFile(new URL("../src/AllClientsScreen.tsx", import.meta.url), "utf8"), | ||
| readFile(new URL("../src/OutstandingsScreen.tsx", import.meta.url), "utf8"), | ||
| ]); | ||
|
|
||
| assert.match(allClients, /Amount unavailable/); | ||
| assert.doesNotMatch(allClients, /Math\.abs/); | ||
| assert.match(outstandings, /Bridge could not read an outstandings amount/); | ||
| assert.doesNotMatch(outstandings, /Math\.abs/); | ||
| }); | ||
|
|
||
| test("all-client responses carry the pinned GUID back to the open action", async () => { | ||
| const [allClients, commands] = await Promise.all([ | ||
| readFile(new URL("../src/AllClientsScreen.tsx", import.meta.url), "utf8"), | ||
| readFile(new URL("../src-tauri/src/commands.rs", import.meta.url), "utf8"), | ||
| ]); | ||
|
|
||
| assert.match(commands, /pub company_guid: String/); | ||
| assert.match(commands, /company_guid: entry\.expected_company_guid/); | ||
| assert.match(allClients, /companyGuid: entry\.company_guid/); | ||
| assert.doesNotMatch(allClients, /companies\.find\(\(company\) => company\.name === entry\.company\)/); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.