Repository navigation
test: add component tests for the administration client - #29
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 testrunssrc/**/*.test.tsx, which sit next to each component.vitest.config.mtspoints@kentico/xperience-admin-baseand@kentico/xperience-admin-componentsat small test doubles inClient/test/kentico:usePageCommandrecords every payload inpageCommandCallsand returns responses set per test withmockPageCommand. Like the real hook,executekeeps the same identity across renders.Dialog,Input,Select,DateTimeInput, …) render plain HTML with proper labels, so tests query by role and label text.Client/dist.Tests (17):
FormSubmissionRemovalComponent:upperSubmissionId([Bug]: Advanced delete can remove submissions created after the preview #24).DELETEenables Delete.FormCloneComponent:CI and docs: CI runs
npm testafternpm run typecheckin the minimum-compatibility job.CONTRIBUTING.mdanddocs/Contributing-Setup.mdnow 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, thennpm test(17/17), thennpm run build. The rebuiltdistmatches the committed bundle.With each fixed bug put back temporarily, exactly the test aimed at it fails:
numberOfRecords: nullNo React
act()warnings or console errors during the run.dotnet packoutput contains no test files.npm auditreports 11 findings (fast-uri, qs, react-router, uuid). The same 11 exist onmain; these dependencies add none. Out of scope here.