Skip to content

Commit

Permalink
add cypress test for PreviewOptions
Browse files Browse the repository at this point in the history
Signed-off-by: grnd-alt <salimbelakkaf@outlook.de>
  • Loading branch information
grnd-alt committed Mar 28, 2024
1 parent 3be23e5 commit 986cc8c
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 28 deletions.
64 changes: 64 additions & 0 deletions cypress/e2e/nodes/PreviewOptions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @copyright Copyright (c) 2022
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { initUserAndFiles, randUser } from '../../utils/index.js'

const user = randUser()

describe('Preview Options', function() {
before(function() {
initUserAndFiles(user, 'codeblock.md', 'empty.md')
})
beforeEach(function() {
cy.login(user)
cy.isolateTest({ sourceFile: 'empty.md' })
cy.openFile('empty.md')
cy.get('.entry-action__insert-link').click()
cy.get('li').get('[data-text-action-entry="insert-link-website"]').click()
cy.get('.input-field__input--trailing-icon').type('nextcloud.com')
cy.get('.input-field__trailing-button').click()
cy.get('.preview-options').click()
})

it('should render previewOptions correctly', function() {
cy.get('.action-button__text').contains('Remove link').should('be.visible')
cy.get('.action-radio__label').each(el => {
cy.wrap(el).invoke('text').should('match', /Text only|Show link preview/)
})
})

it('should toggle to Link Preview', function() {
cy.get('.preview').should('not.exist')
cy.get('.action-radio__label').each(el => {
cy.wrap(el).invoke('text').then(text => {
if (text === 'Show link preview') {
cy.wrap(el).click()
}
})
})
cy.get('.preview').should('be.visible')
})

it('should Remove link', function() {
cy.get('.paragraph-content').should('have.text', 'nextcloud.com')
cy.get('.action-button__text').contains('Remove link').click()
cy.get('.paragraph-content').should('not.have.text', 'nextcloud.com')
})
})
59 changes: 31 additions & 28 deletions src/components/Editor/PreviewOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,39 @@
-
-->
<template>
<NcActions data-text-preview-options="select"
@open="$emit('open')">
<template #icon>
<DotsVerticalIcon :size="20" />
</template>
<NcActionCaption :name="t('text', 'Preview options')" />
<NcActionRadio data-text-preview-option="text-only"
close-after-click
name="preview-option"
value="text-only"
:checked="value === 'text-only'"
@change="e => $emit('update:value', e.currentTarget.value)">
{{ t('text', 'Text only') }}
</NcActionRadio>
<NcActionRadio data-text-preview-option="link-preview"
close-after-click
name="preview-option"
value="link-preview"
:checked="value === 'link-preview'"
@change="e => $emit('update:value', e.currentTarget.value)">
{{ t('text', 'Show link preview') }}
</NcActionRadio>
<NcActionSeparator />
<NcActionButton @click="e => $emit('update:value', 'delete-preview')">
<div>
<NcActions data-text-preview-options="select"
class="preview-options"
@open="$emit('open')">
<template #icon>
<DeleteIcon :size="20" />
<DotsVerticalIcon :size="20" />
</template>
{{ t('text','Remove link') }}
</NcActionButton>
</NcActions>
<NcActionCaption :name="t('text', 'Preview options')" />
<NcActionRadio data-text-preview-option="text-only"
close-after-click
name="preview-option"
value="text-only"
:checked="value === 'text-only'"
@change="e => $emit('update:value', e.currentTarget.value)">
{{ t('text', 'Text only') }}
</NcActionRadio>
<NcActionRadio data-text-preview-option="link-preview"
close-after-click
name="preview-option"
value="link-preview"
:checked="value === 'link-preview'"
@change="e => $emit('update:value', e.currentTarget.value)">
{{ t('text', 'Show link preview') }}
</NcActionRadio>
<NcActionSeparator />
<NcActionButton @click="e => $emit('update:value', 'delete-preview')">
<template #icon>
<DeleteIcon :size="20" />
</template>
{{ t('text','Remove link') }}
</NcActionButton>
</NcActions>
</div>
</template>

<script>
Expand Down

0 comments on commit 986cc8c

Please sign in to comment.