Skip to content

Commit

Permalink
fix: focus issue on translate modal, remove duplicate code
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <[email protected]>
  • Loading branch information
luka-nextcloud committed Apr 26, 2024
1 parent 1ca45b2 commit 9e5b885
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
24 changes: 24 additions & 0 deletions cypress/e2e/Assistant.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,28 @@ describe('Assistant', () => {
.should('be.visible')
.should('contain', 'Hello World')
})

it('Open translate dialog', () => {
cy.isolateTest({
sourceFile: fileName,
})
cy.openFile(fileName, { force: true })

cy.getContent()
.click({ force: true })
cy.get('[data-cy="assistantMenu"]')
.click()
cy.get('[data-cy="open-translate"]')
.should('be.visible')
.click()

cy.get('[data-cy="translate-input"]')
.should('be.visible')
.click()
cy.get('[data-cy="translate-input"]')
.should('be.visible')
.type('Hello World')
cy.get('[data-cy="translate-input"]')
.should('be.focused')
})
})
2 changes: 1 addition & 1 deletion cypress/e2e/share.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('Open test.md in viewer', function() {
cy.getModal().getContent().should('contain', 'Hello world')
cy.getModal().getContent().find('h2').should('contain', 'Hello world')
cy.getModal().find('.modal-header button.header-close').click()
cy.get('.modal-mask').should('not.exist')
cy.get('.modal-mask').should('not.be.visible')
// cy.get('#rich-workspace').getContent().should('contain', 'Hello world')
})
})
Expand Down
5 changes: 4 additions & 1 deletion src/components/Assistant.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</template>
{{ provider.name }}
</NcActionButton>
<NcActionButton close-after-click @click="openTranslateDialog">
<NcActionButton data-cy="open-translate" close-after-click @click="openTranslateDialog">
<template #icon>
<TranslateVariant :size="20" />
</template>
Expand Down Expand Up @@ -295,6 +295,9 @@ export default {
await this.fetchTasks()
},
openTranslateDialog() {
if (!this.selection.trim().length) {
this.$editor.commands.selectAll()
}
emit('text:translate-modal:show', { content: this.selection || '' })
},
async openResult(task) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Menu/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
:can-be-focussed="activeMenuEntry === visibleEntries.length"
@click="activeMenuEntry = 'remain'">
<template #lastAction="{ visible }">
<NcActionButton close-after-click v-if="canTranslate" @click="showTranslate">
<NcActionButton v-if="canTranslate" close-after-click @click="showTranslate">
<template #icon>
<TranslateVariant />
</template>
Expand Down
1 change: 1 addition & 0 deletions src/components/Modal/Translate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
:value.sync="input"
:label="t('text', 'Text to translate from')"
autofocus
data-cy="translate-input"
input-class="translate-textarea"
resize="none"
@focus="onInputFocus" />
Expand Down

0 comments on commit 9e5b885

Please sign in to comment.