trendmicro-frontend / tonic-ui

Tonic UI is a UI component library for React, built with Emotion and Styled System. It is designed to be easy to use and easy to customize.
https://trendmicro-frontend.github.io/tonic-ui
MIT License
125 stars 28 forks source link

test(react): improve test coverage for `Accordion`, `Textarea`, and `VisuallyHidden` components #870

Closed cheton closed 2 months ago

cheton commented 3 months ago

PR Type

Enhancement, Tests


Description


Changes walkthrough 📝

Relevant files
Enhancement
AccordionContent.js
Add `role="region"` to AccordionContent for accessibility

packages/react/src/accordion/AccordionContent.js - Added `role="region"` to improve accessibility.
+1/-0     
Tests
Accordion.test.js
Add unit tests for Accordion component                                     

packages/react/src/accordion/__tests__/Accordion.test.js
  • Added unit tests for the Accordion component.
  • Tested rendering, toggling visibility, handling multiple items, and
    disabled state.
  • +189/-0 
    Textarea.test.js
    Add unit tests for Textarea component                                       

    packages/react/src/textarea/__tests__/Textarea.test.js
  • Added unit tests for the Textarea component.
  • Tested rendering, disabled, error, readonly, required attributes,
    onChange function, and border color.
  • +135/-0 
    VisuallyHidden.test.js
    Add unit tests for VisuallyHidden component                           

    packages/react/src/visually-hidden/__tests__/VisuallyHidden.test.js
  • Added unit tests for the VisuallyHidden component.
  • Tested rendering and visual hiding of content.
  • +37/-0   

    💡 PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    codesandbox[bot] commented 3 months ago

    Review or Edit in CodeSandbox

    Open the branch in Web EditorVS CodeInsiders
    Open Preview

    codesandbox-ci[bot] commented 3 months ago

    This pull request is automatically built and testable in CodeSandbox.

    To see build info of the built libraries, click here or the icon next to each commit SHA.

    codesandbox-ci[bot] commented 3 months ago

    This pull request is automatically built and testable in CodeSandbox.

    To see build info of the built libraries, click here or the icon next to each commit SHA.

    trendmicro-frontend-bot commented 3 months ago

    Tonic UI Demo

    codesandbox-ci[bot] commented 3 months ago

    This pull request is automatically built and testable in CodeSandbox.

    To see build info of the built libraries, click here or the icon next to each commit SHA.

    codesandbox-ci[bot] commented 3 months ago

    This pull request is automatically built and testable in CodeSandbox.

    To see build info of the built libraries, click here or the icon next to each commit SHA.

    codesandbox-ci[bot] commented 3 months ago

    This pull request is automatically built and testable in CodeSandbox.

    To see build info of the built libraries, click here or the icon next to each commit SHA.

    codesandbox-ci[bot] commented 3 months ago

    This pull request is automatically built and testable in CodeSandbox.

    To see build info of the built libraries, click here or the icon next to each commit SHA.

    cheton commented 2 months ago

    /review --pr_reviewer.inline_code_comments=true --pr_reviewer.require_score_review=true

    codiumai-pr-agent-pro[bot] commented 2 months ago

    PR Reviewer Guide 🔍

    (Review updated until commit https://github.com/trendmicro-frontend/tonic-ui/commit/aae0fea4798ff6f1088fe2fda342a5e792b0baa3)

    ⏱️ Estimated effort to review [1-5] 3
    🏅 Score 92
    🧪 Relevant tests Yes
    🔒 Security concerns No
    ⚡ Key issues to review None
    cheton commented 2 months ago

    /improve

    cheton commented 2 months ago

    /add_docs

    codiumai-pr-agent-pro[bot] commented 2 months ago

    PR Documentation 📚

    Here is a list of the files that were modified in the PR, with docstring for each altered code component:

    codiumai-pr-agent-pro[bot] commented 2 months ago

    PR Code Suggestions ✨

    Textarea.test.js                                                                                                                               

      arrow_function (function) [+99/-0]                                                                                                                   
      Component signature:
      ```javascript const arrow_function = () => { ``` Docstring:
      ```javascript /** * Test suite for the Textarea component. * * This function contains multiple test cases to ensure the Textarea component * renders correctly under various conditions and interactions. * * @function */ ```

    VisuallyHidden.test.js                                                                                                                   

      arrow_function (function) [+32/-0]                                                                                                                   
      Component signature:
      ```javascript const arrow_function = () => { ``` Docstring:
      ```javascript /** * Test suite for the VisuallyHidden component. * * @function * @name arrow_function * * @description * This function contains tests for the VisuallyHidden component to ensure it renders correctly and that its content is visually hidden but still present in the document. * * @example * describe('VisuallyHidden', () => { * it('should render correctly', async () => { * const { container } = render( * Hidden Content * ); * * expect(container).toMatchSnapshot(); * * await testA11y(container); * }); * * it('should render the content but visually hidden', () => { * const { getByText } = render( * Hidden Content * ); * const content = getByText('Hidden Content'); * * // Check that the content is in the document * expect(content).toBeInTheDocument(); * * // Check that the content is visually hidden * const styles = window.getComputedStyle(content); * expect(styles.position).toBe('absolute'); * expect(styles.width).toBe('1px'); * expect(styles.height).toBe('1px'); * expect(styles.padding).toBe('0px'); * expect(styles.border).toBe('0px'); * expect(styles.overflow).toBe('hidden'); * expect(styles.clipPath).toBe('inset(50%)'); * expect(styles.whiteSpace).toBe('nowrap'); * }); * }); */ ```
    CategorySuggestion                                                                                                                                    Score
    Enhancement
    Add an assertion to check the initial value of the textarea before typing ___ **In the test for the onChange function, add an assertion to check the initial value of the
    textarea before typing to ensure the test covers the initial state as well.** [packages/react/src/textarea/__tests__/Textarea.test.js [75-77]](https://github.com/trendmicro-frontend/tonic-ui/pull/870/files#diff-86a773dab4d14773dfe69929462b27070d0bb91aefb0aa0dfa8f7226b91fdf2dR75-R77) ```diff const textarea = screen.getByTestId('textarea'); +expect(textarea).toHaveDisplayValue(''); await user.type(textarea, 'hello'); expect(onChange).toHaveBeenCalled(); ``` - [x] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: This is a valid enhancement. Adding an assertion to check the initial value of the textarea ensures that the test covers the initial state, which is important for verifying that the textarea starts empty before any user interaction.
    7
    Compatibility
    Update the assertion to use clip instead of clipPath for better browser compatibility ___ **The expect(styles.clipPath).toBe('inset(50%)'); assertion on line 34 should be updated to
    expect(styles.clip).toBe('rect(1px, 1px, 1px, 1px)'); for better compatibility with older
    browsers that do not support clipPath.** [packages/react/src/visually-hidden/__tests__/VisuallyHidden.test.js [34]](https://github.com/trendmicro-frontend/tonic-ui/pull/870/files#diff-0e247f86dd40408f95235c167d00efc8abc097e6704a3d6f2ff991246f1202b7R34-R34) ```diff -expect(styles.clipPath).toBe('inset(50%)'); +expect(styles.clip).toBe('rect(1px, 1px, 1px, 1px)'); ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 6 Why: This suggestion is valid as using `clip` instead of `clipPath` can enhance compatibility with older browsers. It's a good practice to ensure that tests and styles are robust across different environments.
    6
    codesandbox-ci[bot] commented 2 months ago

    This pull request is automatically built and testable in CodeSandbox.

    To see build info of the built libraries, click here or the icon next to each commit SHA.

    codecov[bot] commented 2 months ago

    Codecov Report

    All modified and coverable lines are covered by tests :white_check_mark:

    Project coverage is 73.69%. Comparing base (beee3ee) to head (aae0fea).

    Additional details and impacted files ```diff @@ Coverage Diff @@ ## v2 #870 +/- ## ========================================== + Coverage 71.92% 73.69% +1.77% ========================================== Files 375 375 Lines 6140 6140 ========================================== + Hits 4416 4525 +109 + Misses 1724 1615 -109 ``` | [Flag](https://app.codecov.io/gh/trendmicro-frontend/tonic-ui/pull/870/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trendmicro-frontend) | Coverage Δ | | |---|---|---| | [codemod](https://app.codecov.io/gh/trendmicro-frontend/tonic-ui/pull/870/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trendmicro-frontend) | `74.28% <ø> (ø)` | | | [react](https://app.codecov.io/gh/trendmicro-frontend/tonic-ui/pull/870/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trendmicro-frontend) | `71.74% <ø> (+2.03%)` | :arrow_up: | | [react-base](https://app.codecov.io/gh/trendmicro-frontend/tonic-ui/pull/870/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trendmicro-frontend) | `100.00% <ø> (ø)` | | | [react-hooks](https://app.codecov.io/gh/trendmicro-frontend/tonic-ui/pull/870/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trendmicro-frontend) | `87.59% <ø> (ø)` | | | [styled-system](https://app.codecov.io/gh/trendmicro-frontend/tonic-ui/pull/870/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trendmicro-frontend) | `93.42% <ø> (ø)` | | | [theme](https://app.codecov.io/gh/trendmicro-frontend/tonic-ui/pull/870/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trendmicro-frontend) | `100.00% <ø> (ø)` | | | [utils](https://app.codecov.io/gh/trendmicro-frontend/tonic-ui/pull/870/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trendmicro-frontend) | `70.28% <ø> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=trendmicro-frontend#carryforward-flags-in-the-pull-request-comment) to find out more.

    :umbrella: View full report in Codecov by Sentry.
    :loudspeaker: Have feedback on the report? Share it here.

    codiumai-pr-agent-pro[bot] commented 2 months ago

    Persistent review updated to latest commit https://github.com/trendmicro-frontend/tonic-ui/commit/abbd8adb5df402143cf7e55ead001fe8d40b99a0

    codiumai-pr-agent-pro[bot] commented 2 months ago

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Accessibility
    Add accessibility check for the Textarea component with the disabled attribute ___ **The testA11y function call should include a check for the Textarea component with the
    disabled attribute to ensure accessibility compliance.** [packages/react/src/textarea/__tests__/Textarea.test.js [38-40]](https://github.com/trendmicro-frontend/tonic-ui/pull/870/files#diff-86a773dab4d14773dfe69929462b27070d0bb91aefb0aa0dfa8f7226b91fdf2dR38-R40) ```diff -render( +const { container } = render(