Skip to content

test: add component tests for the administration client - #29

Merged
andresvillenas merged 1 commit into
mainfrom
test/client-component-tests
Sep 24, 2026
Merged

andresvillenas merged 1 commit into
mainfrom
test/client-component-tests

Conversation

@andresvillenas

Copy link
Copy Markdown
Collaborator

Summary

Fixes #25.

The administration client had no JavaScript test runner, so request building, validation and preview invalidation could only be checked by hand in a running admin. #22, #24 and #26 were all client-side bugs that the .NET tests couldn't catch.

Setup: Vitest with React Testing Library, jsdom and jest-dom matchers. All four are dev dependencies only.

  • npm test runs src/**/*.test.tsx, which sit next to each component.
  • The Kentico admin packages only run inside the Xperience admin, so vitest.config.mts points @kentico/xperience-admin-base and @kentico/xperience-admin-components at small test doubles in Client/test/kentico:
    • usePageCommand records every payload in pageCommandCalls and returns responses set per test with mockPageCommand. Like the real hook, execute keeps the same identity across renders.
    • The admin components (Dialog, Input, Select, DateTimeInput, …) render plain HTML with proper labels, so tests query by role and label text.
  • The webpack build is unaffected: the bundle hash didn't change. The NuGet package still contains only Client/dist.

Tests (17):

  • FormSubmissionRemovalComponent:
  • FormCloneComponent:
    • The default name is loaded for the row's form, and Clone sends the trimmed name.
    • The display name limit is measured after trimming, like the server does ([Bug]: Client type check fails and is not run in CI #26).
    • Clone is disabled for a blank name.
    • An invalid row form ID shows an error without calling the server.
    • Server errors are shown.

CI and docs: CI runs npm test after npm run typecheck in the minimum-compatibility job. CONTRIBUTING.md and docs/Contributing-Setup.md now list both commands and explain the test doubles.

The Advanced export and Export selected dialogs are not covered yet. They can reuse the same test doubles.

Test plan

  • The CI client steps pass from a clean npm ci: npm run typecheck, then npm test (17/17), then npm run build. The rebuilt dist matches the committed bundle.

  • With each fixed bug put back temporarily, exactly the test aimed at it fails:

    Reintroduced bug Failing test
    [Bug]: Export these first ignores Number of records limit #22: export sends numberOfRecords: null previews without a boundary and uses the returned boundary for export and delete
    [Bug]: Advanced delete can remove submissions created after the preview #24: export/delete ignore the preview boundary same test
    [Bug]: Client type check fails and is not run in CI #26: clone ignores the length limit blocks names longer than the server's limit, measured after trimming
  • No React act() warnings or console errors during the run.

  • dotnet pack output contains no test files.

  • npm audit reports 11 findings (fast-uri, qs, react-router, uuid). The same 11 exist on main; these dependencies add none. Out of scope here.

The administration client had no JavaScript test runner, so request
building, validation and preview invalidation could only be checked by
hand in a running admin. #22, #24 and #26 were all client-side bugs that
server tests could not catch.

Adds Vitest with React Testing Library and jsdom. The Kentico admin
packages only run inside the Xperience administration, so Vitest aliases
them to test doubles: usePageCommand records every payload and returns
responses set per test, and the admin components render plain, labelled
HTML.

Covers the Advanced delete dialog (matching filters and preview boundary
across Preview, Export these first and Delete, preview invalidation,
confirmation gating, validation and errors) and the Clone form dialog
(default name, trimmed submit, the display name limit, and errors). CI
runs the tests after the type check.

Fixes #25
@andresvillenas andresvillenas added the enhancement New feature or request label Sep 24, 2026
@andresvillenas
andresvillenas merged commit fd004cb into main Sep 24, 2026
3 checks passed
@andresvillenas
andresvillenas deleted the test/client-component-tests branch September 24, 2026 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add a component test setup for the administration client

1 participant