Skip to content

Test the diagram's elements against real pathways - #12

Merged
adamjohnwright merged 2 commits into
mainfrom
diagram-service-tests
Oct 9, 2026
Merged

adamjohnwright merged 2 commits into
mainfrom
diagram-service-tests

Conversation

@adamjohnwright

Copy link
Copy Markdown
Contributor

DiagramService.getDiagram turns Reactome's layout and graph files into the elements cytoscape draws. That's about 700 lines, and no test covered it.

These tests run it on two real pathways, stored as fixtures exactly as the release serves them:

  • R-HSA-9679191, Potential therapeutics for SARS: drugs, entity sets, links.
  • R-HSA-2206292, MPS VII: a disease diagram, with normal entities faded out and affected ones crossed out.

What any drawn diagram must satisfy:

  • every element has its own id;
  • no line points at something that isn't drawn;
  • every entity in the layout is drawn as its kind (the classes from nodeTypeMap) and keeps its reactomeId;
  • every reaction becomes a node.

And for these pathways:

  • each drug carries the drug class;
  • each crossed-out entity carries crossed;
  • each faded entity is isFadeOut, and whatever replaces it is drawn.

Shown to catch faults: I broke the service four ways, one at a time: dropped the drug class, dropped the crossed class, broke a link's source, and switched off the fade. Each made exactly one test fail; restored, all 18 pass.

avoidOverlap lays sub-pathway labels out in a rendered cytoscape graph, which measures text on a canvas that jsdom doesn't have. The spec stubs a 2D context that measures a character as 6px and draws nothing. The fixtures are minified (about 250 KB in all) and excluded from Prettier.

🤖 Generated with Claude Code

Adam Wright and others added 2 commits October 9, 2026 13:55
The diagram service turns Reactome's layout and graph files into the
elements cytoscape draws -- some 700 lines no test touched. These check it
against two real pathways, stored as fixtures exactly as the release serves
them: R-HSA-9679191 (drugs, entity sets, links) and R-HSA-2206292 (a
disease diagram, normal entities faded and affected ones crossed out).

What a drawn diagram has to be, whatever the pathway: every element its own
id, no line to something not drawn, every entity of the layout drawn as its
kind, every reaction a node; and a drug marked a drug, a crossed-out entity
crossed, a faded one faded and replaced by something drawn. Each was shown
to catch a fault: dropping the drug class, the crossed class, a link's
source, or the fade each fails exactly one test.

Sub-pathway labels are laid out in a rendered cytoscape graph, which
measures text on a canvas jsdom does not have; the spec gives it one that
measures and draws nothing. The fixtures are left out of Prettier.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From review:
- Only 2 of the 34 faded entities in MPS VII have a replacement, so the
  check passed with replacements gone entirely. It now covers faded
  reactions too and requires that some have one; crossed-out entities must
  not be faded. Shown failing with no replacement set.
- The expected classes were read from the service's own map, so a wrong
  entry there passed. They are written out now; shown failing with Gene
  drawn as RNA.
- R-HSA-69620, Cell Cycle Checkpoints, is added: sub-pathway labels, a gene,
  an RNA and an embedded pathway. Each label is drawn once and placed apart
  from the others; shown failing with one label lost.
- Unanswered requests fail the test; only the canvas stub is restored, not
  every mock; and its comment says why it is needed even with no
  sub-pathways.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adamjohnwright
adamjohnwright merged commit 41e6775 into main Oct 9, 2026
1 check passed
@adamjohnwright
adamjohnwright deleted the diagram-service-tests branch October 9, 2026 14:17
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