Skip to content

Add Vitest unit tests for frontend admin UI - #3797

Open
Vondry wants to merge 2 commits into
bolt:6.2from
Vondry:chore/vitest-unit-tests
Open

Add Vitest unit tests for frontend admin UI#3797
Vondry wants to merge 2 commits 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 based on the previous #3794 (should be merged first) and it is effectively third step in the Vue 3 migration which adds > 90% test coverage to the admin UI assets, so that we can be later much more confident with the Vue 3 refactor.

  • This PR does not touch any runtime code at all! All runtime code changes are there only because it is based on the existing open PR

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
  • 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
  • Tooling & CI:
    • Added test:unit, test:unit:watch, and test:unit:coverage npm scripts
    • Added unit test run to GitHub Actions CI (assets_code_analysis.yaml)
    • Updated ESLint to lint test files and added coverage/ to .gitignore

Verification

  • npm run test:unit passes (47 test files, 485 passed, 11 skipped)
  • 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/localVueglobal.plugins, destroy()unmount(), .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
  • Unblock the 11 it.skip tests once component fixes land

Vondry added 2 commits August 14, 2026 10:34
First step of the staged Vue 3 / TypeScript migration. Introduces
TypeScript on the existing Vue 2.7 codebase without touching any
component logic, so the eventual framework swap lands as a much
smaller, mechanical change.

Build tooling:

- Upgrade @symfony/webpack-encore 1.8.2 -> 4.7.0. 4.7 is the last
  release supporting Vue 2; Encore 5.0 dropped it. The version option
  of enableVueLoader() is deliberately omitted: it only accepts 2 or 3,
  and passing 2 selects the target that still requires
  vue-template-compiler. Left unset, Encore detects vue@2.7 and picks
  its "vue2.7" target, which uses the SFC compiler Vue 2.7 ships
  itself, so vue-template-compiler is no longer needed.
- Bump sass-loader 9 -> 14 and postcss-loader 4 -> 8 to match Encore
  4.7's peer ranges, and add webpack and webpack-cli as explicit
  dependencies as Encore 4 requires.
- Drop @babel/plugin-transform-regenerator and
  @babel/plugin-transform-runtime, which were declared but unreferenced.

TypeScript:

- Add tsconfig.json with strict plus noImplicitReturns,
  noFallthroughCasesInSwitch, noImplicitOverride, isolatedModules,
  allowUnreachableCode false and allowUnusedLabels false. The include
  list is .ts/.d.ts only; the SFCs have no lang="ts" yet, so they are
  not type-checked until they move to <script setup lang="ts"> and the
  checker becomes vue-tsc.
- Add typescript 6, ts-loader and @types/luxon, wire ts-loader through
  Encore.enableTypeScriptLoader(), and add a typecheck script plus a CI
  step running it.
- Scope typescript-eslint to assets/**/*.ts so the Vue 2 SFCs keep
  being linted by the vue2 preset.

Filters:

- Convert assets/js/filters and assets/js/services/api to TypeScript.
- Replace the Vue 2 global filters, removed in Vue 3, with directly
  imported functions at all 13 call sites across 7 components. Return
  types are inferred rather than annotated.

Behaviour is unchanged apart from trim(), strip() and uppercase() no
longer throwing a TypeError on null or non-string input. Values that
previously rendered are unaffected: trim() still passes non-strings
through untouched instead of coercing them, so numbers are not
truncated and objects do not become "[object Object]".
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.

1 participant