Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ jobs:
ref: ${{ matrix.server-versions }}
path: apps/viewer

- name: Checkout assistant
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
repository: nextcloud/assistant
ref: 'main'
path: apps/assistant

- name: Checkout app
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
Expand Down Expand Up @@ -69,6 +76,13 @@ jobs:
npm ci
TESTING=true npm run build --if-present

- name: Install dependencies & build assistant
working-directory: apps/assistant
run: |
composer install --no-dev
npm ci
npm run build

- name: Save context
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
Expand Down Expand Up @@ -142,6 +156,8 @@ jobs:
php occ user:add --password-from-env user2
php occ app:enable viewer
php occ app:enable text
php occ app:enable assistant
php occ app:enable testing
php occ app:list
php occ background:cron
php occ config:system:set session_keepalive --value=false --type=boolean
Expand Down
76 changes: 76 additions & 0 deletions cypress/e2e/Assistant.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { initUserAndFiles, randUser } from '../utils/index.js'

const currentUser = randUser()

const fileName = 'empty.md'

describe('Assistant', () => {
before(() => {
initUserAndFiles(currentUser, fileName)
})

beforeEach(() => {
cy.login(currentUser)
cy.visit('/apps/files')
})

it('See assistant button', () => {
cy.isolateTest({
sourceFile: fileName,
})
cy.openFile(fileName, { force: true })

cy.getContent()
.click({ force: true })

cy.get('[data-cy="assistantMenu"]')
.should('be.visible')

cy.get('[data-cy="assistantMenu"]')
.click()

cy.get('.action-item__popper ul').children().should(($children) => {
const entries = $children.find('button').map((i, el) => el.innerText).get()
expect(entries.length).to.be.greaterThan(0)
expect('Free prompt').to.be.oneOf(entries)
expect('Translate').to.be.oneOf(entries)
expect('Show assistant results').to.be.oneOf(entries)
})
})

it('Send free prompt request', () => {
cy.isolateTest({
sourceFile: fileName,
})
cy.openFile(fileName, { force: true })

cy.getContent()
.click({ force: true })
cy.get('[data-cy="assistantMenu"]')
.click()
cy.get('.action-item__popper ul li').first()
.click()

cy.get('.assistant-modal--content #input-prompt')
.should('be.visible')

cy.get('.assistant-modal--content #input-prompt')
.type('Hello World')
cy.get('.assistant-modal--content .submit-button')
.click()

// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(2000)

cy.get('.assistant-modal--content .close-button')
.click()
cy.get('[data-cy="assistantMenu"]')
.click()
cy.get('.action-item__popper ul li').last()
.click()

cy.get('.modal-container__content .task-list')
.should('be.visible')
.should('contain', 'Hello World')
})
})
4 changes: 3 additions & 1 deletion cypress/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ if [ $? -eq 0 ]; then
php /var/www/html/occ user:add --password-from-env user2
php /var/www/html/occ app:enable viewer
php /var/www/html/occ app:enable text
php /var/www/html/occ app:enable assistant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was for some way of running isolated cypress tests locally, but never used that script myself. @max-nextcloud Do you happen to know if we still make use of that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember it. Looking at the log of that file indicates that it was introduced by @susnux in f62c29b.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was just for local tests, but nowadays we could use @nextcloud/cypress/docker which also works locally :)

php /var/www/html/occ app:enable testing
php /var/www/html/occ app:list
"
fi

exec $@
exec $@
2 changes: 1 addition & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
use OCA\Text\Middleware\SessionMiddleware;
use OCA\Text\Notification\Notifier;
use OCA\Text\Service\ConfigService;
use OCA\TPAssistant\Event\BeforeAssistantNotificationEvent;
use OCA\TpAssistant\Event\BeforeAssistantNotificationEvent;
use OCA\Viewer\Event\LoadViewer;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
Expand Down
2 changes: 1 addition & 1 deletion lib/Listeners/BeforeAssistantNotificationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace OCA\Text\Listeners;

use OCA\Text\AppInfo\Application;
use OCA\TPAssistant\Event\BeforeAssistantNotificationEvent;
use OCA\TpAssistant\Event\BeforeAssistantNotificationEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IURLGenerator;
Expand Down
41 changes: 36 additions & 5 deletions src/components/Assistant.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
:editor="$editor"
:tippy-options="floatingOptions()"
:should-show="floatingShow"
class="floating-menu">
class="floating-menu"
data-cy="assistantMenu">
<NcActions :title="t('text', 'Nextcloud Assistant')" :type="'secondary'">
<template #icon>
<CreationIcon :size="20" class="icon" />
Expand Down Expand Up @@ -154,6 +155,7 @@ import {
} from './Editor.provider.js'
import { FloatingMenu } from '@tiptap/vue-2'
import Translate from './Modal/Translate.vue'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'

const limitInRange = (num, min, max) => {
return Math.min(Math.max(parseInt(num), parseInt(min)), parseInt(max))
Expand Down Expand Up @@ -241,15 +243,15 @@ export default {

this.$editor.on('selectionUpdate', this.onSelection)
this.fetchTasks()
this.$interval = setInterval(() => this.fetchTasks(), 60 * 1000)
subscribe('notifications:notification:received', this.checkNotification)
},
beforeDestroy() {
if (!this.showAssistant) {
return
}

this.$editor.off('selectionUpdate', this.onSelection)
clearInterval(this.$interval)
unsubscribe('notifications:notification:received', this.checkNotification)
},
methods: {
async fetchTasks() {
Expand All @@ -268,6 +270,12 @@ export default {
}
}).sort((a, b) => b.id - a.id)
},
async checkNotification(event) {
if (event.notification.app !== 'assistant' || event.notification.actions[0].type !== 'WEB') {
return
}
await this.fetchTasks()
},
onSelection() {
const { state } = this.$editor
const { from, to } = state.selection
Expand All @@ -281,6 +289,17 @@ export default {
taskType,
input: this.selection,
isInsideViewer: true,
closeOnResult: false,
actionButtons: [
{
type: 'primary',
title: t('text', 'Insert result'),
label: t('text', 'Insert result'),
onClick: (lastTask) => {
this.insertResult(lastTask)
},
},
],
})
await this.fetchTasks()
},
Expand Down Expand Up @@ -344,11 +363,23 @@ export default {
getReferenceClientRect: () => {
const editorRect = this.$parent.$el.querySelector('.ProseMirror').getBoundingClientRect()
const pos = posToDOMRect(this.$editor.view, this.$editor.state.selection.from, this.$editor.state.selection.to)
let rightSpacing = 0
let addTopSpacing = 0

if (editorRect.width < 670) {
rightSpacing = 20
}

if (editorRect.width < 425) {
rightSpacing = 66
addTopSpacing = 30
}

return {
...pos,
width: editorRect.width,
width: editorRect.width - rightSpacing,
height: limitInRange(pos.height, buttonSize, window.innerHeight),
top: limitInRange(pos.top, topSpacing, window.innerHeight - bottomSpacing),
top: limitInRange(pos.top, topSpacing, window.innerHeight - bottomSpacing) + addTopSpacing,
left: editorRect.left,
right: editorRect.right,
bottom: limitInRange(pos.top + buttonSize, bottomSpacing, window.innerHeight - topSpacing) + 22,
Expand Down
2 changes: 1 addition & 1 deletion tests/stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract public function getShare(): \OCP\Share\IShare;
}
}

namespace OCA\TPAssistant\Event {
namespace OCA\TpAssistant\Event {

use OCP\TextProcessing\Task;

Expand Down