console icon indicating copy to clipboard operation
console copied to clipboard

NO-JIRA: Add /gen-rtl-tests Claude code slash command for generating React Testing Library tests for React components

Open cajieh opened this issue 2 months ago • 13 comments

Add /gen-rtl-tests Claude code slash command for generating React Testing Library tests for React components

The /gen-rtl-tests uses the OCP Console React Testing Library Best Practices for React Components guide as a source of truth for test generation.

Usage

- /gen-rtl-test path/to/Component.tsx - Generate tests for a specific component
- /gen-rtl-test @Component.tsx` - Use `@` for file autocomplete, then select the file
- /gen-rtl-test` - Without arguments, you'll be prompted for the component

Objectives

  • Establish consistent project-wide testing standards
  • Promote user-centric testing that focuses on behavior over implementation
  • Provide practical, rules-based guidance for common scenarios
  • Improve test quality, resilience, and maintainability

Workflow

☒ Read and analyze <Component.tsx> ☒ Generate 5-10 comprehensive tests using Console RTL Best Practices for React Components ☒ Run generated tests ☒ Fix any test failures ☒ Fix act() warnings ☐ Run yarn build validation ☐ Verify all tests pass with zero warnings

cajieh avatar Nov 03 '25 20:11 cajieh

@cajieh: This pull request explicitly references no jira issue.

In response to this:

Add /gen-rtl-tests Claude code slash command for generating React Testing Library tests for React components

The /gen-rtl-tests uses the OCP Console React Testing Library Best Practices for React Components guide as a source of truth for test generation.

Usage

- /gen-rtl-test path/to/Component.tsx - Generate tests for a specific component
- /gen-rtl-test @Component.tsx` - Use `@` for file autocomplete, then select the file
- /gen-rtl-test` - Without arguments, you'll be prompted for the component

Objectives

  • Establish consistent project-wide testing standards
  • Promote user-centric testing that focuses on behavior over implementation
  • Provide practical, rules-based guidance for common scenarios
  • Improve test quality, resilience, and maintainability

Workflow

☒ Read and analyze <Component.tsx> ☒ Generate 5-10 comprehensive tests using Console RTL Best Practices for React Components ☒ Run generated tests ☒ Fix any test failures ☒ Fix act() warnings ☐ Run yarn build validation ☐ Verify all tests pass with zero warnings

This proposed /gen-rtl-tests slash command requires more testing for reliable and consistent output across multiple runs.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

openshift-ci-robot avatar Nov 03 '25 20:11 openshift-ci-robot

The PR looks good. I think we are missing the case when developer did some changes (added/modified some components) in which case Claude should check the git diff and add/update the components. I think that could be the default use case when dev will not supply any arguments. If there are no valid components changes in the git diff we should be prompting the dev for name.

Also I would also add a step where Claude will actually execute the added/modified tests to validate if they are passing.

Makes sense. 🙏

cajieh avatar Nov 05 '25 13:11 cajieh

Walkthrough

A new documentation file is added at .claude/commands/generate-rtl-tests.md that outlines a comprehensive workflow and standards for generating React Testing Library tests, including usage instructions, component detection, testing principles, 26 rules, and validation procedures.

Changes

Cohort / File(s) Summary
Documentation for RTL Test Generation
\.claude/commands/generate-rtl-tests\.md
Added new documentation file detailing comprehensive workflow and standards for React Testing Library test generation, including component detection, testing principles, 26 rules, test targets, verification steps, and validation procedures

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

✨ Finishing touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Dec 01 '25 16:12 coderabbitai[bot]

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cajieh, jhadvig, sg00dwin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

openshift-ci[bot] avatar Dec 12 '25 17:12 openshift-ci[bot]

/verified by @jhadvig

cajieh avatar Dec 16 '25 16:12 cajieh

@cajieh: This PR has been marked as verified by @jhadvig.

In response to this:

/verified by @jhadvig

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

openshift-ci-robot avatar Dec 16 '25 16:12 openshift-ci-robot

/label jira/valid-bug

cajieh avatar Dec 16 '25 18:12 cajieh

/retest

cajieh avatar Dec 16 '25 18:12 cajieh

@cajieh: Can not set label jira/valid-bug: Must be member in one of these teams: [openshift-patch-managers openshift-staff-engineers openshift-release-oversight openshift-sustaining-engineers]

In response to this:

/label jira/valid-bug

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

openshift-ci[bot] avatar Dec 16 '25 18:12 openshift-ci[bot]

/test okd-scos-images

cajieh avatar Dec 17 '25 11:12 cajieh

/retest-required

Remaining retests: 0 against base HEAD 19b01f06cb8106dfe21ca3cc12dd5376a5935e39 and 2 for PR HEAD d65903e192919ed646440378c19c8b3481c2abdc in total

openshift-ci-robot avatar Dec 17 '25 11:12 openshift-ci-robot

/retest-required

Remaining retests: 0 against base HEAD 9ac9e36e6bca30bd2b7f84752cc588f4cb842b44 and 1 for PR HEAD d65903e192919ed646440378c19c8b3481c2abdc in total

openshift-ci-robot avatar Dec 17 '25 16:12 openshift-ci-robot

/retest-required

Remaining retests: 0 against base HEAD d3b540a070b976f490eb3259f963703f4c33200d and 0 for PR HEAD d65903e192919ed646440378c19c8b3481c2abdc in total

openshift-ci-robot avatar Dec 18 '25 18:12 openshift-ci-robot

@cajieh: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

openshift-ci[bot] avatar Dec 18 '25 19:12 openshift-ci[bot]