Skip to content

CONSOLE-5229: Enable RTL ESLint rules in Knative tests by removing file-level no-container / no-node-access suppressions#16405

Open
cajieh wants to merge 1 commit intoopenshift:mainfrom
cajieh:enable-rtl-eslint-rules-knative-tests
Open

CONSOLE-5229: Enable RTL ESLint rules in Knative tests by removing file-level no-container / no-node-access suppressions#16405
cajieh wants to merge 1 commit intoopenshift:mainfrom
cajieh:enable-rtl-eslint-rules-knative-tests

Conversation

@cajieh
Copy link
Copy Markdown
Contributor

@cajieh cajieh commented May 6, 2026

CONSOLE-5229: Enable RTL ESLint rules in Knative tests by removing file-level no-container / no-node-access suppressions

Analysis / Root cause:
Tech-Debt

Solution description:
Cleanup

Screenshots / screen recording:
N/A

Test setup:
Run yarn test <Knative tests>

Test cases:
N/A

Browser conformance:

  • Chrome
  • Firefox
  • Safari (or Epiphany on Linux)

Additional info:

Reviewers and assignees:
/assign @vikram-raj

Summary by CodeRabbit

  • Tests

    • Refactored test suite to use React Testing Library best practices, replacing DOM container queries with accessible queries and data-test attributes for more reliable testing.
    • Improved mock implementations for improved test clarity and maintainability across Knative plugin components.
  • Chores

    • Enhanced test infrastructure with shared RTL stub components for consistent test setup.

@openshift-ci-robot
Copy link
Copy Markdown
Contributor

openshift-ci-robot commented May 6, 2026

@cajieh: This pull request references CONSOLE-5229 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

CONSOLE-5229: Enable RTL ESLint rules in Knative tests by removing file-level no-container / no-node-access suppressions

Analysis / Root cause:
Tech-Debt

Solution description:
Cleanup

Screenshots / screen recording:
N/A

Test setup:
Run yarn test <Knative tests>

Test cases:
N/A

Browser conformance:

  • Chrome
  • Firefox
  • Safari (or Epiphany on Linux)

Additional info:

Reviewers and assignees:

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 openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label May 6, 2026
@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 6, 2026
@openshift-ci openshift-ci Bot requested review from sg00dwin and spadgett May 6, 2026 18:20
@openshift-ci openshift-ci Bot added the component/knative Related to knative-plugin label May 6, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 6, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cajieh

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

The pull request process is described here

Details 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 openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 6, 2026
@cajieh
Copy link
Copy Markdown
Contributor Author

cajieh commented May 6, 2026

/retest

@cajieh cajieh force-pushed the enable-rtl-eslint-rules-knative-tests branch 3 times, most recently from 3a3f172 to 1e11c38 Compare May 6, 2026 21:29
@cajieh
Copy link
Copy Markdown
Contributor Author

cajieh commented May 7, 2026

/test all

@cajieh cajieh force-pushed the enable-rtl-eslint-rules-knative-tests branch 3 times, most recently from 7d7fd65 to 22ef89d Compare May 7, 2026 15:24
@cajieh
Copy link
Copy Markdown
Contributor Author

cajieh commented May 7, 2026

/test images

@cajieh
Copy link
Copy Markdown
Contributor Author

cajieh commented May 7, 2026

/test e2e-gcp-console

@cajieh cajieh changed the title [WIP] CONSOLE-5229: Enable RTL ESLint rules in Knative tests by removing file-level no-container / no-node-access suppressions CONSOLE-5229: Enable RTL ESLint rules in Knative tests by removing file-level no-container / no-node-access suppressions May 7, 2026
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 7, 2026
@cajieh cajieh force-pushed the enable-rtl-eslint-rules-knative-tests branch from 22ef89d to 158e48c Compare May 7, 2026 20:20
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

📝 Walkthrough

Walkthrough

This pull request systematically refactors test infrastructure and test files in the Knative plugin to adopt React Testing Library best practices. A new rtl-stub-components module is introduced to provide reusable, typed stub components for testing. The react-i18next mock is enriched with proper TypeScript types and expanded functionality. Throughout test files, mocks are migrated from string placeholders to functional React components with data-test attributes. Test assertions are updated from container-based DOM queries to React Testing Library screen queries, replacing querySelector patterns with getByTestId, getByRole, and visibility checks.

🚥 Pre-merge checks | ✅ 11 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Test Structure And Quality ❓ Inconclusive Custom check is designed for Ginkgo (Go) test code, but PR contains only Jest (JS/TS) React tests. Framework mismatch makes check inapplicable. Check is not applicable to this PR's codebase. For proper assessment: (1) confirm if custom check was intended for this JS/TS project, or (2) apply JS/TS-specific test quality check instead.
✅ Passed checks (11 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary objective: enabling RTL ESLint rules by removing file-level suppressions, tied to CONSOLE-5229. It's specific and directly describes the core change.
Description check ✅ Passed The description follows the template structure with Analysis/Root cause (Tech-Debt) and Solution description (Cleanup). Test setup and assignment are provided, though some sections are minimal or N/A.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed Custom check for Ginkgo tests not applicable. PR modifies only Jest tests (JavaScript/TypeScript), not Go tests. All test names are static and deterministic.
Microshift Test Compatibility ✅ Passed This PR contains only React Testing Library unit tests (TypeScript/JavaScript), not Ginkgo e2e tests. The MicroShift compatibility check applies only to Go Ginkgo tests. Not applicable to this PR.
Single Node Openshift (Sno) Test Compatibility ✅ Passed Custom check not applicable. PR contains only Jest/RTL frontend unit tests (JavaScript/TypeScript), not Ginkgo e2e tests. No cluster topology or multi-node assumptions present.
Topology-Aware Scheduling Compatibility ✅ Passed PR scope is frontend test refactoring only. No deployment manifests, operator code, controllers, or scheduling constraints are added or modified. Check is not applicable.
Ote Binary Stdout Contract ✅ Passed PR modifies only JavaScript/TypeScript test files (knative-plugin frontend). OTE Binary Stdout Contract applies exclusively to Go binaries with Ginkgo/klog. Not applicable.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo e2e tests added in this PR. Only frontend Jest unit test refactoring. Custom check not applicable.

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

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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

Copy link
Copy Markdown
Contributor

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

🧹 Nitpick comments (3)
frontend/packages/knative-plugin/src/components/overview/serving-list/__tests__/ServingListPage.spec.tsx (1)

52-56: ⚡ Quick win

Remove redundant duplicate render test.

Line 52–56 repeats the exact same assertions as Line 46–50, so it doesn’t increase confidence and just adds maintenance overhead.

Proposed cleanup
-  it('should render the main components without errors', () => {
-    render(<ServingListPage />);
-    expect(screen.getByTestId('mock-NamespaceBar')).toBeVisible();
-    expect(screen.getByTestId('mock-MultiTabListPage')).toBeVisible();
-  });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@frontend/packages/knative-plugin/src/components/overview/serving-list/__tests__/ServingListPage.spec.tsx`
around lines 52 - 56, Remove the duplicated test block that renders
ServingListPage and asserts visibility of 'mock-NamespaceBar' and
'mock-MultiTabListPage' — specifically delete the redundant it(...) test that
calls render(<ServingListPage />) and the two expect(...) assertions so only the
original test remains; look for the duplicated "should render the main
components without errors" it block referencing ServingListPage and the test ids
'mock-NamespaceBar' and 'mock-MultiTabListPage' and remove the second
occurrence.
frontend/packages/knative-plugin/src/components/sink-source/__tests__/SinkSourceModal.spec.tsx (1)

23-27: 💤 Low value

Form mock spreads all PF-specific props onto a native <form> element.

PF's Form accepts props like isWidthLimited, isHorizontal, etc. that are not valid HTML attributes. Spreading the entire ...props remainder onto <form> will cause React to emit "Unknown prop" DOM warnings during the test run. These don't fail tests on their own, but they pollute the output and can mask real warnings. Filtering known-non-DOM props, or only forwarding id, would keep the test output clean.

🧹 Proposed tidy-up
-  Form: jest.fn(({ children, ...props }) => (
-    <form data-test={props.id} {...props}>
-      {children}
-    </form>
-  )),
+  Form: jest.fn(({ children, id, ...rest }: any) => (
+    <form data-test={id} id={id}>
+      {children}
+    </form>
+  )),

The same concern applies identically to the TrafficSplittingModal.spec.tsx Form mock (line 26-30).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@frontend/packages/knative-plugin/src/components/sink-source/__tests__/SinkSourceModal.spec.tsx`
around lines 23 - 27, The Form mock in SinkSourceModal.spec.tsx currently
spreads all PF-specific props onto a native <form>, causing React "Unknown prop"
warnings; update the jest.fn mock for Form (and the analogous Form mock in
TrafficSplittingModal.spec.tsx) to avoid spreading unknown props — only forward
safe DOM attributes like id (e.g., use the id prop and children) or explicitly
filter out PF-only props such as isWidthLimited/isHorizontal before passing
props to the <form>, so tests no longer emit DOM unknown-prop warnings.
frontend/packages/knative-plugin/src/components/sink-pubsub/__tests__/SinkPubsub.spec.tsx (1)

75-94: ⚡ Quick win

Three of four test cases are functional duplicates — the suite provides no additional coverage.

  • "should render the component with Formik" (lines 75–78) and "should render properly for Subscription resource type" (lines 80–83) are byte-for-byte identical: same formProps, same single assertion.
  • "should handle different source objects" (lines 91–94) also renders with formProps (the Subscription fixture) without supplying any alternate source, making it identical to tests 1 and 2.

The only genuinely distinct case is the Trigger test (lines 85–89).

♻️ Proposed cleanup
-  it('should render the component with Formik', () => {
-    render(<SinkPubsub {...formProps} />);
-    expect(screen.getByTestId('mock-Formik')).toBeVisible();
-  });
-
-  it('should render properly for Subscription resource type', () => {
-    render(<SinkPubsub {...formProps} />);
-    expect(screen.getByTestId('mock-Formik')).toBeVisible();
-  });
+  it('should render Formik wrapper for Subscription resource type', () => {
+    render(<SinkPubsub {...formProps} />);
+    expect(screen.getByTestId('mock-Formik')).toBeVisible();
+  });

   it('should render properly for Trigger resource type', () => {
     const triggerProps = { source: EventTriggerObj, resourceType: 'Trigger' };
     render(<SinkPubsub {...triggerProps} />);
     expect(screen.getByTestId('mock-Formik')).toBeVisible();
   });

-  it('should handle different source objects', () => {
-    render(<SinkPubsub {...formProps} />);
-    expect(screen.getByTestId('mock-Formik')).toBeVisible();
-  });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@frontend/packages/knative-plugin/src/components/sink-pubsub/__tests__/SinkPubsub.spec.tsx`
around lines 75 - 94, Tests contain three identical renders using the same
formProps (Subscription) which is redundant; keep one Subscription render test
and the distinct Trigger test (using EventTriggerObj and resourceType:
'Trigger'), and either remove the other duplicate tests ("should render the
component with Formik" and one of the Subscription tests) or change the "should
handle different source objects" test to actually supply a different source
(e.g., a different fixture than formProps or a null/edge-case source) and assert
expected behavior; update references to SinkPubsub, formProps, EventTriggerObj,
and resourceType in the affected test cases accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@frontend/packages/knative-plugin/src/components/add/__tests__/EventSink.spec.tsx`:
- Around line 18-29: The Formik mock is leaking real Formik hooks by spreading
...actual, which lets components like EventSinkSection (used inside
EventSinkForm) call useFormikContext() against no provider and fail; fix by
removing the ...actual spread from the jest.mock so the module is fully mocked
(or replace the mock with the existing mockFormikRenderer test utility from
unit-test-utils to render the component inside a real Formik provider), ensuring
Formik is either fully stubbed or the component is wrapped with a proper Formik
context so useFormikContext/Field/useField don't run against undefined.

In
`@frontend/packages/knative-plugin/src/components/overview/__tests__/RevisionsOverviewList.spec.tsx`:
- Around line 93-100: The test for RevisionsOverviewList currently only asserts
visibility of the traffic split button; update the assertion to check the
disabled state as the test name promises by replacing or augmenting the existing
expect(screen.getByTestId('mock-Button')).toBeVisible() with
expect(screen.getByTestId('mock-Button')).toBeDisabled() (or add that
assertion), so the "no revisions" scenario verifies the button is disabled;
target the getByTestId('mock-Button') call in RevisionsOverviewList.spec.tsx.

In
`@frontend/packages/knative-plugin/src/components/overview/__tests__/RoutesOverviewList.spec.tsx`:
- Around line 55-63: The test "should render multiple RoutesOverviewListItem
when multiple routes" only asserts a single visible item; update the test in
RoutesOverviewList.spec.tsx to assert multiplicity by querying all items
produced by <RoutesOverviewList> (use the test id 'mock-RoutesOverviewListItem')
and expecting length to equal the number of routes in
MockKnativeResources.ksroutes.data (or at least >1); ensure you use
screen.getAllByTestId('mock-RoutesOverviewListItem') and assert the resulting
array length matches/mock data count rather than a single getByTestId visibility
check.

In
`@frontend/packages/knative-plugin/src/components/pub-sub/details/__test__/TriggerDetails.spec.tsx`:
- Around line 60-64: The test for TriggerDetails uses getByTestId which throws
if the element is missing, and currently asserts visibility even though the spec
says FilterTable should not render; update the negative-case assertion by using
screen.queryByTestId('mock-FilterTable') on the TriggerDetails render (with
triggerDataClone where spec.filter is omitted) and assert that it is null or not
present (e.g., expect(...).toBeNull() or expect(...).not.toBeInTheDocument()) so
the test correctly verifies FilterTable is not rendered.

---

Nitpick comments:
In
`@frontend/packages/knative-plugin/src/components/overview/serving-list/__tests__/ServingListPage.spec.tsx`:
- Around line 52-56: Remove the duplicated test block that renders
ServingListPage and asserts visibility of 'mock-NamespaceBar' and
'mock-MultiTabListPage' — specifically delete the redundant it(...) test that
calls render(<ServingListPage />) and the two expect(...) assertions so only the
original test remains; look for the duplicated "should render the main
components without errors" it block referencing ServingListPage and the test ids
'mock-NamespaceBar' and 'mock-MultiTabListPage' and remove the second
occurrence.

In
`@frontend/packages/knative-plugin/src/components/sink-pubsub/__tests__/SinkPubsub.spec.tsx`:
- Around line 75-94: Tests contain three identical renders using the same
formProps (Subscription) which is redundant; keep one Subscription render test
and the distinct Trigger test (using EventTriggerObj and resourceType:
'Trigger'), and either remove the other duplicate tests ("should render the
component with Formik" and one of the Subscription tests) or change the "should
handle different source objects" test to actually supply a different source
(e.g., a different fixture than formProps or a null/edge-case source) and assert
expected behavior; update references to SinkPubsub, formProps, EventTriggerObj,
and resourceType in the affected test cases accordingly.

In
`@frontend/packages/knative-plugin/src/components/sink-source/__tests__/SinkSourceModal.spec.tsx`:
- Around line 23-27: The Form mock in SinkSourceModal.spec.tsx currently spreads
all PF-specific props onto a native <form>, causing React "Unknown prop"
warnings; update the jest.fn mock for Form (and the analogous Form mock in
TrafficSplittingModal.spec.tsx) to avoid spreading unknown props — only forward
safe DOM attributes like id (e.g., use the id prop and children) or explicitly
filter out PF-only props such as isWidthLimited/isHorizontal before passing
props to the <form>, so tests no longer emit DOM unknown-prop warnings.
🪄 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: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: bd9e1994-1fc0-4861-95d5-72b233cb22a9

📥 Commits

Reviewing files that changed from the base of the PR and between 1b45874 and 158e48c.

📒 Files selected for processing (50)
  • frontend/__mocks__/react-i18next.ts
  • frontend/packages/knative-plugin/src/__tests__/rtl-stub-components.tsx
  • frontend/packages/knative-plugin/src/components/add/__tests__/EventSink.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/__tests__/EventSinkAlert.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/__tests__/EventSinkForm.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/__tests__/EventSinkPage.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/__tests__/EventSource.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/__tests__/EventSourceAlert.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/__tests__/EventSourceForm.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/event-sinks/__tests__/EventSinkSection.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/event-sinks/__tests__/KafkaSinkSection.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/event-sources/__tests__/ApiServerSection.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/event-sources/__tests__/ContainerSourceSection.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/event-sources/__tests__/EventSourceSection.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/event-sources/__tests__/KafkaSourceNetSection.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/event-sources/__tests__/KafkaSourceSection.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/event-sources/__tests__/SinkBindingSection.spec.tsx
  • frontend/packages/knative-plugin/src/components/add/event-sources/form-fields/__tests__/SinkResources.spec.tsx
  • frontend/packages/knative-plugin/src/components/eventing/__tests__/EventingListPage.spec.tsx
  • frontend/packages/knative-plugin/src/components/knatify/__tests__/CreateKnatifyPage.spec.tsx
  • frontend/packages/knative-plugin/src/components/knatify/__tests__/KnatifyForm.spec.tsx
  • frontend/packages/knative-plugin/src/components/overview/RevisionsOverviewListItem.tsx
  • frontend/packages/knative-plugin/src/components/overview/__tests__/ConfigurationsOverviewList.spec.tsx
  • frontend/packages/knative-plugin/src/components/overview/__tests__/ConfigurationsOverviewListItem.spec.tsx
  • frontend/packages/knative-plugin/src/components/overview/__tests__/DeploymentOverviewList.spec.tsx
  • frontend/packages/knative-plugin/src/components/overview/__tests__/EventPubSubResources.spec.tsx
  • frontend/packages/knative-plugin/src/components/overview/__tests__/EventSourceOwnedList.spec.tsx
  • frontend/packages/knative-plugin/src/components/overview/__tests__/EventSourceResources.spec.tsx
  • frontend/packages/knative-plugin/src/components/overview/__tests__/KSRouteSplitListItem.spec.tsx
  • frontend/packages/knative-plugin/src/components/overview/__tests__/KSRoutesOverviewListItem.spec.tsx
  • frontend/packages/knative-plugin/src/components/overview/__tests__/RevisionsOverviewList.spec.tsx
  • frontend/packages/knative-plugin/src/components/overview/__tests__/RevisionsOverviewListItem.spec.tsx
  • frontend/packages/knative-plugin/src/components/overview/__tests__/RoutesOverviewList.spec.tsx
  • frontend/packages/knative-plugin/src/components/overview/__tests__/RoutesOverviewListItem.spec.tsx
  • frontend/packages/knative-plugin/src/components/overview/serving-list/__tests__/ServingListPage.spec.tsx
  • frontend/packages/knative-plugin/src/components/pub-sub/details/__test__/DynamicResourceLink.spec.tsx
  • frontend/packages/knative-plugin/src/components/pub-sub/details/__test__/SubscriptionDetails.spec.tsx
  • frontend/packages/knative-plugin/src/components/pub-sub/details/__test__/TriggerDetails.spec.tsx
  • frontend/packages/knative-plugin/src/components/revisions/__tests__/RevisionRow.spec.tsx
  • frontend/packages/knative-plugin/src/components/routes/__tests__/RouteRow.spec.tsx
  • frontend/packages/knative-plugin/src/components/services/__tests__/ServiceRow.spec.tsx
  • frontend/packages/knative-plugin/src/components/sink-pubsub/__tests__/SinkPubsub.spec.tsx
  • frontend/packages/knative-plugin/src/components/sink-pubsub/__tests__/SinkPubsubModal.spec.tsx
  • frontend/packages/knative-plugin/src/components/sink-source/__tests__/SinkSource.spec.tsx
  • frontend/packages/knative-plugin/src/components/sink-source/__tests__/SinkSourceModal.spec.tsx
  • frontend/packages/knative-plugin/src/components/sink-uri/__tests__/SinkUri.spec.tsx
  • frontend/packages/knative-plugin/src/components/sink-uri/__tests__/SinkUriModal.spec.tsx
  • frontend/packages/knative-plugin/src/components/traffic-splitting/__tests__/TrafficSplittingFields.spec.tsx
  • frontend/packages/knative-plugin/src/components/traffic-splitting/__tests__/TrafficSplittingModal.spec.tsx
  • frontend/packages/knative-plugin/src/topology/sidebar/__tests__/KnativeOverviewSections.spec.tsx
📜 Review details
🔇 Additional comments (40)
frontend/packages/knative-plugin/src/components/overview/serving-list/__tests__/ServingListPage.spec.tsx (1)

1-1: Good RTL migration in this spec.

Switching to screen-based assertions and component mocks with stable test hooks is clean and aligned with the lint-rule enablement goal.

Also applies to: 11-16, 47-49

frontend/packages/knative-plugin/src/components/eventing/__tests__/EventingListPage.spec.tsx (2)

1-1: Nice update to RTL-compliant test patterns.

Using render + screen and functional JSX mocks here is a solid improvement and keeps the test intent clear.

Also applies to: 12-20, 57-61


63-140: Coverage depth is solid for this page.

Good to see the props contract assertion and namespace URL behavior checks retained alongside the RTL query migration.

frontend/packages/knative-plugin/src/components/overview/RevisionsOverviewListItem.tsx (1)

47-47: Good scoped test hook on the deployment branch.

This keeps RTL selectors deterministic without changing the existing conditional render behavior.

frontend/packages/knative-plugin/src/components/services/__tests__/ServiceRow.spec.tsx (1)

10-14: RTL migration is clean and consistent.

Using DOM-backed mocks plus screen-based assertions removes container/node access and keeps the tests stable.

Also applies to: 45-49, 72-145

frontend/packages/knative-plugin/src/__tests__/rtl-stub-components.tsx (1)

7-24: Nice extraction of reusable RTL stubs.

This improves test maintainability and standardizes mocks across knative-plugin suites.

frontend/packages/knative-plugin/src/components/pub-sub/details/__test__/DynamicResourceLink.spec.tsx (1)

1-9: Good modernization of the DynamicResourceLink test.

The shared stub + screen assertions are straightforward and aligned with the lint-rule objective.

Also applies to: 25-40

frontend/packages/knative-plugin/src/components/add/event-sources/form-fields/__tests__/SinkResources.spec.tsx (1)

17-20: Solid switch to shared text stubs and screen queries.

This keeps the tests lint-compliant and easier to reason about.

Also applies to: 50-57

frontend/packages/knative-plugin/src/components/add/event-sinks/__tests__/EventSinkSection.spec.tsx (1)

10-33: Nice cleanup of test doubles and assertions.

The deterministic mock text strategy makes the visibility/presence checks much clearer.

Also applies to: 98-118

frontend/packages/knative-plugin/src/components/add/event-sources/__tests__/EventSourceSection.spec.tsx (1)

1-22: Looks good—consistent RTL query migration here as well.

Assertions are now aligned with user-visible output rather than DOM internals.

Also applies to: 42-44

frontend/packages/knative-plugin/src/components/revisions/__tests__/RevisionRow.spec.tsx (1)

10-20: Good RTL-first refactor for RevisionRow tests.

The shift to shared stubs and screen assertions is consistent and maintainable.

Also applies to: 60-104

frontend/packages/knative-plugin/src/components/knatify/__tests__/CreateKnatifyPage.spec.tsx (1)

71-71: LGTM — clean migration to the centralized react-i18next mock.

frontend/packages/knative-plugin/src/components/add/__tests__/EventSourceAlert.spec.tsx (1)

1-35: LGTM — well-structured RTL migration.

Correct use of queryByText (absence assertion) vs. getByText (presence + toBeVisible()), and returning a plain string from the Alert mock is valid React 16+.

frontend/packages/knative-plugin/src/components/add/event-sources/__tests__/KafkaSourceNetSection.spec.tsx (1)

36-41: LGTM — count assertion is precise and correctly cross-checked against the formik mock.

2 SASL + 3 TLS = 5 SecretKeySelector instances. Using toHaveLength(5) is more declarative than the > 0 pattern seen elsewhere and will catch regressions accurately.

frontend/packages/knative-plugin/src/components/add/event-sources/__tests__/SinkBindingSection.spec.tsx (1)

50-63: LGTM — correct use of RTL queries and precise count assertions.

frontend/packages/knative-plugin/src/components/knatify/__tests__/KnatifyForm.spec.tsx (1)

38-39: LGTM — FlexForm/FormBody as transparent pass-throughs is the right call here.

Making layout wrappers transparent ensures the stub text from each section actually renders and can be asserted on, without needing to know the internal DOM structure of those layout components.

frontend/packages/knative-plugin/src/components/add/event-sources/__tests__/ApiServerSection.spec.tsx (1)

50-61: LGTM — mixing real translation-key assertions with stub-based component assertions is a valid pattern here.

screen.getByText('Resource') relies on the i18next mock stripping the namespace prefix (knative~Resource'Resource'), which is the documented behavior. This is an intentional choice that ties the test to translation key stability — acceptable and more meaningful than purely mock-based assertions for user-visible labels.

frontend/packages/knative-plugin/src/components/routes/__tests__/RouteRow.spec.tsx (1)

18-19: rtl-stub-components module is complete and correctly exported.

Verification confirms frontend/packages/knative-plugin/src/__tests__/rtl-stub-components.tsx exports all required symbols:

  • knativeInternalUtilsStubs.ResourceLink — properly typed and renders expected mock
  • knativeInternalUtilsStubs.SidebarSectionHeading — also present
  • createKnativeTextStub — function implemented correctly

All usages in test files (e.g., RouteRow.spec.tsx) match the actual module exports. No missing or malformed exports.

frontend/__mocks__/react-i18next.ts (1)

53-54: ⚡ Quick win

Trans regex limitation verified, but not a concern for knative-plugin.

The regex /<\d+><\/\d+>/ does match only empty adjacent tags (<0></0>), and react-i18next's documented standard is the numbered-tag convention with content: defaults="hello <0>world</0>". However, verification shows knative-plugin uses no Trans component with defaults at all—only the useTranslation() hook. The codebase-wide pattern consistently uses the empty-tag form (<0></0> paired with components={[children]}), which the mock correctly handles. The documented scope of the mock ("components-array-only pattern") aligns with actual usage.

frontend/packages/knative-plugin/src/components/add/event-sinks/__tests__/KafkaSinkSection.spec.tsx (1)

40-59: Nice RTL migration here.

The updated screen-based assertions are clear and aligned with user-visible behavior for title/field presence checks.

frontend/packages/knative-plugin/src/components/add/event-sources/__tests__/ContainerSourceSection.spec.tsx (1)

55-74: Good accessibility-oriented assertions.

Using getByRole('textbox', { name: ... }) and visible text checks improves test intent and resilience.

frontend/packages/knative-plugin/src/components/add/event-sources/__tests__/KafkaSourceSection.spec.tsx (1)

67-110: Solid conversion to RTL-first assertions.

The required-field checks via accessible queries keep these tests closer to real user interaction semantics.

frontend/packages/knative-plugin/src/components/add/__tests__/EventSource.spec.tsx (1)

46-83: Good behavioral assertions for context-source branching.

The heading/button/target checks clearly validate the two sink initialization paths.

frontend/packages/knative-plugin/src/components/pub-sub/details/__test__/SubscriptionDetails.spec.tsx (1)

35-49: Looks good.

This keeps the detail tests RTL-friendly while preserving both presence and absence scenarios.

frontend/packages/knative-plugin/src/components/overview/__tests__/EventSourceResources.spec.tsx (1)

64-130: Strong scenario coverage retained after RTL cleanup.

The sink target matrix remains well-tested while avoiding container/node access patterns.

frontend/packages/knative-plugin/src/topology/sidebar/__tests__/KnativeOverviewSections.spec.tsx (1)

74-75: LGTM on the i18n mock simplification.

Using the shared react-i18next mock keeps this test aligned with the suite-wide pattern.

frontend/packages/knative-plugin/src/components/traffic-splitting/__tests__/TrafficSplittingFields.spec.tsx (1)

19-19: Good simplification of i18n test setup.

Using the shared react-i18next mock here keeps this spec consistent with the repo-wide RTL cleanup and removes duplicate mock logic.

frontend/packages/knative-plugin/src/components/sink-uri/__tests__/SinkUriModal.spec.tsx (1)

36-36: Nice cleanup for translation mocking.

Switching to the shared module mock keeps this test lean and aligned with the broader Knative test refactor.

frontend/packages/knative-plugin/src/components/sink-uri/__tests__/SinkUri.spec.tsx (1)

15-15: Looks good.

This keeps i18n mocking centralized and avoids test-local mock drift.

frontend/packages/knative-plugin/src/components/sink-pubsub/__tests__/SinkPubsubModal.spec.tsx (1)

26-27: Good balance of shared mock reuse and local override.

Reusing the common i18n mock while overriding Trans for this spec keeps behavior explicit without reintroducing boilerplate.

frontend/packages/knative-plugin/src/components/overview/__tests__/ConfigurationsOverviewList.spec.tsx (1)

7-8: Great RTL-style assertion update.

Using a renderable stub and screen-based assertions is cleaner and consistent with the lint-rule enablement goal.

Also applies to: 17-19

frontend/packages/knative-plugin/src/components/add/__tests__/EventSinkAlert.spec.tsx (1)

1-1: Strong cleanup of test assertions.

The move from container-driven checks to screen queries makes the intent clearer and matches the RTL linting direction for this PR.

Also applies to: 5-5, 10-12, 15-17, 20-28

frontend/packages/knative-plugin/src/components/overview/__tests__/DeploymentOverviewList.spec.tsx (1)

6-11: Nice reuse of shared stub components.

Pulling in knativeInternalUtilsStubs and asserting via screen improves maintainability and keeps this spec aligned with the rest of the suite.

Also applies to: 54-56

frontend/packages/knative-plugin/src/components/sink-source/__tests__/SinkSource.spec.tsx (1)

18-18: Good tightening of the Formik contract assertion.

Checking children as a function is a stronger, less brittle validation than a generic presence check.

Also applies to: 62-65

frontend/packages/knative-plugin/src/components/traffic-splitting/__tests__/TrafficSplittingModal.spec.tsx (2)

26-30: Same non-DOM prop spread concern as SinkSourceModal.spec.tsx — see that comment for the suggested fix.


42-80: RTL migration is well-executed — LGTM.

Bare jest.mock('react-i18next') (no factory) is the cleanest pattern in the PR, and the role-based button queries ({ name: 'Save' } / { name: 'Cancel' }) are properly user-facing rather than relying on translation keys.

frontend/packages/knative-plugin/src/components/overview/__tests__/EventSourceOwnedList.spec.tsx (1)

1-26: Clean RTL migration — LGTM.

The switch to screen.getByTestId against the shared knativeInternalUtilsStubs is consistent with the pattern used across the PR.

frontend/packages/knative-plugin/src/components/add/__tests__/EventSinkForm.spec.tsx (1)

1-52: Clean stub-component migration — LGTM.

The createKnativeTextStub pattern is applied consistently for SyncedEditorField, FormFooter, CodeEditorField, and EventSinkSection, and the bare jest.mock('react-i18next') aligns with the project-wide auto-mock.

frontend/packages/knative-plugin/src/components/add/__tests__/EventSinkPage.spec.tsx (1)

1-141: Solid RTL migration — LGTM.

String-returning mock components ('mock-LoadingBox', 'mock-EventSink', 'mock-EventSinkAlert') pair cleanly with screen.getByText/screen.queryByText, and the symmetric positive/negative assertions in each test case give good signal.

frontend/packages/knative-plugin/src/components/overview/__tests__/RevisionsOverviewListItem.spec.tsx (1)

110-113: ⚡ Quick win

The toHaveAttribute('kind', 'RevisionModel') assertion is correctly implemented. The knativeInternalUtilsStubs.ResourceLink stub forwards all props as DOM attributes via the spread operator ({...(props as HTMLAttributes<HTMLSpanElement>)}), which means the kind prop will be properly set on the rendered element. RTL is also correctly configured in frontend/setup-tests.js to use data-test as the testIdAttribute, matching the stub's selector. The test assertion will pass and correctly validate the kind attribute.

Comment thread frontend/packages/knative-plugin/src/components/add/__tests__/EventSink.spec.tsx Outdated
Comment on lines 93 to 100
it('should show info if no Revisions present, link for all revisions should not be shown and traffic split button should be disabled', () => {
const { container } = render(
render(
<RevisionsOverviewList revisions={[]} service={MockKnativeResources.revisions.data[0]} />,
);
expect(container.querySelector('Link')).not.toBeInTheDocument();
expect(screen.queryByTestId('mock-Link')).not.toBeInTheDocument();
expect(screen.getByText(/No Revisions found for this resource/)).toBeInTheDocument();
const button = container.querySelector('Button');
expect(button).toBeInTheDocument();
expect(screen.getByTestId('mock-Button')).toBeVisible();
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Disabled-state behavior is unasserted in the “no revisions” scenario.

The test name says the traffic split button should be disabled, but it currently checks only visibility.

Suggested fix
   it('should show info if no Revisions present, link for all revisions should not be shown and traffic split button should be disabled', () => {
     render(
       <RevisionsOverviewList revisions={[]} service={MockKnativeResources.revisions.data[0]} />,
     );
     expect(screen.queryByTestId('mock-Link')).not.toBeInTheDocument();
     expect(screen.getByText(/No Revisions found for this resource/)).toBeInTheDocument();
-    expect(screen.getByTestId('mock-Button')).toBeVisible();
+    expect(screen.getByTestId('mock-Button')).toBeDisabled();
   });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('should show info if no Revisions present, link for all revisions should not be shown and traffic split button should be disabled', () => {
const { container } = render(
render(
<RevisionsOverviewList revisions={[]} service={MockKnativeResources.revisions.data[0]} />,
);
expect(container.querySelector('Link')).not.toBeInTheDocument();
expect(screen.queryByTestId('mock-Link')).not.toBeInTheDocument();
expect(screen.getByText(/No Revisions found for this resource/)).toBeInTheDocument();
const button = container.querySelector('Button');
expect(button).toBeInTheDocument();
expect(screen.getByTestId('mock-Button')).toBeVisible();
});
it('should show info if no Revisions present, link for all revisions should not be shown and traffic split button should be disabled', () => {
render(
<RevisionsOverviewList revisions={[]} service={MockKnativeResources.revisions.data[0]} />,
);
expect(screen.queryByTestId('mock-Link')).not.toBeInTheDocument();
expect(screen.getByText(/No Revisions found for this resource/)).toBeInTheDocument();
expect(screen.getByTestId('mock-Button')).toBeDisabled();
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@frontend/packages/knative-plugin/src/components/overview/__tests__/RevisionsOverviewList.spec.tsx`
around lines 93 - 100, The test for RevisionsOverviewList currently only asserts
visibility of the traffic split button; update the assertion to check the
disabled state as the test name promises by replacing or augmenting the existing
expect(screen.getByTestId('mock-Button')).toBeVisible() with
expect(screen.getByTestId('mock-Button')).toBeDisabled() (or add that
assertion), so the "no revisions" scenario verifies the button is disabled;
target the getByTestId('mock-Button') call in RevisionsOverviewList.spec.tsx.

Comment on lines 55 to 63
it('should render multiple RoutesOverviewListItem when multiple routes', () => {
const { container } = render(
render(
<RoutesOverviewList
ksroutes={MockKnativeResources.ksroutes.data}
resource={MockKnativeResources.revisions.data[0]}
/>,
);
expect(container.querySelector('routesoverviewlistitem')).toBeInTheDocument();
expect(screen.getByTestId('mock-RoutesOverviewListItem')).toBeVisible();
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

“Multiple routes” case is not actually asserting multiplicity.

This test currently checks only that one item is visible, so it doesn’t verify the behavior in the test name.

Suggested fix
   it('should render multiple RoutesOverviewListItem when multiple routes', () => {
     render(
       <RoutesOverviewList
         ksroutes={MockKnativeResources.ksroutes.data}
         resource={MockKnativeResources.revisions.data[0]}
       />,
     );
-    expect(screen.getByTestId('mock-RoutesOverviewListItem')).toBeVisible();
+    expect(screen.getAllByTestId('mock-RoutesOverviewListItem').length).toBeGreaterThan(1);
   });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('should render multiple RoutesOverviewListItem when multiple routes', () => {
const { container } = render(
render(
<RoutesOverviewList
ksroutes={MockKnativeResources.ksroutes.data}
resource={MockKnativeResources.revisions.data[0]}
/>,
);
expect(container.querySelector('routesoverviewlistitem')).toBeInTheDocument();
expect(screen.getByTestId('mock-RoutesOverviewListItem')).toBeVisible();
});
it('should render multiple RoutesOverviewListItem when multiple routes', () => {
render(
<RoutesOverviewList
ksroutes={MockKnativeResources.ksroutes.data}
resource={MockKnativeResources.revisions.data[0]}
/>,
);
expect(screen.getAllByTestId('mock-RoutesOverviewListItem').length).toBeGreaterThan(1);
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@frontend/packages/knative-plugin/src/components/overview/__tests__/RoutesOverviewList.spec.tsx`
around lines 55 - 63, The test "should render multiple RoutesOverviewListItem
when multiple routes" only asserts a single visible item; update the test in
RoutesOverviewList.spec.tsx to assert multiplicity by querying all items
produced by <RoutesOverviewList> (use the test id 'mock-RoutesOverviewListItem')
and expecting length to equal the number of routes in
MockKnativeResources.ksroutes.data (or at least >1); ensure you use
screen.getAllByTestId('mock-RoutesOverviewListItem') and assert the resulting
array length matches/mock data count rather than a single getByTestId visibility
check.

Comment on lines 60 to 64
it('should not render FilterTable if filter is not present', () => {
const triggerDataClone = _.omit(_.cloneDeep(triggerData), 'spec.filter');
const { container } = render(<TriggerDetails obj={triggerDataClone} />);
expect(container.querySelector('filtertable')).toBeInTheDocument();
render(<TriggerDetails obj={triggerDataClone} />);
expect(screen.getByTestId('mock-FilterTable')).toBeVisible();
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix the negative-case assertion for missing filter.

Line 63 currently asserts FilterTable is visible, but the test name says it should not render when spec.filter is absent. This inverts the scenario’s intent.

Suggested fix
   it('should not render FilterTable if filter is not present', () => {
     const triggerDataClone = _.omit(_.cloneDeep(triggerData), 'spec.filter');
     render(<TriggerDetails obj={triggerDataClone} />);
-    expect(screen.getByTestId('mock-FilterTable')).toBeVisible();
+    expect(screen.queryByTestId('mock-FilterTable')).not.toBeInTheDocument();
   });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('should not render FilterTable if filter is not present', () => {
const triggerDataClone = _.omit(_.cloneDeep(triggerData), 'spec.filter');
const { container } = render(<TriggerDetails obj={triggerDataClone} />);
expect(container.querySelector('filtertable')).toBeInTheDocument();
render(<TriggerDetails obj={triggerDataClone} />);
expect(screen.getByTestId('mock-FilterTable')).toBeVisible();
});
it('should not render FilterTable if filter is not present', () => {
const triggerDataClone = _.omit(_.cloneDeep(triggerData), 'spec.filter');
render(<TriggerDetails obj={triggerDataClone} />);
expect(screen.queryByTestId('mock-FilterTable')).not.toBeInTheDocument();
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@frontend/packages/knative-plugin/src/components/pub-sub/details/__test__/TriggerDetails.spec.tsx`
around lines 60 - 64, The test for TriggerDetails uses getByTestId which throws
if the element is missing, and currently asserts visibility even though the spec
says FilterTable should not render; update the negative-case assertion by using
screen.queryByTestId('mock-FilterTable') on the TriggerDetails render (with
triggerDataClone where spec.filter is omitted) and assert that it is null or not
present (e.g., expect(...).toBeNull() or expect(...).not.toBeInTheDocument()) so
the test correctly verifies FilterTable is not rendered.

@cajieh cajieh force-pushed the enable-rtl-eslint-rules-knative-tests branch from 158e48c to ee39c88 Compare May 7, 2026 20:33
@cajieh cajieh force-pushed the enable-rtl-eslint-rules-knative-tests branch from ee39c88 to 1ab93a6 Compare May 7, 2026 20:53
@cajieh
Copy link
Copy Markdown
Contributor Author

cajieh commented May 7, 2026

/test all

@cajieh
Copy link
Copy Markdown
Contributor Author

cajieh commented May 8, 2026

/test images

@cajieh
Copy link
Copy Markdown
Contributor Author

cajieh commented May 8, 2026

/test e2e-gcp-console

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 8, 2026

@cajieh: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/images 1ab93a6 link true /test images
ci/prow/e2e-gcp-console 1ab93a6 link true /test e2e-gcp-console

Full PR test history. Your PR dashboard.

Details

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. component/knative Related to knative-plugin jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants