Skip to content

Commit 03ee467

Browse files
committed
chore: add hotkeys cypress tests
Signed-off-by: skjnldsv <[email protected]>
1 parent d2fef17 commit 03ee467

File tree

2 files changed

+68
-33
lines changed

2 files changed

+68
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* eslint-disable no-unused-expressions */
2+
/**
3+
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
4+
* SPDX-License-Identifier: AGPL-3.0-or-later
5+
*/
6+
// dist file might not be built when running eslint only
7+
// eslint-disable-next-line import/no-unresolved,n/no-missing-import
8+
import { Folder, Permission, addNewFileMenuEntry, type Entry } from '@nextcloud/files'
9+
import { generateRemoteUrl } from '@nextcloud/router'
10+
import { UploadPicker } from '../../../lib/index.ts'
11+
import type { ComponentPublicInstance } from 'vue'
12+
13+
describe('UploadPicker: hotkeys testing', () => {
14+
const propsData = {
15+
content: () => [],
16+
destination: new Folder({
17+
id: 56,
18+
owner: 'user',
19+
source: generateRemoteUrl('dav/files/user/Folder'),
20+
permissions: Permission.ALL,
21+
root: '/files/user',
22+
}),
23+
}
24+
25+
before(() => {
26+
addNewFileMenuEntry({
27+
id: 'test',
28+
displayName: 'Test',
29+
iconSvgInline: '<svg></svg>',
30+
handler: (...args) => console.debug(args),
31+
} as Entry)
32+
})
33+
34+
it('opens the upload menu when pressing u', () => {
35+
cy.mount(UploadPicker, { propsData })
36+
37+
// Check and init aliases
38+
cy.get('[data-cy-upload-picker] [data-cy-upload-picker-input]').as('input').should('exist')
39+
cy.get('[data-cy-upload-picker] .upload-picker__progress').as('progress').should('exist')
40+
41+
cy.get('[role="menu"]').should('not.exist')
42+
43+
cy.get('body').type('u')
44+
cy.get('[role="menu"]').should('be.visible')
45+
})
46+
47+
it('closes the upload menu when pressing escape', () => {
48+
cy.mount(UploadPicker, { propsData })
49+
.then(({ component }) => {
50+
// force the menu to be opened
51+
component.openedMenu = true
52+
})
53+
54+
cy.get('[data-cy-upload-picker] [data-cy-upload-picker-input]').as('input').should('exist')
55+
cy.get('[data-cy-upload-picker] .upload-picker__progress').as('progress').should('exist')
56+
57+
cy.get('[role="menu"]').should('be.visible')
58+
59+
cy.get('body').type('{esc}')
60+
cy.get('[role="menu"]').should('not.be.visible')
61+
})
62+
})

cypress/support/component.ts

+6-33
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,11 @@ window._oc_capabilities = { files: {} }
3232

3333
// Example use:
3434
// cy.mount(MyComponent)
35-
Cypress.Commands.add('mount', (component, optionsOrProps) => {
36-
let instance = null
35+
Cypress.Commands.add('mount', (component, options = {}) => {
36+
// Setup options object
37+
options.extensions = options.extensions || {}
38+
options.extensions.plugins = options.extensions.plugins || []
39+
options.extensions.components = options.extensions.components || {}
3740

38-
// Add our mounted method to expose the component instance to cypress
39-
40-
// Support old vue 2 options
41-
if (component.options) {
42-
if (!component.options.mounted) {
43-
component.options.mounted = []
44-
}
45-
component.options.mounted.push(function() {
46-
instance = this
47-
})
48-
}
49-
50-
// Support new vue 3 options
51-
if (typeof component?.mounted !== 'function') {
52-
component.mounted = function() {
53-
instance = this
54-
}
55-
} else {
56-
// If the component already has a mounted method, we need to chain them
57-
const originalMounted = component.mounted
58-
component.mounted = function() {
59-
originalMounted.call(this)
60-
instance = this
61-
}
62-
}
63-
64-
// Expose the component with cy.get('@component')
65-
const mounted = mount(component, optionsOrProps).then(() => {
66-
cy.wrap(instance).as('component')
67-
return mounted
68-
})
41+
return mount(component, options)
6942
})

0 commit comments

Comments
 (0)