Skip to content

Commit

Permalink
improved cypress element selectors according to best practices
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <[email protected]>
  • Loading branch information
elzody committed Feb 21, 2024
1 parent 2e5975e commit e421f44
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cypress/e2e/nodes/CodeBlock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Front matter support', function() {
cy.getContent().find('code').eq(1).find('.hljs-string').eq(0).contains('"bar"')
cy.getContent().find('code').eq(1).find('.hljs-keyword').eq(1).contains('function')

cy.getContent().find('.code-block').eq(1).find('.view-switch > button').click()
cy.getContent().find('.code-block').eq(1).find('[data-cy="copy-code"]').click()

// Copy code to clipboard
cy.getContent().find('code').eq(1).invoke('text')
Expand All @@ -56,7 +56,7 @@ describe('Front matter support', function() {
)

// Remove language
cy.getContent().find('.code-block').eq(1).find('.view-switch div div button').click()
cy.getContent().find('.code-block').eq(1).find('[data-cy="code-action-group"]').find('div:first-child').click()
// FIXME: Label behaviour changed, should be back once https://github.com/nextcloud-libraries/nextcloud-vue/pull/4484 is merged
// cy.get('.action-input__text-label').contains('Code block language')
cy.get('.input-field__input:visible').clear()
Expand All @@ -66,7 +66,7 @@ describe('Front matter support', function() {
cy.getContent().find('code').eq(1).find('.hljs-keyword').should('not.exist')

// Re-add language
cy.getContent().find('.code-block').eq(1).find('.view-switch div div button').click()
cy.getContent().find('.code-block').eq(1).find('[data-cy="code-action-group"]').find('div:first-child').click()
cy.get('.input-field__input:visible').type('javascript')

cy.getContent().find('code').eq(1).find('.hljs-keyword').eq(0).contains('const')
Expand Down
8 changes: 6 additions & 2 deletions src/nodes/CodeBlockView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<div class="view-switch">
<NcActions :aria-label="t('text', 'Copy code block')">
<NcActionButton v-if="hasCode"
data-cy="copy-code"
:aria-label="t('text', 'Copy code')"
:close-after-click="false"
@click="copyCode">
Expand All @@ -15,8 +16,11 @@
</NcActionButton>
</NcActions>

<NcActions v-if="isEditable" :aria-label="t('text', 'Code block options')">
<NcActionInput :label="t('text', 'Code block language')"
<NcActions v-if="isEditable"
data-cy="code-action-group"
:aria-label="t('text', 'Code block options')">
<NcActionInput
:label="t('text', 'Code block language')"
:value="type"
:show-trailing-button="false"
:placeholder="t('text', 'e.g. php, javascript, json…')"
Expand Down

0 comments on commit e421f44

Please sign in to comment.