Skip to content

Add unit tests for 18 low-coverage files, and fix what they found - #205

Open
jeffmaki wants to merge 12 commits into
developfrom
test/coverage-batch1
Open

jeffmaki wants to merge 12 commits into
developfrom
test/coverage-batch1

Conversation

@jeffmaki

@jeffmaki jeffmaki commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

CI flagged 18 files with poor test coverage: the project wizard and projects services, their composables and storage, util/geojson.ts, AppSelect, the dashboard map and three review panels. Each file now has @test outline comments at the top, with unit tests written to them. Where the code disagreed with the outline, the code was fixed, so this PR also changes some behavior (listed below).

Measured with #204's line-based coverage, total line coverage is 65% on this branch, up from 60.3% on develop. This PR's own CI still uses develop's statement-based merge, which loses most unit-test hits, so its table reads 50%. #204 replaces that merge.

Behavior changes

Review page

  • Details shows "N/A" for a missing value, for an open changeset's close date and for feedback with no due date. It used to crash on an open changeset or show the epoch.
  • An unchanged ("noop") element reads "unchanged".

Dashboard map

  • A failed map setup is retried on the next workspace.
  • The spinner stays until the map has loaded. An error before the style loads shows the error message; a failed tile doesn't.
  • Resizing re-fits the view only until the user pans or zooms.

AppSelect

  • It now has listbox semantics. The toggle is a combobox named "label: value", the options have the option role, and the selected and active options are marked.
  • Escape inside a dialog closes only the list.

Projects

  • Project-group POCs get lead access to projects, including the Contributors tab. The backend already treats POCs as leads.
  • Project cards round completed tasks to the nearest task. Above 100 tasks they say "About N/M", because percent_completed arrives rounded. The project page still counts its loaded tasks exactly.
  • Unknown task statuses log a warning.

Project wizard

  • Area upload:
    • It keeps the largest polygon anywhere in the file: in a MultiPolygon, across a FeatureCollection's features, in a GeometryCollection, in an array of Features or nested under other keys.
    • An amber warning names the polygons, holes and features it left out.
    • An unclosed triangle is accepted.
    • Bare coordinate arrays, bare points and lines, non-WGS 84 coordinates and zero-area outlines are rejected, each with its own message.
    • Malformed GeoJSON gives an upload message instead of a TypeError.
  • Tasks tab:
    • It shows "About N tasks" under the task-size slider. The count used to be computed without being shown.
    • The count mirrors the server's latitude/longitude grid.
    • It takes tens of milliseconds for a 100,000-vertex boundary, down from most of a second.
    • It counts a cell the boundary cuts into pieces once, while the server makes a task of each piece, so it can run a little low.
  • A non-numeric task size falls back to 0.45 km².
  • Review step:
    • The imagery row reads "Checking…" while validation runs, then "Working", "Not valid" or "Not provided".
    • The Number of tasks row is removed, since tasks are only generated later, on the Tasks tab.
  • Malformed custom imagery shows "Custom imagery is not valid JSON."
  • Blank instructions are sent as null, like the description. The backend's instructions field is optional.
  • Saved wizard progress needs a real polygon to restore, and restores for any project status the API returns.
  • The step configuration is checked when the wizard loads.
  • The wizard client wraps errors as the projects client does. From the create response it reads id and keeps the API's status.
  • bboxToPolygon gives its Feature properties: {}, and an empty ring throws.

Removed

These were deleted instead of tested, because nothing uses them:

  • the task-generation simulation and services/mock-project-wizard.ts
  • listWorkspaceUsers
  • the VITE_USE_MOCK_WORKSPACE_PROJECTS flag, with services/mock-workspace-projects.ts and mock-api/workspace-projects/

Testing

  • Unit: all 1,173 tests in 87 files pass. Lint and typecheck are clean.
  • E2E: the full suite passed on this branch combined with Merge unit and e2e coverage by line, and count components and composables #204, apart from three tests:
    • signin and smoke expect port 3000, and the run used another port.
    • "applies a filter requested while a refresh is in progress" in review.spec.ts is timing-sensitive. It failed once in a full parallel run, and passed 10 of 10 on both this branch and develop when rerun under equal load.
  • Project specs: the create, edit and index specs pass after the last commits.
  • Preview count: the faster count matched the previous code on 1,600 random boundaries. A unit test checks it against a cell-by-cell count.

🤖 Generated with Claude Code

jeffmaki and others added 12 commits December 2, 2026 12:32
Proposed outlines only, for review before tests are generated from them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add unit tests written to each file's @test outline, with the outlines
revised to state the product owner's decisions. All nine files reach 100%
unit line coverage. The code changes those decisions call for:

- useProjectDisplay: completedTaskCount rounds down, so 10 tasks at 96%
  show 9/10 (15).
- useProjectRole: a project-group POC gets lead-level access on projects,
  including managing contributors; the project detail and edit pages pass
  in the TDEI roles they already load (14). The effective-role comment now
  says a project role replaces the workspace role (13).
- geojson: bboxToPolygon's Feature has properties {} (16); polygonToBbox
  and shapeToCenter throw for an empty outer ring (17).
- Wizard storage: a restored AOI needs closed rings of at least 4
  positions (18).
- Custom imagery: malformed JSON reports "Custom imagery is not valid
  JSON." rather than the parser's own message (19).
- Step config: each of the four steps must appear exactly once (20).
- Create payload: blank instructions are sent as null (21).
- Review step: the imagery status follows the validation result, passed in
  by the create page: Working, Not valid or Not provided (22). The Number
  of Tasks row is gone, since tasks are generated later (23).

The payload and review tests stub the rich-text sanitizer, because
DOMPurify does not work under happy-dom: it unwraps allowed tags and lets
<script> through.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Unit tests for five components, written to their @test outlines, which
now record the product owner's decisions:

- AppSelect: Escape on an open list closes only the list, not an
  enclosing dialog such as AddContributorDialog's b-modal. The toggle is
  a combobox named with its current value; the list is a listbox of
  options with the selected one aria-selected, and the active option is
  referenced with aria-activedescendant.
- Dashboard map: the spinner stays until the map has loaded, and a map
  that reports an error before its style loads shows the error instead
  of spinning. A failed map setup is retried for the next workspace.
  A container resize re-fits the view only until the user pans or zooms.
- Review attribute diff: a noop action's header reads "unchanged".
- Review details: an open changeset's Closed At (an Invalid Date that
  crashed formatting), a feedback with no due date (shown as 12/31/69)
  and any field with no value now show "N/A".
- Feature image: no code change; the outline now says a new image
  expands the panel again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The product owner revised two decisions.

- 15: the completed task count rounds to the nearest task. The API sends
  percent_completed rounded from the real counts, so the nearest task is
  exact for up to 100 tasks. Above that the count can be off, so it reads
  "About <done>/<total>". The project cards and the project page share one
  helper, completedTasksFromPercent, so they agree.
- 22: while the custom imagery is still being validated, as right after
  reloading on the Review step, its status reads "Checking…". The create
  page passes its pending state to the review summary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Unit tests for services/project-wizard-aoi.ts, project-wizard-tasks.ts,
project-wizard.ts and projects.ts, written to their revised @test outlines,
plus a composable test for the area step's upload warning.

AOI upload (project-wizard-aoi.ts):
- Malformed GeoJSON (a FeatureCollection without features, non-array
  coordinates, null features or positions) gives an upload message, never a
  TypeError (25).
- A bare coordinate array is still rejected, now with a message that says so (26).
- An untyped { coordinates } MultiPolygon keeps its largest polygon, like a
  typed one (27); a 3-point unclosed ring works in a MultiPolygon too (28).
- The parser returns a warning when holes, other polygons or other features
  are dropped; the area step shows it as a warning, on its own line (29).
- Coordinates outside lon +-180 / lat +-90 and zero-area rings are rejected (30).

Task preview (project-wizard-tasks.ts):
- normalizeTaskAreaSquareKilometers(NaN) gives the 0.45 default (31).
- The preview lays the server's lat/lon grid and counts only the cells that
  meet the AOI, up to the server's 50 000 cap (32). A cell the AOI cuts into
  separate pieces counts once; the server counts each piece.
- Remove simulateProjectWizardTaskGeneration and mock-project-wizard.ts (34).

Clients:
- ProjectWizardClientError wraps non-2xx responses with the Response (35).
- createProject returns the API's status, else draft (36), reading only id (37).
- Remove the unused listWorkspaceUsers (39) and ProjectWizardWorkspaceUser.id (24).
- Correct the stale mapper-name comment (40); remove the mock projects branch,
  mock-workspace-projects.ts and its JSON (41); warn on an unknown task status (42).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bboxToPolygon now includes `properties: {}` (decision 16); the dashboard map
tests were written against the Feature without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The wizard keeps the status the API gives a new project (#36), so its saved
progress now restores for any status the API returns, not only "draft".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An upload now keeps its largest polygon wherever it is: across a
FeatureCollection's features, in a GeometryCollection, in an array of
Features or nested under other keys, as a MultiPolygon already did. The
warning counts the polygons and features left out. A polygon without
three usable points is passed over when another is usable, and bare
points and lines are rejected rather than read as an outline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Tasks tab now shows "About N tasks" under the task-size slider. The
count files each boundary segment under the grid rows it crosses, so a row
checks only its own segments: a 100,000-vertex boundary takes tens of
milliseconds instead of most of a second, with the same counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fb92ef4f-57dc-4aae-aae6-ae2a660dc661
Commits

Reviewing files that changed from the base of the PR and between 6ee7bf6 and 3c4de5a.

Files selected for processing: 52

  • components/AppSelect.vue
  • components/dashboard/Map.vue
  • components/project-wizard/steps/AreaOfInterestStep.vue
  • components/project-wizard/steps/ReviewStep.vue
  • components/review/AttributeDiff.vue
  • components/review/Details.vue
  • components/review/FeatureImage.vue
  • components/workspace-project-details/TaskSetupPanel.vue
  • composables/useProjectDisplay.ts
  • composables/useProjectRole.ts
  • composables/useProjectWizardAoi.ts
  • composables/useProjectWizardSettings.ts
  • mock-api/workspace-projects/page-1.json
  • mock-api/workspace-projects/page-2.json
  • mock-api/workspace-projects/page-3.json
  • pages/workspace/[id]/projects/[projectId]/edit.vue
  • pages/workspace/[id]/projects/[projectId]/index.vue
  • pages/workspace/[id]/projects/create.vue
  • services/mock-project-wizard.ts
  • services/mock-workspace-projects.ts
  • services/project-custom-imagery.ts
  • services/project-wizard-aoi.ts
  • services/project-wizard-definitions.ts
  • services/project-wizard-payload.ts
  • services/project-wizard-review.ts
  • services/project-wizard-tasks.ts
  • services/project-wizard-users.ts
  • services/project-wizard.ts
  • services/projects.ts
  • test/unit/components/AppSelect.test.ts
  • test/unit/components/DashboardMap.test.ts
  • test/unit/components/ReviewAttributeDiff.test.ts
  • test/unit/components/ReviewDetails.test.ts
  • test/unit/components/ReviewFeatureImage.test.ts
  • test/unit/components/TaskSetupPanel.test.ts
  • test/unit/composables/useProjectDisplay.test.ts
  • test/unit/composables/useProjectRole.test.ts
  • test/unit/composables/useProjectWizardAoi.test.ts
  • test/unit/services/project-custom-imagery.test.ts
  • test/unit/services/project-wizard-aoi.test.ts
  • test/unit/services/project-wizard-definitions.test.ts
  • test/unit/services/project-wizard-payload.test.ts
  • test/unit/services/project-wizard-review.test.ts
  • test/unit/services/project-wizard-tasks.test.ts
  • test/unit/services/project-wizard-users.test.ts
  • test/unit/services/project-wizard.test.ts
  • test/unit/services/projects.test.ts
  • test/unit/util/geojson.test.ts
  • test/unit/util/project-wizard-storage.test.ts
  • types/project-wizard.ts
  • util/geojson.ts
  • util/project-wizard-storage.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

This branch has not been deployed

No deployments
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.

1 participant