Skip to content

Commit

Permalink
Merge pull request #48725 from nextcloud/chore/remove-old-test
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Oct 29, 2024
2 parents 9aec7b9 + d84600a commit ce2e1a0
Show file tree
Hide file tree
Showing 35 changed files with 639 additions and 471 deletions.
1 change: 1 addition & 0 deletions __tests__/setup-testing-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
* SPDX-License-Identifier: CC0-1.0
*/
import '@testing-library/jest-dom/vitest'
import 'core-js/stable/index.js'
123 changes: 123 additions & 0 deletions apps/federatedfilesharing/src/components/RemoteShareDialog.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import RemoteShareDialog from './RemoteShareDialog.vue'

describe('RemoteShareDialog', () => {
it('can be mounted', () => {
cy.mount(RemoteShareDialog, {
propsData: {
owner: 'user123',
name: 'my-photos',
remote: 'nextcloud.local',
passwordRequired: false,
},
})

cy.findByRole('dialog')
.should('be.visible')
.and('contain.text', 'user123@nextcloud.local')
.and('contain.text', 'my-photos')
cy.findByRole('button', { name: 'Cancel' })
.should('be.visible')
cy.findByRole('button', { name: /add remote share/i })
.should('be.visible')
})

it('does not show password input if not enabled', () => {
cy.mount(RemoteShareDialog, {
propsData: {
owner: 'user123',
name: 'my-photos',
remote: 'nextcloud.local',
passwordRequired: false,
},
})

cy.findByRole('dialog')
.should('be.visible')
.find('input[type="password"]')
.should('not.exist')
})

it('emits true when accepted', () => {
const onClose = cy.spy().as('onClose')

cy.mount(RemoteShareDialog, {
listeners: {
close: onClose,
},
propsData: {
owner: 'user123',
name: 'my-photos',
remote: 'nextcloud.local',
passwordRequired: false,
},
})

cy.findByRole('button', { name: 'Cancel' }).click()
cy.get('@onClose')
.should('have.been.calledWith', false)
})

it('show password input if needed', () => {
cy.mount(RemoteShareDialog, {
propsData: {
owner: 'admin',
name: 'secret-data',
remote: 'nextcloud.local',
passwordRequired: true,
},
})

cy.findByRole('dialog')
.should('be.visible')
.find('input[type="password"]')
.should('be.visible')
})

it('emits the submitted password', () => {
const onClose = cy.spy().as('onClose')

cy.mount(RemoteShareDialog, {
listeners: {
close: onClose,
},
propsData: {
owner: 'admin',
name: 'secret-data',
remote: 'nextcloud.local',
passwordRequired: true,
},
})

cy.get('input[type="password"]')
.type('my password{enter}')
cy.get('@onClose')
.should('have.been.calledWith', true, 'my password')
})

it('emits no password if cancelled', () => {
const onClose = cy.spy().as('onClose')

cy.mount(RemoteShareDialog, {
listeners: {
close: onClose,
},
propsData: {
owner: 'admin',
name: 'secret-data',
remote: 'nextcloud.local',
passwordRequired: true,
},
})

cy.get('input[type="password"]')
.type('my password')
cy.findByRole('button', { name: 'Cancel' }).click()
cy.get('@onClose')
.should('have.been.calledWith', false)
})
})
67 changes: 67 additions & 0 deletions apps/federatedfilesharing/src/components/RemoteShareDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!--
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<script setup lang="ts">
import { t } from '@nextcloud/l10n'
import { computed, ref } from 'vue'
import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js'
import NcPasswordField from '@nextcloud/vue/dist/Components/NcPasswordField.js'

const props = defineProps<{
/** Name of the share */
name: string
/** Display name of the owner */
owner: string
/** The remote instance name */
remote: string
/** True if the user should enter a password */
passwordRequired: boolean
}>()

const emit = defineEmits<{
(e: 'close', state: boolean, password?: string): void
}>()

const password = ref('')

/**
* The dialog buttons
*/
const buttons = computed(() => [
{
label: t('federatedfilesharing', 'Cancel'),
callback: () => emit('close', false),
},
{
label: t('federatedfilesharing', 'Add remote share'),
nativeType: props.passwordRequired ? 'submit' : undefined,
type: 'primary',
callback: () => emit('close', true, password.value),
},
])
</script>

<template>
<NcDialog :buttons="buttons"
:is-form="passwordRequired"
:name="t('federatedfilesharing', 'Remote share')"
@submit="emit('close', true, password)">
<p>
{{ t('federatedfilesharing', 'Do you want to add the remote share {name} from {owner}@{remote}?', { name, owner, remote }) }}
</p>
<NcPasswordField v-if="passwordRequired"
class="remote-share-dialog__password"
:label="t('federatedfilesharing', 'Remote share password')"
:value.sync="password" />
</NcDialog>
</template>

<style scoped lang="scss">
.remote-share-dialog {

&__password {
margin-block: 1em .5em;
}
}
</style>
Loading

0 comments on commit ce2e1a0

Please sign in to comment.