-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(files): Provide
useFileListWidth
composable
Replace the mixin with a composable, this is better typed and works in both: Options- and Composition API. Also added component tests for it. Signed-off-by: Ferdinand Thiessen <[email protected]>
- Loading branch information
Showing
8 changed files
with
115 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/*! | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import { defineComponent } from 'vue' | ||
import { useFileListWidth } from './useFileListWidth.ts' | ||
|
||
const ComponentMock = defineComponent({ | ||
template: '<div id="test-component" style="width: 100%;background: white;">{{ fileListWidth }}</div>', | ||
setup() { | ||
return { | ||
fileListWidth: useFileListWidth(), | ||
} | ||
}, | ||
}) | ||
const FileListMock = defineComponent({ | ||
template: '<main id="app-content-vue" style="width: 100%;"><component-mock /></main>', | ||
components: { | ||
ComponentMock, | ||
}, | ||
}) | ||
|
||
describe('composable: fileListWidth', () => { | ||
|
||
it('Has initial value', () => { | ||
cy.viewport(600, 400) | ||
|
||
cy.mount(FileListMock, {}) | ||
cy.get('#app-content-vue') | ||
.should('be.visible') | ||
.and('contain.text', '600') | ||
}) | ||
|
||
it('Is reactive to size change', () => { | ||
cy.viewport(600, 400) | ||
cy.mount(FileListMock) | ||
cy.get('#app-content-vue').should('contain.text', '600') | ||
|
||
cy.viewport(800, 400) | ||
cy.screenshot() | ||
cy.get('#app-content-vue').should('contain.text', '800') | ||
}) | ||
|
||
it('Is reactive to style changes', () => { | ||
cy.viewport(600, 400) | ||
cy.mount(FileListMock) | ||
cy.get('#app-content-vue') | ||
.should('be.visible') | ||
.and('contain.text', '600') | ||
.invoke('attr', 'style', 'width: 100px') | ||
|
||
cy.get('#app-content-vue') | ||
.should('contain.text', '100') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/*! | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import type { Ref } from 'vue' | ||
import { useElementSize } from '@vueuse/core' | ||
import { onMounted, onUnmounted, ref } from 'vue' | ||
|
||
/** | ||
* Get the reactive width of the file list | ||
*/ | ||
export function useFileListWidth(): Readonly<Ref<number>> { | ||
const element = ref(document.querySelector<HTMLElement>('#app-content-vue') ?? document.body) | ||
onMounted(() => { element.value = document.querySelector('#app-content-vue')! }) | ||
|
||
const { width, stop } = useElementSize(element) | ||
onUnmounted(stop) | ||
|
||
return width | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.