test(experiments): adds test for collaboration annotation examples
This commit is contained in:
committed by
Dominik
parent
528ba5d71c
commit
c4eaf31b12
@@ -1,7 +1,59 @@
|
|||||||
context('/src/Experiments/Annotation/Vue/', () => {
|
context('/src/Experiments/CollaborationAnnotation/Vue/', () => {
|
||||||
before(() => {
|
before(() => {
|
||||||
cy.visit('/src/Experiments/Annotation/Vue/')
|
cy.visit('/src/Experiments/CollaborationAnnotation/Vue/')
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: Write tests
|
it('renders two editors', () => {
|
||||||
|
cy.get('.ProseMirror').should('have.length', 2)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sets an annotation in editor 1 and shows annotations in both editors', () => {
|
||||||
|
cy.window().then(win => {
|
||||||
|
cy.stub(win, 'prompt', () => 'This is a test comment')
|
||||||
|
cy.get('.editor-1 .ProseMirror').type('{selectall}{backspace}Hello world{selectall}')
|
||||||
|
cy.get('button').contains('comment').eq(0).click()
|
||||||
|
cy.get('.editor-1 .ProseMirror').type('{end}')
|
||||||
|
cy.get('.ProseMirror .annotation').should('have.length', 2)
|
||||||
|
cy.get('.comment').should('exist').contains('This is a test comment')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('updates an existing annotation', () => {
|
||||||
|
let commentIndex = 0
|
||||||
|
cy.window().then(win => {
|
||||||
|
cy.stub(win, 'prompt', () => {
|
||||||
|
switch (commentIndex) {
|
||||||
|
case 0:
|
||||||
|
commentIndex += 1
|
||||||
|
return 'This is a test comment'
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
commentIndex += 1
|
||||||
|
return 'This is the new comment'
|
||||||
|
|
||||||
|
default:
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
cy.get('.editor-1 .ProseMirror').type('{selectall}{backspace}Hello world{selectall}')
|
||||||
|
cy.get('button').contains('comment').eq(0).click()
|
||||||
|
cy.get('.comment').should('exist').contains('This is a test comment')
|
||||||
|
cy.get('button').contains('update').click()
|
||||||
|
cy.get('.comment').should('exist').contains('This is the new comment')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('deletes an existing annotation', () => {
|
||||||
|
cy.window().then(win => {
|
||||||
|
cy.stub(win, 'prompt', () => 'This is a test comment')
|
||||||
|
|
||||||
|
cy.get('.editor-1 .ProseMirror').type('{selectall}{backspace}Hello world{selectall}')
|
||||||
|
cy.get('button').contains('comment').eq(0).click()
|
||||||
|
cy.get('.comment').should('exist').contains('This is a test comment')
|
||||||
|
cy.get('button').contains('remove').click()
|
||||||
|
cy.get('.ProseMirror .annotation').should('not.exist')
|
||||||
|
cy.get('.comment').should('not.exist')
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
<button @click="addComment" :disabled="!editor.can().addAnnotation()">
|
<button @click="addComment" :disabled="!editor.can().addAnnotation()">
|
||||||
comment
|
comment
|
||||||
</button>
|
</button>
|
||||||
<editor-content :editor="editor" />
|
<editor-content class="editor-1" :editor="editor" />
|
||||||
<div v-for="comment in comments" :key="comment.id">
|
<div class="comment" v-for="comment in comments" :key="comment.id">
|
||||||
{{ comment }}
|
{{ comment }}
|
||||||
|
|
||||||
<button @click="updateComment(comment.id)">
|
<button @click="updateComment(comment.id)">
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
<button @click="addAnotherComment" :disabled="!anotherEditor.can().addAnnotation()">
|
<button @click="addAnotherComment" :disabled="!anotherEditor.can().addAnnotation()">
|
||||||
comment
|
comment
|
||||||
</button>
|
</button>
|
||||||
<editor-content :editor="anotherEditor" />
|
<editor-content class="editor-2" :editor="anotherEditor" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -52,12 +52,11 @@ export default {
|
|||||||
editor: null,
|
editor: null,
|
||||||
anotherEditor: null,
|
anotherEditor: null,
|
||||||
comments: [],
|
comments: [],
|
||||||
ydoc: new Y.Doc(),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.ydoc = new Y.Doc()
|
const ydoc = new Y.Doc()
|
||||||
|
|
||||||
this.editor = new Editor({
|
this.editor = new Editor({
|
||||||
extensions: [
|
extensions: [
|
||||||
@@ -67,12 +66,12 @@ export default {
|
|||||||
Bold,
|
Bold,
|
||||||
Heading,
|
Heading,
|
||||||
CollaborationAnnotation.configure({
|
CollaborationAnnotation.configure({
|
||||||
document: this.ydoc,
|
document: ydoc,
|
||||||
onUpdate: items => { this.comments = items },
|
onUpdate: items => { this.comments = items },
|
||||||
instance: 'editor1',
|
instance: 'editor1',
|
||||||
}),
|
}),
|
||||||
Collaboration.configure({
|
Collaboration.configure({
|
||||||
document: this.ydoc,
|
document: ydoc,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
content: `
|
content: `
|
||||||
@@ -93,11 +92,11 @@ export default {
|
|||||||
Bold,
|
Bold,
|
||||||
Heading,
|
Heading,
|
||||||
CollaborationAnnotation.configure({
|
CollaborationAnnotation.configure({
|
||||||
document: this.ydoc,
|
document: ydoc,
|
||||||
instance: 'editor2',
|
instance: 'editor2',
|
||||||
}),
|
}),
|
||||||
Collaboration.configure({
|
Collaboration.configure({
|
||||||
document: this.ydoc,
|
document: ydoc,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user