From 7af7d0f1d6532b5adf70a9908a1740535c3df77a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 13 Jun 2026 13:23:41 +0000 Subject: [PATCH] Add unit tests for useRuntimeFlag composable 8 table-driven tests covering featureDropdownMenu computed: - versions at, above, and below the 2.11.0 boundary - v-prefixed and pre-release version strings - uncoercible strings (dev, unknown) fall back to 0.0.0 Uses a reactive ref mock so Vue's computed re-evaluates on each it.each entry without needing jest.isolateModules. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- shell/composables/useRuntimeFlag.test.ts | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 shell/composables/useRuntimeFlag.test.ts diff --git a/shell/composables/useRuntimeFlag.test.ts b/shell/composables/useRuntimeFlag.test.ts new file mode 100644 index 00000000000..ab33e6ee076 --- /dev/null +++ b/shell/composables/useRuntimeFlag.test.ts @@ -0,0 +1,59 @@ +import { ref } from 'vue'; +import { useRuntimeFlag } from '@shell/composables/useRuntimeFlag'; + +const mockVersion = ref('2.12.0'); +const mockGetVersionInfo = jest.fn(() => ({ fullVersion: mockVersion.value })); + +jest.mock('@shell/utils/version', () => ({ getVersionInfo: (...args: any[]) => mockGetVersionInfo(...args) })); + +describe('useRuntimeFlag', () => { + describe('featureDropdownMenu', () => { + const { featureDropdownMenu } = useRuntimeFlag({} as any); + + it.each([ + { + desc: 'version at boundary 2.11.0', + fullVersion: '2.11.0', + expected: true, + }, + { + desc: 'version above boundary', + fullVersion: '2.12.0', + expected: true, + }, + { + desc: 'v-prefixed version at boundary', + fullVersion: 'v2.11.0', + expected: true, + }, + { + desc: 'pre-release version at boundary', + fullVersion: '2.11.0-rc1', + expected: true, + }, + { + desc: 'version just below boundary', + fullVersion: '2.10.9', + expected: false, + }, + { + desc: 'old version well below boundary', + fullVersion: '2.0.0', + expected: false, + }, + { + desc: 'uncoercible dev version string', + fullVersion: 'dev', + expected: false, + }, + { + desc: 'unknown version string', + fullVersion: 'unknown', + expected: false, + }, + ])('returns $expected for $desc', ({ fullVersion, expected }) => { + mockVersion.value = fullVersion; + expect(featureDropdownMenu.value).toStrictEqual(expected); + }); + }); +});