Skip to content

test: verify AbstractGraph.createHandler factory method delegation#819

Merged
tbouffard merged 3 commits intomainfrom
test/Graph.createHandler_factory_methods
May 7, 2025
Merged

test: verify AbstractGraph.createHandler factory method delegation#819
tbouffard merged 3 commits intomainfrom
test/Graph.createHandler_factory_methods

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented May 7, 2025

Add tests ensuring AbstractGraph.createEdgeHandler properly delegates to specialized factory methods
(createElbowEdgeHandler and createEdgeSegmentHandler) based on edge style registry configuration.
Tests cover both built-in edge styles and custom handler implementations.

This prepares the move of these methods to SelectionCellsHandler where they are used.

Notes

Covers #762

Summary by CodeRabbit

Summary by CodeRabbit

  • Tests
    • Added new tests to verify support for custom edge handler classes when using custom edge styles, ensuring correct instantiation for different handler types.

Add tests ensuring `AbstractGraph.createEdgeHandler` properly delegates to specialized factory methods
(createElbowEdgeHandler and createEdgeSegmentHandler) based on edge style registry configuration.
Tests cover both built-in edge styles and custom handler implementations.
@tbouffard tbouffard added the chore Build, CI/CD or repository tasks (issues/PR maintenance, environments, ...) label May 7, 2025
@coderabbitai
Copy link

coderabbitai bot commented May 7, 2025

Walkthrough

The test suite for the Graph's createEdgeHandler functionality was expanded with new tests. These tests verify that custom edge handler classes are correctly instantiated when custom edge styles are used, ensuring that the graph respects custom handler implementations associated with specific handler kinds. Global setup and teardown were added to maintain a clean edge style registry state.

Changes

File(s) Change Summary
packages/core/tests/view/Graph.test.ts Added a "Custom edge handler" describe block with three tests verifying instantiation of custom edge handler classes for custom edge styles and handler kinds. Added global setup/teardown hooks to unregister edge styles before/after tests. Removed redundant unregister calls. No changes to public or exported entities.

Sequence Diagram(s)

sequenceDiagram
    participant TestSuite
    participant Graph
    participant EdgeStyleRegistry
    participant CustomEdgeHandler

    TestSuite->>Graph: createEdgeHandler(edge)
    Graph->>EdgeStyleRegistry: getHandlerKind(style)
    alt handlerKind is 'elbow'
        Graph->>CustomEdgeHandler: createElbowEdgeHandler()
    else handlerKind is 'segment'
        Graph->>CustomEdgeHandler: createEdgeSegmentHandler()
    else
        Graph->>CustomEdgeHandler: createEdgeHandlerInstance()
    end
    Graph-->>TestSuite: returns instance of custom handler
Loading

Possibly related PRs

  • test: improve the Graph tests #797: Both PRs enhance the test coverage for createEdgeHandler in the Graph test suite, focusing on custom edge styles and handler instantiation, making their changes directly related.
  • fix: consider ManhattanConnector as orthogonal #707: This PR modifies the core logic of createEdgeHandler and related methods, intersecting with the current PR's focus on testing custom handler instantiation, making them related at the level of handler creation and testing.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b1ec2c and 4451016.

📒 Files selected for processing (1)
  • packages/core/__tests__/view/Graph.test.ts (3 hunks)
🔇 Additional comments (5)
packages/core/__tests__/view/Graph.test.ts (5)

27-27: Good import addition for test requirements.

The EdgeStyleRegistry import is appropriately added to support the custom edge handler tests where specific handler kinds need to be registered.


41-46: Well-structured test isolation.

Adding global beforeEach and afterAll hooks that call unregisterAllEdgeStyles() ensures a clean edge style registry state before each test and after all tests. This prevents test pollution and allows tests to run independently.


194-208: Comprehensive test for default handler delegation.

This test effectively verifies that when a graph overrides the createEdgeHandlerInstance method, the createEdgeHandler method correctly uses this custom implementation. The test structure clearly demonstrates the factory pattern delegation.


210-224: Well-designed test for elbow handler delegation.

This test properly verifies that when a custom edge style is registered with handlerKind: 'elbow' and the graph overrides the createElbowEdgeHandler method, the createEdgeHandler method correctly delegates to this specialized factory method. This aligns perfectly with the PR objective of testing factory method delegation.


226-240: Thorough test for segment handler delegation.

This test effectively verifies that when a custom edge style is registered with handlerKind: 'segment' and the graph overrides the createEdgeSegmentHandler method, the createEdgeHandler method correctly delegates to this specialized factory method. The test completes the coverage of the factory delegation logic.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/core/__tests__/view/Graph.test.ts (1)

215-215: Consider cleaning up registered edge styles

The tests register custom edge styles but don't unregister them afterward. While this doesn't appear to affect the current test suite (due to the isolated nature of each test), consider adding cleanup code to ensure test isolation.

 test('elbow', () => {
   class CustomEdgeHandler extends ElbowEdgeHandler {}
   const edgeStyle = customEdgeStyle;
   EdgeStyleRegistry.add('custom', edgeStyle, { handlerKind: 'elbow' });
+  afterAll(() => {
+    EdgeStyleRegistry.remove('custom');
+  });

   // ...test implementation...
 });

Also applies to: 231-231

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f9d1d3d and 4b1ec2c.

📒 Files selected for processing (1)
  • packages/core/__tests__/view/Graph.test.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/core/__tests__/view/Graph.test.ts (2)
packages/core/src/index.ts (1)
  • BaseGraph (21-21)
packages/core/src/view/style/edge/EdgeStyleRegistry.ts (1)
  • EdgeStyleRegistry (65-65)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (ubuntu-22.04)
  • GitHub Check: build (macos-14)
  • GitHub Check: build
🔇 Additional comments (6)
packages/core/__tests__/view/Graph.test.ts (6)

27-27: Appropriate import addition

Added EdgeStyleRegistry import is necessary for the new tests to register custom edge styles with specific handler kinds.


195-195: Well-named test group

The "Custom edge handler" describe block clearly indicates its purpose of testing custom edge handler functionality.


196-210: Good test for default handler customization

This test properly verifies that the graph uses a custom EdgeHandler subclass when createEdgeHandlerInstance is overridden.

Note that line 199 is commented out, which appears intentional as this test doesn't require the style to be registered with the registry (it's testing the default case).


212-226: Correct verification of elbow handler delegation

This test properly verifies that when a custom style is registered with handlerKind: 'elbow', the graph delegates to the overridden createElbowEdgeHandler method.


228-242: Correct verification of segment handler delegation

This test properly verifies that when a custom style is registered with handlerKind: 'segment', the graph delegates to the overridden createEdgeSegmentHandler method.


195-243: Good test coverage for createEdgeHandler factory method delegation

These tests effectively verify that AbstractGraph.createEdgeHandler correctly delegates to specialized factory methods based on edge style registry configuration. The tests cover both built-in edge styles (in the existing tests) and custom handler implementations (in the new tests).

The tests are well-structured with consistent patterns:

  1. Define a custom handler class
  2. Register the edge style with appropriate handler kind
  3. Override the appropriate factory method
  4. Verify the correct handler instance is created

This aligns perfectly with the PR objectives to verify factory method delegation.

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 7, 2025

@tbouffard tbouffard merged commit aa579c1 into main May 7, 2025
2 checks passed
@tbouffard tbouffard deleted the test/Graph.createHandler_factory_methods branch May 7, 2025 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Build, CI/CD or repository tasks (issues/PR maintenance, environments, ...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant