Skip to content

Feat/update tests#10

Merged
ghostleek merged 12 commits intomainfrom
feat/update-tests
Apr 3, 2026
Merged

Feat/update tests#10
ghostleek merged 12 commits intomainfrom
feat/update-tests

Conversation

@ghostleek
Copy link
Copy Markdown
Contributor

@ghostleek ghostleek commented Mar 29, 2026

  • Investigate HTML files to identify missing DOM elements and correct COMPONENT_SCALE values
  • Fix circuit-symbol.test.js: add missing DOM elements (rotate180Btn, zoom buttons, text controls) to beforeAll
  • Fix circuit-symbol.test.js: update componentSize() and getComponentNodes() assertions to reflect COMPONENT_SCALE = 0.8
  • Fix object-circuit.test.js: update getLocalNodes() and getComponentNodes() assertions to reflect COMPONENT_SCALE = 0.8 / BULB_SCALE = 1
  • Run tests to verify all pass (30/30 pass across both suites)

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

Add Jest tests for circuit tool logic (snap, gcd, componentSize, getComponentNodes) in __tests__/canvas/circuit-symbol.test.js and a test helper __tests__/canvas/helpers.js to extract and eval inline scripts from public/tools HTML files. Also relocate favicon to app/favicon.ico and remove several legacy touch/fav icon and image files (apple-touch icons, favicon-16/32, mstile, stringSq) as part of asset cleanup.
Add a new test suite (jsdom) for pure logic functions from circuit_diagram_secjc.html. Tests verify GRID (22.4), snap() behavior, rotatePoint() rotations, componentSize() for various components (transistor, transformer, bulb, battery, resistor), and getComponentNodes() geometry for transistor, transformer and standard components (resistor/arrow). Uses loadCircuitScript helper to import functions under test.
Add a new Jest test file (__tests__/canvas/object-circuit.test.js) that exercises pure logic from object_circuitv2.html. The tests run in the jsdom environment and validate rotatePoint at cardinal angles, getLocalNodes for bulb/battery/switch/unknown types, and getComponentNodes for world-space node positions. The file uses a loadCircuitScript helper and sets up a minimal DOM with SVG and tool buttons to initialise the script.
@ghostleek ghostleek requested a review from Copilot March 29, 2026 14:23
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
diagrams Ready Ready Preview, Comment Apr 3, 2026 4:08am

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Jest unit coverage for geometry/logic utilities embedded in the circuit HTML tools by extracting and evaluating their inline scripts under jsdom, plus includes an app favicon for the Next.js host.

Changes:

  • Added new Jest test suites for circuit_diagram_creatorv2.html, circuit_diagram_secjc.html, and object_circuitv2.html logic functions.
  • Introduced a shared test helper to extract and eval the first inline <script> from tool HTML files and return selected symbols.
  • Added app/favicon.ico.

Reviewed changes

Copilot reviewed 4 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
app/favicon.ico Adds favicon asset for the Next.js app.
tests/canvas/helpers.js Test helper for extracting/evaluating inline tool scripts and returning selected exports.
tests/canvas/circuit-symbol.test.js Unit tests for symbol tool logic (snap/gcd/sizing/nodes) via evaluated inline script.
tests/canvas/circuit-secjc.test.js Unit tests for SECJC tool logic (snap/rotate/sizing/nodes) via evaluated inline script.
tests/canvas/object-circuit.test.js Unit tests for object tool logic (rotate/local nodes/world nodes) via evaluated inline script.

Comment thread __tests__/canvas/object-circuit.test.js
Comment thread __tests__/canvas/object-circuit.test.js
Comment thread __tests__/canvas/circuit-symbol.test.js
Comment thread __tests__/canvas/circuit-symbol.test.js
ghostleek and others added 2 commits March 29, 2026 22:29
Add two new test suites:

- __tests__/canvas/water-tank.test.js: jsdom tests that set up a minimal DOM, load the water_tank_generator IIFE via a helper, and exercise rendering logic (initial SVG render, water polygon visibility based on percent, mode switching, and invalid-input error states).

- __tests__/pages/metrics.test.tsx: jsdom tests for the async MetricsPage server component that mock the DB (getDb), call render(await MetricsPage()), and verify aggregate stats, per-tool rows and counts, default-zero behavior when data is absent, and DB error handling.

These tests exercise UI behavior and server-component rendering with mocked database responses to catch regressions in rendering and error states.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
ghostleek and others added 3 commits March 29, 2026 22:32
Add new DOM controls to canvas test fixtures (rotate 180, text input, font size, add/update text, zoom in/out/reset) in circuit-symbol and object-circuit tests to match UI changes. Update MetricsPage test to reflect new mocked MAU/export values and adjust expectations. Add a jest.config testPathIgnorePatterns entry to ignore __tests__/canvas/helpers.js during test discovery.
…-circuit tests

Agent-Logs-Url: https://github.com/String-sg/diagrams/sessions/a3e69062-b05e-4798-b3f4-c90adcb3b978

Co-authored-by: ghostleek <44336310+ghostleek@users.noreply.github.com>
Adjust unit tests to reflect changes in component scaling and minor UI label updates. Tests in circuit-symbol now account for COMPONENT_SCALE = 0.8 by using toBeCloseTo for componentSize and node position assertions, and update snap() negative-value check to use Math.abs. object-circuit tests updated zoom button labels (+, −, 100%) and remove some unused text-related controls. water-tank test tightened the water polygon assertion to count polygons (ensuring only the clipPath polygon remains) rather than a simple string absence check.
Update CLAUDE.md test documentation to reflect expanded test suites (now 8 suites, 95 tests), add breakdown of API/pages/canvas tests, canvas helpers notes, and a gotcha about snap(-10) returning -0.

Adjust __tests__/canvas/object-circuit.test.js expectations to account for COMPONENT_SCALE=0.8: replace exact object equality with toBeCloseTo assertions and update numeric expected positions (battery node offsets -> ±36.8 local, world positions ~63.2/136.8; rotated battery x positions ~136.8/63.2; switch endpoints -> ±32). Add clarifying comments for the scaled geometry.
Update CLAUDE.md test documentation to reflect expanded test suites (now 8 suites, 95 tests), add breakdown of API/pages/canvas tests, canvas helpers notes, and a gotcha about snap(-10) returning -0.

Adjust __tests__/canvas/object-circuit.test.js expectations to account for COMPONENT_SCALE=0.8: replace exact object equality with toBeCloseTo assertions and update numeric expected positions (battery node offsets -> ±36.8 local, world positions ~63.2/136.8; rotated battery x positions ~136.8/63.2; switch endpoints -> ±32). Add clarifying comments for the scaled geometry.
@ghostleek ghostleek merged commit 31a1e87 into main Apr 3, 2026
4 checks passed
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.

3 participants