From 3457fe18cf8193883f45b50ecbc9638c91ace2fb Mon Sep 17 00:00:00 2001 From: undergroundwires Date: Thu, 14 Dec 2023 09:51:42 +0100 Subject: [PATCH] Fix OS switching not working on tree view UI This commit resolves a rendering bug in the tree view component. Previously, updating the tree collection prior to node updates led to rendering errors due to the presence of non-existent nodes in the new collection. Changes: - Implement manual control over the rendering process in tree view. This includes clearing the rendering queue and currently rendered nodes before updates, aligning the rendering process with the updated collection. - Add Cypress E2E tests to test switching between all operating systems and script views, ensuring no uncaught errors and preventing regression. - Replace hardcoded operating system lists in the download URL list view with a unified `getSupportedOsList()` method from the application, reducing duplication and simplifying future updates. - Rename `initial-nodes` to `nodes` in `TreeView.vue` to reflect their mutable nature. - Centralize the function for getting operating system names into `OperatingSystemNames.ts`, improving reusability in E2E tests. --- .../components/Scripts/Menu/TheOsChanger.vue | 18 ++--- .../Scripts/View/Tree/ScriptsTree.vue | 6 +- .../Rendering/UseGradualNodeRendering.ts | 35 +++++++-- .../Scripts/View/Tree/TreeView/TreeView.vue | 41 +++++++++-- .../components/Shared/OperatingSystemNames.ts | 15 ++++ .../components/TheFooter/DownloadUrlList.vue | 13 ++-- .../TheFooter/DownloadUrlListItem.vue | 17 +---- tests/e2e/code-highlighting.cy.ts | 2 +- tests/e2e/operating-system-selector.cy.ts | 72 +++++++++++++++++++ tests/e2e/tsconfig.json | 2 +- .../Tree/Shared/OperatingSystemNames.spec.ts | 24 +++++++ .../View/Tree/TreeView/TreeView.spec.ts | 58 +++++++++++---- .../Rendering/UseGradualNodeRendering.spec.ts | 58 +++++++++++++-- 13 files changed, 285 insertions(+), 76 deletions(-) create mode 100644 src/presentation/components/Shared/OperatingSystemNames.ts create mode 100644 tests/e2e/operating-system-selector.cy.ts create mode 100644 tests/integration/presentation/components/Scripts/View/Tree/Shared/OperatingSystemNames.spec.ts diff --git a/src/presentation/components/Scripts/Menu/TheOsChanger.vue b/src/presentation/components/Scripts/Menu/TheOsChanger.vue index 6bebcacb..e0cf643a 100644 --- a/src/presentation/components/Scripts/Menu/TheOsChanger.vue +++ b/src/presentation/components/Scripts/Menu/TheOsChanger.vue @@ -14,10 +14,11 @@ import { defineComponent, computed } from 'vue'; import { injectKey } from '@/presentation/injectionSymbols'; import { OperatingSystem } from '@/domain/OperatingSystem'; +import { getOperatingSystemDisplayName } from '@/presentation/components/Shared/OperatingSystemNames'; import MenuOptionList from './MenuOptionList.vue'; import MenuOptionListItem from './MenuOptionListItem.vue'; -interface IOsViewModel { +interface OperatingSystemOption { readonly name: string; readonly os: OperatingSystem; } @@ -31,12 +32,12 @@ export default defineComponent({ const { modifyCurrentContext, currentState } = injectKey((keys) => keys.useCollectionState); const { application } = injectKey((keys) => keys.useApplication); - const allOses = computed>( + const allOses = computed>( () => application .getSupportedOsList() - .map((os) : IOsViewModel => ({ + .map((os) : OperatingSystemOption => ({ os, - name: renderOsName(os), + name: getOperatingSystemDisplayName(os), })), ); @@ -57,13 +58,4 @@ export default defineComponent({ }; }, }); - -function renderOsName(os: OperatingSystem): string { - switch (os) { - case OperatingSystem.Windows: return 'Windows'; - case OperatingSystem.macOS: return 'macOS'; - case OperatingSystem.Linux: return 'Linux (preview)'; - default: throw new RangeError(`Cannot render os name: ${OperatingSystem[os]}`); - } -} diff --git a/src/presentation/components/Scripts/View/Tree/ScriptsTree.vue b/src/presentation/components/Scripts/View/Tree/ScriptsTree.vue index 8bf044be..7cc1b647 100644 --- a/src/presentation/components/Scripts/View/Tree/ScriptsTree.vue +++ b/src/presentation/components/Scripts/View/Tree/ScriptsTree.vue @@ -5,9 +5,9 @@ 'top-padding': hasTopPadding, }" > -