From 0b01d65cce7954e8c0dd728e86e89fd353cffad9 Mon Sep 17 00:00:00 2001 From: Gerard Mc Ardle Date: Fri, 15 May 2026 12:14:19 +0200 Subject: [PATCH] refactor: update SideBar component styles and add unit tests - Changed width properties to use flexbox for better responsiveness. - Added min-height and max-width constraints. - Introduced a new test suite for the SideBar component to ensure proper rendering and responsive behavior. --- .../src/components/SideBar/SideBar.vue | 9 +- .../unit/components/sidebar/SideBar.spec.ts | 95 +++++++++++++++++++ 2 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 packages/web-pkg/tests/unit/components/sidebar/SideBar.spec.ts diff --git a/packages/web-pkg/src/components/SideBar/SideBar.vue b/packages/web-pkg/src/components/SideBar/SideBar.vue index f624413e4fa..38e536a096c 100644 --- a/packages/web-pkg/src/components/SideBar/SideBar.vue +++ b/packages/web-pkg/src/components/SideBar/SideBar.vue @@ -294,8 +294,11 @@ export default defineComponent({ border-left: 1px solid var(--oc-color-border); position: relative; overflow: hidden; - min-width: 440px; - width: 440px; + flex: 0 1 440px; + min-width: 0; + max-width: 440px; + align-self: stretch; + min-height: 0; &:focus, &:focus-visible { @@ -306,6 +309,7 @@ export default defineComponent({ .app-sidebar-full-width { min-width: 100% !important; width: 100% !important; + max-width: 100% !important; } @media only screen and (max-width: $oc-breakpoint-medium-default) { @@ -392,6 +396,7 @@ export default defineComponent({ } &__body { + min-height: 0; overflow-y: auto; overflow-x: hidden; padding: var(--oc-space-small); diff --git a/packages/web-pkg/tests/unit/components/sidebar/SideBar.spec.ts b/packages/web-pkg/tests/unit/components/sidebar/SideBar.spec.ts new file mode 100644 index 00000000000..f221825a211 --- /dev/null +++ b/packages/web-pkg/tests/unit/components/sidebar/SideBar.spec.ts @@ -0,0 +1,95 @@ +import SideBar from '../../../../src/components/SideBar/SideBar.vue' +import { SideBarPanel } from '../../../../src/components/SideBar/types' +import { Resource, SpaceResource } from '@ownclouders/web-client' +import { defaultPlugins, shallowMount } from '@ownclouders/web-test-helpers' +import { defineComponent } from 'vue' + +const DummyPanel = defineComponent({ name: 'DummyPanel', template: '
' }) + +const mockRootPanel: SideBarPanel = { + name: 'Details', + icon: 'information', + title: () => 'Details', + isVisible: () => true, + isRoot: () => true, + component: DummyPanel +} + +describe('SideBar', () => { + it('renders app-sidebar landmark', () => { + const wrapper = shallowMount(SideBar, { + props: { + isOpen: true, + loading: false, + availablePanels: [mockRootPanel], + panelContext: { items: [] }, + activePanel: '' + }, + global: { + plugins: [...defaultPlugins()], + stubs: { OcSpinner: true, OcButton: true, OcIcon: true } + } + }) + expect(wrapper.find('[data-testid="app-sidebar"]').exists()).toBe(true) + }) + + it('adds full-width class when viewport width is at most 960px', () => { + const original = window.innerWidth + Object.defineProperty(window, 'innerWidth', { + configurable: true, + value: 800 + }) + try { + const wrapper = shallowMount(SideBar, { + props: { + isOpen: true, + loading: false, + availablePanels: [mockRootPanel], + panelContext: { items: [] }, + activePanel: '' + }, + global: { + plugins: [...defaultPlugins()], + stubs: { OcSpinner: true, OcButton: true, OcIcon: true } + } + }) + expect(wrapper.find('[data-testid="app-sidebar"]').classes()).toContain('app-sidebar-full-width') + } finally { + Object.defineProperty(window, 'innerWidth', { + configurable: true, + value: original + }) + } + }) + + it('does not add full-width class when viewport is wider than 960px', () => { + const original = window.innerWidth + Object.defineProperty(window, 'innerWidth', { + configurable: true, + value: 1400 + }) + try { + const wrapper = shallowMount(SideBar, { + props: { + isOpen: true, + loading: false, + availablePanels: [mockRootPanel], + panelContext: { items: [] }, + activePanel: '' + }, + global: { + plugins: [...defaultPlugins()], + stubs: { OcSpinner: true, OcButton: true, OcIcon: true } + } + }) + expect(wrapper.find('[data-testid="app-sidebar"]').classes()).not.toContain( + 'app-sidebar-full-width' + ) + } finally { + Object.defineProperty(window, 'innerWidth', { + configurable: true, + value: original + }) + } + }) +})