From c6b4c6dbf21dd4cd9e87dad68ca67fa8c83035e7 Mon Sep 17 00:00:00 2001 From: Alex Grozav Date: Mon, 29 Apr 2024 16:10:48 +0300 Subject: [PATCH] refactor(editor): Rewrite TabBar to composition API (no-changelog) (#9231) --- .../src/components/MainHeader/MainHeader.vue | 4 +- .../src/components/MainHeader/TabBar.spec.ts | 57 +++++++++++++++++++ .../src/components/MainHeader/TabBar.vue | 57 +++++++------------ 3 files changed, 80 insertions(+), 38 deletions(-) create mode 100644 packages/editor-ui/src/components/MainHeader/TabBar.spec.ts diff --git a/packages/editor-ui/src/components/MainHeader/MainHeader.vue b/packages/editor-ui/src/components/MainHeader/MainHeader.vue index 53eb1fd634..c0e7068140 100644 --- a/packages/editor-ui/src/components/MainHeader/MainHeader.vue +++ b/packages/editor-ui/src/components/MainHeader/MainHeader.vue @@ -6,8 +6,8 @@ diff --git a/packages/editor-ui/src/components/MainHeader/TabBar.spec.ts b/packages/editor-ui/src/components/MainHeader/TabBar.spec.ts new file mode 100644 index 0000000000..2d05ed572f --- /dev/null +++ b/packages/editor-ui/src/components/MainHeader/TabBar.spec.ts @@ -0,0 +1,57 @@ +import { fireEvent } from '@testing-library/vue'; +import { createComponentRenderer } from '@/__tests__/render'; +import TabBar from '@/components/MainHeader/TabBar.vue'; + +const renderComponent = createComponentRenderer(TabBar); + +describe('TabBar', () => { + const items = [ + { name: 'Workflow', value: 'workflow' }, + { name: 'Executions', value: 'executions' }, + ]; + + it('should render the correct number of tabs', async () => { + const { findAllByRole } = renderComponent({ + props: { + items, + modelValue: 'workflow', + }, + }); + + const tabs = await findAllByRole('radio'); + expect(tabs.length).toBe(2); + }); + + it('should emit update:modelValue event when a tab is clicked', async () => { + const { findAllByRole, emitted } = renderComponent({ + props: { + items, + modelValue: 'workflow', + }, + }); + + const tabs = await findAllByRole('radio'); + const executionsTab = tabs[1]; + + await fireEvent.click(executionsTab); + + expect(emitted()).toHaveProperty('update:modelValue'); + }); + + it('should update the active tab when modelValue prop changes', async () => { + const { findAllByRole, rerender } = renderComponent({ + props: { + items, + modelValue: 'workflow', + }, + }); + + await rerender({ modelValue: 'executions' }); + + const tabs = await findAllByRole('radio'); + const executionsTab = tabs[1]; + const executionsTabButton = executionsTab.querySelector('.button'); + + expect(executionsTabButton).toHaveClass('active'); + }); +}); diff --git a/packages/editor-ui/src/components/MainHeader/TabBar.vue b/packages/editor-ui/src/components/MainHeader/TabBar.vue index b0dc486441..1b11891aa4 100644 --- a/packages/editor-ui/src/components/MainHeader/TabBar.vue +++ b/packages/editor-ui/src/components/MainHeader/TabBar.vue @@ -4,50 +4,35 @@ :class="{ [$style.container]: true, ['tab-bar-container']: true, - [$style.menuCollapsed]: mainSidebarCollapsed, }" > - + -