Skip to content

Add skill for writing unit tests for PatternFly ecosystem components#29

Merged
jpuzz0 merged 6 commits intopatternfly:mainfrom
wise-king-sullyman:add-pf-testing-skill
Apr 2, 2026
Merged

Add skill for writing unit tests for PatternFly ecosystem components#29
jpuzz0 merged 6 commits intopatternfly:mainfrom
wise-king-sullyman:add-pf-testing-skill

Conversation

@wise-king-sullyman
Copy link
Copy Markdown
Contributor

@wise-king-sullyman wise-king-sullyman commented Mar 19, 2026

Closes #22

Summary by CodeRabbit

  • Documentation
    • Added a new PatternFly test-writing skill guide for contributors, detailing conventions for test file organization, naming, and a standard Jest + React Testing Library scaffold.
    • Includes guidance on mocking, test nesting, snapshot vs. class assertions, inline setup recommendations, and a comprehensive coverage checklist to ensure consistent, isolated unit tests.


## Output

Output the complete test file ready to save. Name it `ComponentName.test.tsx`.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The existing unit-test-generator covers the same task in 69 lines by trusting the AI to know RTL. Most of this (query priority, userEvent vs fireEvent, findBy vs waitFor) is standard RTL knowledge the AI already has — the unique value here is the PatternFly wiki conventions (test() vs it() nesting, mock child components, snapshot policy, toHaveClass for CSS). Could those stand alone at ~80-100 lines with the RTL reference material moved to a reference.md?

name: pf-library-test-writer
description: Write unit tests for PatternFly ecosystem components following official testing standards
---

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How does someone know when to use this vs. unit-test-generator? A one-liner in the description like "for contributors to PatternFly libraries, not consumers" would help.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d38059a7-4b32-4be7-9dfd-bf89fcd31f15

📥 Commits

Reviewing files that changed from the base of the PR and between 901f0c8 and 2797ad9.

📒 Files selected for processing (1)
  • plugins/pf-react/skills/pf-library-test-writer/SKILL.md
✅ Files skipped from review due to trivial changes (1)
  • plugins/pf-react/skills/pf-library-test-writer/SKILL.md

📝 Walkthrough

Walkthrough

Added a new documented skill, pf-react:pf-library-test-writer, and referenced it in plugins/pf-react/README.md. New plugins/pf-react/skills/pf-library-test-writer/SKILL.md defines PatternFly React Testing Library conventions. Review performed against CONTRIBUTING.md, CONTRIBUTING-SKILLS.md, and Anthropic's skill-creator guidance.

Changes

Cohort / File(s) Summary
README update
plugins/pf-react/README.md
Documented and referenced new pf-library-test-writer skill; added directory entry for skills/pf-library-test-writer/ and SKILL.md to the file-structure listing.
New skill documentation
plugins/pf-react/skills/pf-library-test-writer/SKILL.md
Added SKILL doc specifying test scope, per-component test file placement (ComponentName.test.tsx), Jest + RTL import scaffold, mocking patterns for child components, test nesting rules (test() at top-level, describe() only for shared setup, it() inside), snapshot constraints (no CSS checks in snapshots; use toHaveClass), and a coverage checklist (render variants, prop forwarding, children, callbacks, conditional rendering, accessibility, snapshots).
Tree / extras
plugins/pf-react/skills/..., plugins/pf-react/skills/pf-bug-triage/SKILL.md, plugins/pf-react/skills/pf-bug-triage/reference.md
README tree updated to include the new skill directory and reflects additional pf-bug-triage files in the skills listing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Guidelines referenced

  • CONTRIBUTING.md
  • CONTRIBUTING-SKILLS.md
  • Anthropic skill-creator plugin guidance

"A tiny skill blooms in docs’ light,
Tests get rules and mocks take flight.
One file per export, tidy and bright,
Snapshots trimmed, classes checked right.
🎉🧪"

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the primary change: adding a new skill for writing unit tests for PatternFly ecosystem components.
Linked Issues check ✅ Passed The PR implements the objective from issue #22 by adding a skill with comprehensive testing guidelines for PatternFly ecosystem components.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue: documentation-only additions to README and new SKILL.md file for the test-writer skill.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

Copy link
Copy Markdown

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@plugins/pf-react/README.md`:
- Around line 79-82: The unlabeled fenced code block containing the file-tree in
README.md should be updated to include a language identifier (e.g., use ```text)
so markdownlint rule MD040 is satisfied; locate the file-tree block in the
pf-react README.md (the block showing the pf-react/ directory structure) and
change the opening fence from ``` to ```text (or another appropriate language)
and save.

In `@plugins/pf-react/skills/pf-library-test-writer/SKILL.md`:
- Around line 32-38: Add a language tag to the fenced code block that lists the
Button files so markdownlint MD040 is satisfied; update the block that starts
with "Button/" to use a language identifier such as ```text (e.g., replace ```
with ```text) so the block remains the same content but has a language
specified.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 18a57271-32bf-4d08-9ac9-5453ffc937c1

📥 Commits

Reviewing files that changed from the base of the PR and between 0e20625 and 8360c57.

📒 Files selected for processing (2)
  • plugins/pf-react/README.md
  • plugins/pf-react/skills/pf-library-test-writer/SKILL.md

Comment on lines 79 to 82
│ ├── unit-test-generator/
│ │ └── SKILL.md
│ └── pf-unit-test-generator/
│ └── pf-library-test-writer/
│ └── SKILL.md
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add a language identifier to the file-tree fenced block (MD040).

The file-structure code fence (opened at Line 69) is unlabeled, which triggers markdownlint.

Suggested fix
-```
+```text
 pf-react/
 ├── .claude-plugin/
 │   └── plugin.json        # Plugin manifest + MCP server config
 ...
 └── README.md
</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against the current code and only fix it if needed.

In @plugins/pf-react/README.md around lines 79 - 82, The unlabeled fenced code
block containing the file-tree in README.md should be updated to include a
language identifier (e.g., use text) so markdownlint rule MD040 is satisfied; locate the file-tree block in the pf-react README.md (the block showing the pf-react/ directory structure) and change the opening fence from to ```text
(or another appropriate language) and save.


</details>

<!-- fingerprinting:phantom:triton:hawk:7d06e245-2cfa-412e-90e5-d1f571512576 -->

<!-- This is an auto-generated comment by CodeRabbit -->

@jpuzz0
Copy link
Copy Markdown
Collaborator

jpuzz0 commented Mar 31, 2026

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown

@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.

♻️ Duplicate comments (2)
plugins/pf-react/skills/pf-library-test-writer/SKILL.md (1)

32-38: ⚠️ Potential issue | 🟡 Minor

Add language identifier to fenced code block (MD040).

The fenced code block showing the file tree is missing a language tag, triggering markdownlint MD040.

🔧 Proposed fix
-```
+```text
 Button/
 ├── Button.tsx
 ├── Button.test.tsx
 ├── ButtonVariant.tsx
 └── ButtonVariant.test.tsx
</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against the current code and only fix it if needed.

In @plugins/pf-react/skills/pf-library-test-writer/SKILL.md around lines 32 -
38, The fenced code block showing the file tree lacks a language identifier;
update the triple-backtick fence surrounding the block that contains "Button/
├── Button.tsx ..." to include a language tag (e.g., ```text) so the code block
is valid for markdownlint MD040; keep the block content unchanged and only
modify the opening fence to add the language identifier.


</details>

</blockquote></details>
<details>
<summary>plugins/pf-react/README.md (1)</summary><blockquote>

`70-70`: _⚠️ Potential issue_ | _🟡 Minor_

**Add language identifier to file tree fenced block (MD040).**

The file structure code fence is missing a language tag, triggering markdownlint MD040.




<details>
<summary>🔧 Proposed fix</summary>

```diff
-```
+```text
 pf-react/
 ├── .claude-plugin/
 │   └── plugin.json
```
</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against the current code and only fix it if needed.

In @plugins/pf-react/README.md at line 70, The README's file-tree fenced code
block is missing a language identifier which triggers markdownlint MD040; update
the fenced block in the README (the file-tree block that starts with triple
backticks) to include a language tag such as "text" (e.g., change ``` to

resolved.
🧹 Nitpick comments (1)
plugins/pf-react/skills/pf-library-test-writer/SKILL.md (1)

6-102: Consider separating RTL reference material into reference.md per Anthropic skill-creator guidelines.

Anthropic's skill-creator plugin (referenced in CONTRIBUTING-SKILLS.md) recommends progressive disclosure: keep SKILL.md under 500 lines as an overview/navigation entry point, and move detailed reference material into separate references/ files. This skill's 102 lines blend PatternFly-specific conventions (mock child components, test() vs it() nesting, snapshot policy, toHaveClass for CSS) with substantial React Testing Library reference material (query priorities, fireEvent vs userEvent, findBy vs waitFor).

The sibling skill pf-bug-triage (110 lines) follows this pattern with a companion reference.md, as do other skills in the repo (pf-token-auditor, analytics-repo-pruning). Moving general RTL best practices to a reference.md would sharpen SKILL.md to focus exclusively on PatternFly-specific requirements and your contribution's unique value, while keeping RTL fundamentals available for developers who need them.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@plugins/pf-react/skills/pf-library-test-writer/SKILL.md` around lines 6 -
102, SKILL.md currently mixes PatternFly-specific testing rules with broad React
Testing Library (RTL) reference material; split the content by creating a new
references/reference.md (or references/RTL-reference.md) and move general RTL
topics (query priorities, fireEvent vs userEvent, findBy vs waitFor, query
examples, and extensive snapshot guidance) into that file, leaving SKILL.md as a
concise PatternFly-focused overview under 500 lines that retains the coverage
checklist, mocking guidance, and PatternFly-specific conventions; update
SKILL.md to link to the new reference file and ensure headings/links mention
pf-library-test-writer and the new reference so reviewers can find the detailed
RTL guidance.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@plugins/pf-react/README.md`:
- Line 70: The README's file-tree fenced code block is missing a language
identifier which triggers markdownlint MD040; update the fenced block in the
README (the file-tree block that starts with triple backticks) to include a
language tag such as "text" (e.g., change ``` to ```text) so the code fence is
properly identified and the linter warning is resolved.

In `@plugins/pf-react/skills/pf-library-test-writer/SKILL.md`:
- Around line 32-38: The fenced code block showing the file tree lacks a
language identifier; update the triple-backtick fence surrounding the block that
contains "Button/ ├── Button.tsx ..." to include a language tag (e.g., ```text)
so the code block is valid for markdownlint MD040; keep the block content
unchanged and only modify the opening fence to add the language identifier.

---

Nitpick comments:
In `@plugins/pf-react/skills/pf-library-test-writer/SKILL.md`:
- Around line 6-102: SKILL.md currently mixes PatternFly-specific testing rules
with broad React Testing Library (RTL) reference material; split the content by
creating a new references/reference.md (or references/RTL-reference.md) and move
general RTL topics (query priorities, fireEvent vs userEvent, findBy vs waitFor,
query examples, and extensive snapshot guidance) into that file, leaving
SKILL.md as a concise PatternFly-focused overview under 500 lines that retains
the coverage checklist, mocking guidance, and PatternFly-specific conventions;
update SKILL.md to link to the new reference file and ensure headings/links
mention pf-library-test-writer and the new reference so reviewers can find the
detailed RTL guidance.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 017bc153-0fa5-4d06-91f5-b27d0994171e

📥 Commits

Reviewing files that changed from the base of the PR and between 37aa4b4 and 947386f.

📒 Files selected for processing (2)
  • plugins/pf-react/README.md
  • plugins/pf-react/skills/pf-library-test-writer/SKILL.md

description: Write unit tests for contributors to PatternFly libraries (patternfly-react, patternfly-chatbot, etc.), not for consumers of PatternFly components. Use `unit-test-generator` for consumer application tests instead.
---

Write unit tests for components and features within the PatternFly ecosystem (patternfly-react, patternfly-chatbot, patternfly-virtual-assistant, and other JS/TS-based PatternFly libraries). All tests must strictly follow the [official PatternFly testing guidelines](https://github.com/patternfly/patternfly-react/wiki/React-Testing-Library-Basics,-Best-Practices,-and-Guidelines).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

"All tests must strictly follow" the wiki link creates a tension - if the wiki changes and diverges from the rules here, the AI has two conflicting sources of truth. Since the skill already captures the key rules inline, could this just reference the wiki as background context rather than the authoritative source?

## How to Write Tests

1. Read the component source to understand its props, children, and behavior.
2. If the PatternFly MCP server is available, use `usePatternFlyDocs` to check the component's props schema, variants, and accessibility requirements.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is prescribing implementation - the AI already knows how to use available MCP tools. Per CONTRIBUTING-SKILLS.md: "Describe outcomes, not implementation."


## Mocking Child Components

Default to **mocking child components** for unit testing prop-passing behavior:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is the key differentiator from pf-unit-test-generator (which says "never mock child components"), but it's buried mid-file. Since this is the main reason someone would pick one skill over the other, would it help to surface this more prominently - maybe in the opening paragraph?

## Test File Structure

```typescript
import React from 'react';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: import React from 'react' isn't needed with modern JSX transform (React 17+) and PF repos don't include it.

@jpuzz0 jpuzz0 merged commit 61c5f1b into patternfly:main Apr 2, 2026
1 check passed
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.

Add a skill for writing unit tests for new components/features which follow our PF guidelines

2 participants