Skip to content

Text Block #721#1461

Merged
memisrose merged 2 commits intodevfrom
text-block-unit-test
Jul 11, 2025
Merged

Text Block #721#1461
memisrose merged 2 commits intodevfrom
text-block-unit-test

Conversation

@alaleung
Copy link
Copy Markdown
Contributor

@alaleung alaleung commented Jul 9, 2025

Description

Text block unit test
#721

Changes Made

Added Text block unit test

@alaleung alaleung requested a review from memisrose July 9, 2025 14:24
@alaleung alaleung requested a review from a team as a code owner July 9, 2025 14:24
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jul 9, 2025

@CodiumAI-Agent /describe

@QodoAI-Agent
Copy link
Copy Markdown

Title

Text Block #721


User description

Description

Text block unit test
#721

Changes Made

Added Text block unit test


PR Type

Tests


Description

  • Adds TextBlock initial render test

  • Tests hide functionality for blocks

  • Verifies tag rendering by variant


Changes walkthrough 📝

Relevant files
Tests
TextBlock.spec.tsx
Add TextBlock component tests                                                       

libs/renderer/src/testing/block-defaults/TextBlock.spec.tsx

  • Imports testing utilities and TextBlock
  • Defines sample blocks fixtures
  • Adds tests for rendering and visibility
  • Tests tag variants h1-h6, p, span
  • +75/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @github-actions
    Copy link
    Copy Markdown

    github-actions bot commented Jul 9, 2025

    @CodiumAI-Agent /review

    @github-actions
    Copy link
    Copy Markdown

    github-actions bot commented Jul 9, 2025

    @CodiumAI-Agent /improve

    @QodoAI-Agent
    Copy link
    Copy Markdown

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix duplicate block ID

    The id for text2 is set to "text", causing a duplicate and mismatch when rendering
    with id="text2". Update it to match the block key so that queries like
    querySelector("[data-block='text2']") target the correct element.

    libs/renderer/src/testing/block-defaults/TextBlock.spec.tsx [25-40]

     text2: {
         data: {
             text: "Hello world",
             isStreaming: false,
             show: "false",
         },
    -    id: "text",
    +    id: "text2",
         widget: "text",
         slots: {},
         listeners: {
             onChange: {
                 type: "sync",
                 order: [],
             },
         },
     },
    Suggestion importance[1-10]: 9

    __

    Why: The id for the text2 block is incorrectly set to "text", causing the selector [data-block='text2'] to fail; updating it to "text2" ensures the element is targeted correctly.

    High
    General
    Use empty DOM element matcher

    Using .equal("") on the result of expect() is not a valid Jest/Vitest matcher.
    Replace it with a DOM matcher to assert the element is empty, e.g.,
    toBeEmptyDOMElement().

    libs/renderer/src/testing/block-defaults/TextBlock.spec.tsx [60]

    -expect(textBlock.innerHTML).equal("");
    +expect(textBlock).toBeEmptyDOMElement();
    Suggestion importance[1-10]: 7

    __

    Why: .equal("") is not a valid Vitest/Jest matcher and will cause the test to error; replacing it with toBeEmptyDOMElement() uses a supported assertion to verify the element is empty.

    Medium
    Prevent shared-state mutation

    Mutating the shared blocks object across iterations can cause side effects between
    tests. Deep clone the blocks fixture inside the loop (or before each render) to
    isolate each variant test.

    libs/renderer/src/testing/block-defaults/TextBlock.spec.tsx [64-72]

     const tagNames = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "span"];
    -const variantBlock = blocks;
     tagNames.forEach((tag) => {
    -    variantBlock.text.data["variant"] = tag;
    +    const variantBlock = JSON.parse(JSON.stringify(blocks));
    +    variantBlock.text.data.variant = tag;
         const { container } = render(<TextBlock id="text" />, {
             blocks: variantBlock,
         });
    -    const textBlock = container.querySelector(`${tag}`);
    +    const textBlock = container.querySelector(tag);
         expect(textBlock).not.toBeNull();
     });
    Suggestion importance[1-10]: 6

    __

    Why: Mutating the shared blocks object across loop iterations can introduce side effects and flaky tests; deep cloning it isolates each variant test for reliability.

    Low

    Copy link
    Copy Markdown
    Contributor

    @memisrose memisrose left a comment

    Choose a reason for hiding this comment

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

    all tests pass with no issues

    @memisrose memisrose merged commit ac79d6b into dev Jul 11, 2025
    3 checks passed
    @memisrose memisrose deleted the text-block-unit-test branch July 11, 2025 17:59
    @github-actions
    Copy link
    Copy Markdown

    @CodiumAI-Agent /update_changelog

    @QodoAI-Agent
    Copy link
    Copy Markdown

    Changelog updates: 🔄

    2025-07-11 *

    Added

    • Text block renderer unit tests.

    to commit the new content to the CHANGELOG.md file, please type:
    '/update_changelog --pr_update_changelog.push_changelog_changes=true'

    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.

    4 participants