Skip to content

SRVOCF-822: Replace test mocks with stubs and extract shared test infrastructure - #149

Merged
openshift-merge-bot[bot] merged 1 commit into
openshift:masterfrom
twoGiants:SRVOCF-822-refactor-list-page-tests-batch-2
Aug 25, 2026
Merged

SRVOCF-822: Replace test mocks with stubs and extract shared test infrastructure#149
openshift-merge-bot[bot] merged 1 commit into
openshift:masterfrom
twoGiants:SRVOCF-822-refactor-list-page-tests-batch-2

Conversation

@twoGiants

@twoGiants twoGiants commented Aug 21, 2026

Copy link
Copy Markdown

Summary

  • 🧪 Replace the useCluster mock in list page tests with a shared useK8sWatchResourceStub that lets the real hook run, catching shape mismatches between the hook and its consumers
  • 🧪 Replace the TestConsumer render pattern in useCluster.test.tsx with renderHook from @testing-library/react
  • 🧪 Remove the FunctionTable mock from list page tests so the real table component is exercised
  • 🔧 Extract shared test infrastructure into src/common/testing/: authFake (session auth helpers), constants, mswServer (default MSW handlers), functionsClientStub, and the K8s watch resource stub with fixture builders
  • 🔧 Move FUNCTION_NAME_LABEL and REVISION_LABEL from useCluster.ts to types.ts so both production code and test stubs can reference them without circular imports
  • 🐛 Remove stale COPY testing/ testing/ from Dockerfile (directory no longer exists)
  • 📚 Update TESTING.md to reflect new MSW handler location

Relates to SRVOCF-822

Checklist

  • Updated docs/ARCHITECTURE.md (if there are relevant changes to our layered architecture)

Additional Info

This is preparatory test refactoring for the namespace scoping feature (SRVOCF-822). The feature implementation will land in a follow-up PR once SRVOCF-979 merges.

The key motivation is twofold. First, the list page tests mocked useCluster entirely, hiding the hook's internals behind pre-computed return values. With the shared useK8sWatchResourceStub, tests set up raw K8s resource fixtures (Knative Services, Deployments) and let the real useCluster derive status, replicas, and URL. Type or field changes in the hook's return shape are now caught immediately instead of passing against a stale mock.

Second, this PR cleans up and streamlines a large chunk of the test suite, introducing testing conventions and a common testing library under src/common/testing/. This library is intended to grow with reusable test doubles and fixtures in future PRs. Not all tests are refactored here; the remaining test files will be migrated incrementally as related work touches them.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Aug 21, 2026
@openshift-ci-robot

openshift-ci-robot commented Aug 21, 2026

Copy link
Copy Markdown

@twoGiants: This pull request references SRVOCF-822 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.1.0" version, but no target version was set.

Details

In response to this:

Summary

  • 🧪 Replace the useCluster mock in list page tests with a shared useK8sWatchResourceStub that lets the real hook run, catching shape mismatches between the hook and its consumers
  • 🧪 Replace the TestConsumer render pattern in useCluster.test.tsx with renderHook from @testing-library/react
  • 🧪 Remove the FunctionTable mock from list page tests so the real table component is exercised
  • 🔧 Extract shared test infrastructure into src/common/testing/: authFake (session auth helpers), constants, mswServer (default MSW handlers), functionsClientStub, and the K8s watch resource stub with fixture builders
  • 🔧 Move FUNCTION_NAME_LABEL and REVISION_LABEL from useCluster.ts to types.ts so both production code and test stubs can reference them without circular imports
  • 🐛 Remove stale COPY testing/ testing/ from Dockerfile (directory no longer exists)
  • 📚 Update TESTING.md to reflect new MSW handler location

Relates to SRVOCF-822

Checklist

  • Updated docs/ARCHITECTURE.md (if there are relevant changes to our layered architecture)

Additional Info

This is preparatory test refactoring for the namespace scoping feature (SRVOCF-822). The feature implementation will land in a follow-up PR once SRVOCF-979 merges.

The key motivation is twofold. First, the list page tests mocked useCluster entirely, hiding the hook's internals behind pre-computed return values. With the shared useK8sWatchResourceStub, tests set up raw K8s resource fixtures (Knative Services, Deployments) and let the real useCluster derive status, replicas, and URL. Type or field changes in the hook's return shape are now caught immediately instead of passing against a stale mock.

Second, this PR cleans up and streamlines a large chunk of the test suite, introducing testing conventions and a common testing library under src/common/testing/. This library is intended to grow with reusable test doubles and fixtures in future PRs. Not all tests are refactored here; the remaining test files will be migrated incrementally as related work touches them.

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
openshift-ci Bot requested review from dsimansk and pmeida August 21, 2026 11:21
@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 21, 2026
@twoGiants twoGiants removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 21, 2026
@twoGiants
twoGiants force-pushed the SRVOCF-822-refactor-list-page-tests-batch-2 branch from 1154e29 to 39ae7bb Compare August 21, 2026 11:41
Comment thread src/common/testing/authFake.ts Outdated
Comment thread src/common/testing/authFake.ts Outdated
Comment thread src/common/testing/functionsClientStub.ts Outdated
Comment thread src/common/testing/functionsClientStub.ts Outdated

@Cragsmann Cragsmann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

looks good, few nit picks

@twoGiants
twoGiants force-pushed the SRVOCF-822-refactor-list-page-tests-batch-2 branch 2 times, most recently from 0ef6397 to c87bb9a Compare August 21, 2026 12:18
Comment thread src/common/types.ts Outdated
Comment thread src/pages/function-list/FunctionsListPage.test.tsx Outdated
Comment thread src/pages/function-list/FunctionsListPage.test.tsx Outdated
Comment thread vitest.config.mts
@openshift-ci openshift-ci Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 24, 2026
@twoGiants
twoGiants force-pushed the SRVOCF-822-refactor-list-page-tests-batch-2 branch from c87bb9a to 69a143c Compare August 25, 2026 10:25
@openshift-ci openshift-ci Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 25, 2026
@pmeida

pmeida commented Aug 25, 2026

Copy link
Copy Markdown

Bad rebase, I think you removed this change:

🐛 Remove stale COPY testing/ testing/ from Dockerfile (directory no longer exists)

The list page tests mocked useCluster entirely, hiding
the hook's internals (status derivation, resource pairing,
label selectors) behind pre-computed return values. The
useCluster tests used a TestConsumer component to render
hook output into DOM elements, then asserted via data-testid
queries.

Replace the useCluster mock with a shared
useK8sWatchResourceStub that both useCluster.test.tsx and
FunctionsListPage.test.tsx use. Tests now set up raw K8s
resource fixtures (Knative Services, Deployments) and let
the real useCluster derive status, replicas, and URL.
Shape mismatches between the hook and its consumers are
caught at test time instead of hidden by a mock.

Replace TestConsumer with renderHook from
@testing-library/react. Hook return values are asserted
directly on result.current instead of through DOM nodes.

Extract shared test infrastructure into src/common/testing:
authFake (session auth helpers), constants (BACKEND_API),
mswServer (default MSW handlers + server), and the K8s
watch resource stub with fixture builders.

Move FUNCTION_NAME_LABEL and REVISION_LABEL from
useCluster.ts to types.ts so both production code and test
stubs can reference them without circular imports.

Keep .tmp directory for vitest output.

Issue SRVOCF-822

Signed-off-by: Stanislav Jakuschevskij <sjakusch@redhat.com>
@twoGiants
twoGiants force-pushed the SRVOCF-822-refactor-list-page-tests-batch-2 branch from 69a143c to 949ad22 Compare August 25, 2026 11:52
@pmeida

pmeida commented Aug 25, 2026

Copy link
Copy Markdown

/lgtm
/approve

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Aug 25, 2026
@openshift-ci

openshift-ci Bot commented Aug 25, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pmeida

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 Aug 25, 2026
@openshift-ci

openshift-ci Bot commented Aug 25, 2026

Copy link
Copy Markdown

@twoGiants: all tests passed!

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.

@openshift-merge-bot
openshift-merge-bot Bot merged commit c96edb7 into openshift:master Aug 25, 2026
6 checks passed
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. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants