Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 61 additions & 39 deletions lib/components/FilePicker/FileListRow.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { Wrapper } from '@vue/test-utils'
import type { ComponentProps } from 'vue-component-type-helpers'

import { afterEach, describe, expect, it, vi } from 'vitest'
import { File, Folder, Permission } from '@nextcloud/files'
Expand All @@ -13,46 +13,9 @@ import { shallowMount } from '@vue/test-utils'
import FileListRow from './FileListRow.vue'
import { nextTick } from 'vue'

/* eslint-disable @typescript-eslint/no-explicit-any, jsdoc/require-jsdoc */

type SubmitAction = (wrapper: Wrapper<any>) => Promise<void>
type ElementEvent = { 'update:selected': boolean | undefined, 'enter-directory': Folder | undefined }

async function clickCheckboxAction(wrapper: Wrapper<any>) {
wrapper.find('input[type="checkbox"]').trigger('click')
}

async function clickElementAction(wrapper: Wrapper<any>) {
wrapper.find('[data-testid="row-name"]').trigger('click')
}

async function pressEnterAction(wrapper: Wrapper<any>) {
wrapper.element.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'Enter' }))
await nextTick()
}

function testSubmitNode(name: string, propsData: ComponentProps<typeof FileListRow>, eventPayload: ElementEvent, actionCallback: SubmitAction) {
it(name, async () => {
const wrapper = shallowMount(FileListRow as any, {
propsData,
stubs: {
NcCheckboxRadioSwitch: {
template: '<label><input type="checkbox" @click="$emit(\'update:model-value\', true)" ></label>',
},
},
})

await actionCallback(wrapper)

for (const [event, payload] of Object.entries(eventPayload)) {
if (payload === undefined) {
expect(wrapper.emitted(event)).toBeUndefined()
} else {
expect(wrapper.emitted(event)).toEqual([[payload]])
}
}
})
}
type FileListRowProps = InstanceType<typeof FileListRow>['$props']

const node = new File({
owner: 'alice',
Expand Down Expand Up @@ -222,3 +185,62 @@ describe('FilePicker: FileListRow', () => {
})
})
})

/**
* Helper function to test the emitted events when submitting a node (file or folder)
*
* @param name - the name of the test case
* @param propsData - the props to pass to the FileListRow component
* @param eventPayload - the expected emitted events and their payloads
* @param actionCallback - the action to perform to submit the node
*/
function testSubmitNode(name: string, propsData: FileListRowProps, eventPayload: ElementEvent, actionCallback: SubmitAction) {
it(name, async () => {
const wrapper = shallowMount(FileListRow as any, {
propsData,
stubs: {
NcCheckboxRadioSwitch: {
template: '<label><input type="checkbox" @click="$emit(\'update:model-value\', true)" ></label>',
},
},
})

await actionCallback(wrapper)

for (const [event, payload] of Object.entries(eventPayload)) {
if (payload === undefined) {
expect(wrapper.emitted(event)).toBeUndefined()
} else {
expect(wrapper.emitted(event)).toEqual([[payload]])
}
}
})
}

/**
* Click on the checkbox element
*
* @param wrapper - the wrapper of the FileListRow component
*/
async function clickCheckboxAction(wrapper: Wrapper<any>) {
wrapper.find('input[type="checkbox"]').trigger('click')
}

/**
* Click on the row element
*
* @param wrapper - the wrapper of the FileListRow component
*/
async function clickElementAction(wrapper: Wrapper<any>) {
wrapper.find('[data-testid="row-name"]').trigger('click')
}

/**
* Press Enter key on the row element
*
* @param wrapper - the wrapper of the FileListRow component
*/
async function pressEnterAction(wrapper: Wrapper<any>) {
wrapper.element.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'Enter' }))
await nextTick()
}
3 changes: 1 addition & 2 deletions lib/public-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { ComponentProps } from 'vue-component-type-helpers'
import { defineAsyncComponent } from 'vue'
import { spawnDialog } from '@nextcloud/vue/functions/dialog'

import type PublicAuthPrompt from './components/PublicAuthPrompt.vue'

type PublicAuthPromptProps = ComponentProps<typeof PublicAuthPrompt>
type PublicAuthPromptProps = InstanceType<typeof PublicAuthPrompt>['$props']

/**
* Show the public auth prompt dialog
Expand Down
Loading