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
74 changes: 74 additions & 0 deletions cypress/e2e/mentions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { initUserAndFiles, randHash } from '../utils/index.js'
import 'cypress-file-upload'

const randUser = randHash()
const randUser1 = randHash()
const currentUser = randUser

const refresh = () => {
cy.get('.files-controls .crumb:not(.hidden) a')
.last()
.click({ force: true })
}

const createFileWithMention = (target, userToMention) => {
const mimeType = 'text/markdown'
const content = `Hello @[${userToMention}](mention://user/${userToMention})`
cy.createFile(target, content, mimeType)
.then(refresh)
}

describe('Test mentioning users', () => {
before(() => {
initUserAndFiles(randUser, 'test.md')
cy.nextcloudCreateUser(randUser1, 'password')
})

beforeEach(() => {
cy.login(currentUser, 'password')
})

it('Type @ and see the user list', () => {
const requestAlias = 'fetchUsersList'
cy.intercept({ method: 'POST', url: '**/users' }).as(requestAlias)

cy.openFile('test.md')
cy.get('.text-editor__content div[contenteditable="true"]')
.clear()
.type(`@${randUser1.substring(0, 3)}`)

return cy.wait(`@${requestAlias}`)
.then(() => {
cy.get('.tippy-box .items').children().should(($children) => {
const users = $children.map((i, el) => el.innerText).get()
expect(users.length).to.be.greaterThan(0)
expect(randUser1).to.be.oneOf(users)
})
})
})

it('Select a user will insert the mention', () => {
const autocompleteReauestAlias = 'fetchUsersList'
cy.intercept({ method: 'POST', url: '**/users' }).as(autocompleteReauestAlias)

cy.openFile('test.md')
cy.get('.text-editor__content div[contenteditable="true"]')
.clear()
.type(`@${randUser1.substring(0, 3)}`)

return cy.wait(`@${autocompleteReauestAlias}`)
.then(() => {
cy.get('.tippy-box .items').contains(randUser1).click()
cy.get('span.mention').contains(randUser1).should('be.visible')
})
})

it(' Open a document with an existing mention and properly see the user bubble rendered', () => {
const mentionFilename = 'mention.md'
createFileWithMention(mentionFilename, randUser1)
cy.openFile(mentionFilename)
cy.get('.text-editor__content div[contenteditable="true"] span.mention')
.contains(randUser1)
.should('be.visible')
})
})
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/extensions/Mention.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default TipTapMention.extend({
getAttrs: element => {
return {
id: element.getAttribute('data-id'),
label: element.innerText ?? element.getAttribute('data-id'),
label: element.innerText || element.textContent || element.getAttribute('data-label'),
}
},
priority: 100,
Expand Down
8 changes: 8 additions & 0 deletions src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ describe('Markdown though editor', () => {
expect(markdownThroughEditor(entry)).toBe(entry)
})
})

test('mentions', () => {
expect(markdownThroughEditor('@[username](mention://user/id)')).toBe(' @[username](mention://user/id) ')
})
})

describe('Markdown serializer from html', () => {
Expand Down Expand Up @@ -203,6 +207,10 @@ describe('Markdown serializer from html', () => {
// Test --- within front matter is allowed
expect(markdownThroughEditorHtml('<pre id="frontmatter"><code>---</code></pre><h1>Heading</h1>')).toBe('----\n---\n----\n\n# Heading')
})

test('mentions', () => {
expect(markdownThroughEditorHtml('<span class="mention" data-label="username" data-type="user" data-id="id">username</span>')).toBe(' @[username](mention://user/id) ')
})
})

describe('Trailing nodes', () => {
Expand Down