Skip to content

refactor(webapp): bring all webapp JS functions under CRAP 10 - #14

Open
adamsrnmsu wants to merge 1 commit into
sandialabs:mainfrom
adamsrnmsu:refactor-js-crap
Open

adamsrnmsu wants to merge 1 commit into
sandialabs:mainfrom
adamsrnmsu:refactor-js-crap

Conversation

@adamsrnmsu

Copy link
Copy Markdown
Collaborator

Description

Follow-up to #5 (which covered Python). crapper reported 52 webapp JS functions at CRAP >= 10, but that was an artifact: without the npm dependencies, JS coverage failed (Cannot find module 'jsdom') and every function scored 0%. With them installed the real list is 25 functions in alerts/static/js/script.js, registers.js, main.js and network_analytics.js. All are now under 10 (highest 9.8).

  • jsdom tests: js_tests/load_script.js runs a page script in jsdom with real jQuery/d3; new tests for main.js, network_analytics.js, registers.js and the alerts helpers. npm test also runs js_tests/*.test.js.
  • Behaviour-preserving extractions where complexity was real: renderAlertList (CC 24), openAlertStream, getAxiosErrorMessage, renderHealthStatus in alerts; draw (CC 22) in registers (resolveMargin also replaces the repeated margin block in the two heatmaps; options.margin is no longer written back to the caller, nothing read it).

Related Issues/PRs

Type of Change

  • Bugfix (fix)
  • Feature (feat)
  • Documentation (docs)
  • Refactor (refactor)
  • Chore (CI, build, dependencies, etc.) (chore)
  • Other (please describe):

Checklist

Testing

  • crapper (webapp JS): 25 functions at CRAP >= 10 before, 0 after.
  • npm test in src/parseus/webapp: 30 tests before, 71 pass and 0 fail after.
  • No Python files changed; the Python suite is unchanged.

Additional Notes

Found while writing the tests, not fixed here: updateGraph passes ${graph_id}-legend without a #, and addToLegend/clearLegend call $(legend_id), which selects a tag name, so the register and state graph legends are never filled. The new tests deliberately do not assert legend contents.

🤖 Generated with Claude Code

Problem: crapper reported 52 webapp JS functions at CRAP >= 10. That number
was an artifact: the npm dependencies were not installed, so JS coverage
failed ("Cannot find module 'jsdom'") and everything scored 0% coverage.
With deps installed (npm install in src/parseus/webapp; node_modules is
already ignored) coverage works and the real list is 25 functions in
alerts/script.js, registers.js, main.js and network_analytics.js.

Cause: five of them had real complexity (draw CC 22, renderAlertList 24,
getAxiosErrorMessage 13, renderHealthStatus 12, openAlertStream 11,
getAlertListSignature 10, reconcilePendingAlertActions 10); the rest were
simply untested (main.js, network_analytics.js, registers.js had no JS
tests at all).

Fix: add jsdom tests (a small loader, js_tests/load_script.js, runs a page
script in jsdom with real jQuery/d3 where the page uses them; npm test now
also runs js_tests/*.test.js), plus behaviour-preserving extractions:
- alerts: captureAlertSelection/restoreAlertSelection/buildAlertRow/
  getAlertTotalCount out of renderAlertList; getAlertSignatureEntry;
  collectSnapshotUuids; getAxiosResponseData; renderDiskUsage;
  handleAlertSnapshotEvent/handleAlertHeartbeatEvent out of openAlertStream.
- registers: resolveMargin, resolvePointStyle, createXScale, paddedDomain
  out of draw (resolveMargin also replaces the repeated margin block in the
  two heatmaps; options.margin is no longer written back, nothing read it).

Verified:
- crapper (webapp, JS): functions with CRAP >= 10: 25 real (52 reported
  before, with coverage broken) -> 0; highest remaining is 9.8.
- npm test: 30 tests before -> 71 pass, 0 fail.
- Python: no Python files changed; tests/test_analytics_capability_declarations.py
  21 passed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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