Skip to content

Commit

Permalink
feat: add cypress test
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <[email protected]>
  • Loading branch information
luka-nextcloud committed Mar 29, 2023
1 parent f386675 commit 13b3fa2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
30 changes: 29 additions & 1 deletion cypress/e2e/workspace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('Workspace', function() {
})

it('adds a Readme.md', function() {
const url = '**/remote.php/dav/files/**'

cy.intercept({ method: 'PUT', url })
.as('addDescription')

Expand Down Expand Up @@ -152,6 +152,33 @@ describe('Workspace', function() {
})
})

it('creates table and add multilines', function() {
cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`)
cy.openWorkspace()
.type('Hello !');

const tag = 'table'
const multilinesContent = `Line 1\nLine 2\nLine 3`

cy.getMenuEntry(tag)
.click()
.should('have.class', 'is-active')

cy.getContent()
.find(`${tag}`).should('be.visible')

cy.get('#rich-workspace .ProseMirror')
.get('table:nth-of-type(1) tr:nth-child(2) td:nth-child(1)')
.click()
.type(multilinesContent)

cy.getEditor()
.find('table:nth-of-type(1) tr:nth-child(2) td:nth-child(1) .content')
.then(($el) => {
expect($el.get(0).innerHTML).to.equal(multilinesContent.replace(/\n/g, '<br>'))
})
})

it('takes README.md into account', function() {
cy.uploadFile('test.md', 'text/markdown', `${Cypress.currentTest.title}/README.md`)
cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`)
Expand Down Expand Up @@ -332,6 +359,7 @@ describe('Workspace', function() {
checkContent()
})
})

})

const openSidebar = filename => {
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/Table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import TableCell from './TableCell.js'
import TableHeader from './TableHeader.js'
import TableHeadRow from './TableHeadRow.js'
import TableRow from './TableRow.js'
import { Plugin, TextSelection } from '@tiptap/pm/state'
import { TextSelection } from '@tiptap/pm/state'
import {
addRowAfter,
addRowBefore,
Expand Down
9 changes: 6 additions & 3 deletions src/nodes/Table/TableCell.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TableCell } from '@tiptap/extension-table-cell'
import { Plugin } from '@tiptap/pm/state'
import { Fragment } from '@tiptap/pm/model'
import { Node, Slice, Fragment } from '@tiptap/pm/model'

export default TableCell.extend({
content: 'inline*',
Expand Down Expand Up @@ -37,15 +37,18 @@ export default TableCell.extend({
return [
new Plugin({
props: {
// Special-treat empty lines in pasted content to prevent jumping out of cell
handlePaste: (view, event, slice) => {
if (slice.content.childCount > 1) {
const state = view.state
const childCount = slice.content.childCount
const childNodes = []
for (let i = 0; i < slice.content.childCount; i++) {
if (i) {
for (let i = 0; i < childCount; i++) {
if (i === 0) {
childNodes.push(state.schema.text('\n'))
}

// Ignore empty children (i.e. empty lines)
if (!slice.content.child(i).firstChild) {
continue
}
Expand Down

0 comments on commit 13b3fa2

Please sign in to comment.