Skip to content

Add Vitest unit tests for frontend admin UI - #3797

Merged
bobvandevijver merged 1 commit into
bolt:6.2from
Vondry:chore/vitest-unit-tests
Oct 24, 2026
Merged

bobvandevijver merged 1 commit into
bolt:6.2from
Vondry:chore/vitest-unit-tests

Conversation

@Vondry

@Vondry Vondry commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR is effectively the third step in the Vue 3 migration, following #3794 (now merged). It adds > 90% test coverage to the admin UI assets, so that we can be much more confident with the Vue 3 refactor later.

  • This PR does not touch any runtime code at all

What's Changed

Adds Vitest and @vue/test-utils for the frontend admin UI components, Vuex stores, filters, and app scripts. This creates a solid regression test suite on Vue 2.7 ahead of the Vue 3 migration.

  • Test Runner: Configured Vitest with Vue 2.7 plugin, jsdom environment, and path aliases
  • Test Harness: Added isolated Vuex store factories, component stubs (multiselect, draggable, editors), DOM fixtures, and global warning fail-fast checks
  • Test Isolation: Every mounted component is destroyed after its test, and spies and stubbed globals are restored automatically, so tests do not depend on their order
  • Coverage: Added unit tests covering:
    • Form editor components (Text, File, Image, Select, Date, Collection, Embed, etc.)
    • Listing table components, bulk selection, and row actions
    • Sidebar, menu navigation, and toolbar
    • App scripts (ajax-save, common, modal, notifications, patience-is-a-virtue, save-on-ctrl-s)
    • Vuex stores, mixins, filters, and API services
  • Existing bugs: Where a component has a known bug, the test pins the current behaviour and is marked Pinning current behaviour, so the Vue 3 refactor can decide what to fix
  • Tooling & CI:
    • Added test:unit, test:unit:watch, and test:unit:coverage npm scripts
    • Added a unit test run to GitHub Actions CI (assets_code_analysis.yaml), with test order shuffled (--sequence.shuffle) to catch order-dependent tests
    • Updated ESLint to lint test files and added coverage/ to .gitignore

Verification

  • npm run test:unit:coverage passes (47 test files, 486 passed, 2 skipped, 9 todo; 97% lines, 92% branches)
  • Stable across repeated shuffled runs
  • npm run lint passes (0 errors, 0 warnings)
  • npm run typecheck passes
  • npm run stylelint passes
  • npm run build succeeds

Notes for the Vue 3 Migration

Tests assert against rendered DOM rather than component internals, so adapting them to Vue 3 is mostly mechanical:

  • @vue/test-utils: propsData: → props:, store/localVue → global.plugins, enableAutoDestroy → enableAutoUnmount, .at(i) → [i]
  • Component stubs: Update v-model event from input to update:modelValue
  • Replace $root.$emit/$on with mitt (Slug ↔ Text) and Vuex with Pinia
  • Un-skip the 2 it.skip tests and write the 9 it.todo tests once their component fixes land. Each one names the commit on refactor/vue3-composition-api that unblocks it (grep -rnE 'it\.(skip|todo)' tests/unit)

Copilot AI left a comment

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.

🔵 Needs a closer look

The broad test harness and dependency changes need human validation of coverage and build results, with locale-dependent assertions still unresolved.

2 open issues
What changed in this PR

Adds a frontend regression suite for Bolt’s Vue 2.7 admin UI ahead of the Vue 3 migration, without changing application source code.

Changes:

  • Adds component, store, filter, service, and app-script tests with shared fixtures and cleanup helpers.
  • Configures Vitest coverage thresholds and shuffled CI runs.
  • Extends TypeScript and ESLint checks to tests and documents migration conventions.
File Description
vitest.config.ts Configures Vue 2 testing, isolation, and coverage thresholds.
tsconfig.json Includes tests and adds module typing support.
tests/​unit/​store/​sidebar-toolbar.spec.ts Tests sidebar, toolbar, and editor stores.
tests/​unit/​store/​listing.spec.ts Tests listing state, selection, and isolation.
tests/​unit/​shims-vuex.d.ts Types the Vuex mount option.
tests/​unit/​shims-vue.d.ts Declares component imports for tests.
tests/​unit/​setup.ts Adds shared browser setup and teardown.
tests/​unit/​services/​api.spec.ts Tests API requests and cached responses.
tests/​unit/​README.md Documents testing conventions and migration steps.
tests/​unit/​mixins/​value.spec.ts Tests field-value initialization and decoding.
tests/​unit/​mixins/​type.spec.ts Tests reactive content-type access.
tests/​unit/​helpers/​warnings.ts Captures and checks Vue warnings.
tests/​unit/​helpers/​stubs.ts Provides third-party component stubs.
tests/​unit/​helpers/​store.ts Builds isolated stores from application modules.
tests/​unit/​helpers/​errors.ts Captures expected Vue lifecycle errors.
tests/​unit/​helpers/​dom.ts Provides surrounding DOM fixtures and cleanup.
tests/​unit/​helpers/​bus.ts Drives and records field-bus events.
tests/​unit/​helpers/​async.ts Adds asynchronous test flushing.
tests/​unit/​filters/​string.spec.ts Tests string formatting and edge cases.
tests/​unit/​filters/​date.spec.ts Tests date and datetime formatting.
tests/​unit/​components/​toolbar/​Toolbar.spec.ts Tests toolbar rendering and color state.
tests/​unit/​components/​ThemeSelect.spec.ts Tests theme stylesheet switching.
tests/​unit/​components/​Textarea.spec.ts Tests textarea metadata and editing.
tests/​unit/​components/​Text.spec.ts Tests text fields and slug-generation events.
tests/​unit/​components/​Slug.spec.ts Tests slug generation, locking, and editing.
tests/​unit/​components/​sidebar/​SubMenu.spec.ts Tests submenu links and labels.
tests/​unit/​components/​sidebar/​SidebarToggler.spec.ts Tests sidebar toggling and persistence.
tests/​unit/​components/​sidebar/​Sidebar.spec.ts Tests sidebar rendering and restored state.
tests/​unit/​components/​sidebar/​Menu.spec.ts Tests navigation and singleton links.
tests/​unit/​components/​Select.spec.ts Tests selections, tagging, ordering, and fetching.
tests/​unit/​components/​ProgressBar.spec.ts Tests progress dimensions and accessibility attributes.
tests/​unit/​components/​Password.spec.ts Tests password visibility and strength scoring.
tests/​unit/​components/​Number.spec.ts Tests numeric field metadata and editing.
tests/​unit/​components/​Markdown.spec.ts Tests markdown editor integration.
tests/​unit/​components/​listing/​Table.spec.ts Tests record rendering and reordering.
tests/​unit/​components/​listing/​SelectBox.spec.ts Tests bulk-action controls and form data.
tests/​unit/​components/​listing/​RowSorting.spec.ts Tests sorting-handle visibility.
tests/​unit/​components/​listing/​RowMeta.spec.ts Tests record metadata rendering.
tests/​unit/​components/​listing/​RowCheckbox.spec.ts Tests row selection and sorting interactions.
tests/​unit/​components/​listing/​RowActions.spec.ts Tests action links and record details.
tests/​unit/​components/​listing/​Row.spec.ts Tests row composition and display modes.
tests/​unit/​components/​listing/​Records.spec.ts Tests initial record-store population.
tests/​unit/​components/​listing/​Filter.spec.ts Tests listing controls and saved preferences.
tests/​unit/​components/​Language.spec.ts Tests locale selection and navigation.
tests/​unit/​components/​Imagelist.spec.ts Tests image-list ordering and removal.
tests/​unit/​components/​Html.spec.ts Tests rich-text editor integration.
tests/​unit/​components/​Filelist.spec.ts Tests file-list controls and indexing.
tests/​unit/​components/​File.spec.ts Tests uploads and server-file browsing.
tests/​unit/​components/​Embed.spec.ts Tests embed lookup, debounce, and previews.
tests/​unit/​components/​Email.spec.ts Tests email-field rendering and metadata.
tests/​unit/​components/​Date.spec.ts Tests real flatpickr integration.
tests/​unit/​components/​Collection.spec.ts Tests collection controls and submitted ordering.
tests/​unit/​components/​Checkbox.spec.ts Tests checkbox state and submitted values.
tests/​unit/​app/​save-on-ctrl-s.spec.ts Tests keyboard save behavior.
tests/​unit/​app/​patience-is-a-virtue.spec.ts Tests loading indicators and button restoration.
tests/​unit/​app/​notifications.spec.ts Tests flash-message toast initialization.
tests/​unit/​app/​modal.spec.ts Tests shared modal reset behavior.
tests/​unit/​app/​common.spec.ts Tests shared admin-page interactions.
tests/​unit/​app/​ajax-save.spec.ts Tests saving, validation, and unload warnings.
package.json Adds test tooling and scripts; updates Terser.
eslint.config.mjs Extends TypeScript linting to tests.
.gitignore Excludes generated coverage reports.
.github/​workflows/​assets_code_analysis.yaml Runs shuffled unit tests with coverage.

Review effort: Balanced

Comment thread tests/unit/app/common.spec.ts
Comment thread tests/unit/filters/date.spec.ts
@bobvandevijver
bobvandevijver merged commit cf9add7 into bolt:6.2 Oct 24, 2026
38 checks passed
@bobvandevijver

Copy link
Copy Markdown
Member

Thanks @Vondry!

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.

3 participants