|
| 1 | +import { initUserAndFiles, randHash } from '../utils/index.js' |
| 2 | +import 'cypress-file-upload' |
| 3 | + |
| 4 | +const randUser = randHash() |
| 5 | +const randUser1 = randHash() |
| 6 | +const currentUser = randUser |
| 7 | + |
| 8 | +const refresh = () => { |
| 9 | + cy.get('.files-controls .crumb:not(.hidden) a') |
| 10 | + .last() |
| 11 | + .click({ force: true }) |
| 12 | +} |
| 13 | + |
| 14 | +const createFileWithMention = (target, userToMention) => { |
| 15 | + const mimeType = 'text/markdown' |
| 16 | + const content = `Hello @[${userToMention}](mention://user/${userToMention})` |
| 17 | + cy.createFile(target, content, mimeType) |
| 18 | + .then(refresh) |
| 19 | +} |
| 20 | + |
| 21 | +describe('Test mentioning users', () => { |
| 22 | + before(() => { |
| 23 | + initUserAndFiles(randUser, 'test.md') |
| 24 | + cy.nextcloudCreateUser(randUser1, 'password') |
| 25 | + }) |
| 26 | + |
| 27 | + beforeEach(() => { |
| 28 | + cy.login(currentUser, 'password') |
| 29 | + }) |
| 30 | + |
| 31 | + it('Type @ and see the user list', () => { |
| 32 | + const requestAlias = 'fetchUsersList' |
| 33 | + cy.intercept({ method: 'POST', url: '**/users' }).as(requestAlias) |
| 34 | + |
| 35 | + cy.openFile('test.md') |
| 36 | + cy.get('.text-editor__content div[contenteditable="true"]') |
| 37 | + .clear() |
| 38 | + .type(`@${randUser1.substring(0, 3)}`) |
| 39 | + |
| 40 | + return cy.wait(`@${requestAlias}`) |
| 41 | + .then(() => { |
| 42 | + cy.get('.tippy-box .items').children().should(($children) => { |
| 43 | + const users = $children.map((i, el) => el.innerText).get() |
| 44 | + expect(users.length).to.be.greaterThan(0) |
| 45 | + expect(randUser1).to.be.oneOf(users) |
| 46 | + }) |
| 47 | + }) |
| 48 | + }) |
| 49 | + |
| 50 | + it('Select a user will insert the mention', () => { |
| 51 | + const autocompleteReauestAlias = 'fetchUsersList' |
| 52 | + cy.intercept({ method: 'POST', url: '**/users' }).as(autocompleteReauestAlias) |
| 53 | + |
| 54 | + cy.openFile('test.md') |
| 55 | + cy.get('.text-editor__content div[contenteditable="true"]') |
| 56 | + .clear() |
| 57 | + .type(`@${randUser1.substring(0, 3)}`) |
| 58 | + |
| 59 | + return cy.wait(`@${autocompleteReauestAlias}`) |
| 60 | + .then(() => { |
| 61 | + cy.get('.tippy-box .items').contains(randUser1).click() |
| 62 | + cy.get('span.mention').contains(randUser1).should('be.visible') |
| 63 | + }) |
| 64 | + }) |
| 65 | + |
| 66 | + it(' Open a document with an existing mention and properly see the user bubble rendered', () => { |
| 67 | + const mentionFilename = 'mention.md' |
| 68 | + createFileWithMention(mentionFilename, randUser1) |
| 69 | + cy.openFile(mentionFilename) |
| 70 | + cy.get('.text-editor__content div[contenteditable="true"] span.mention') |
| 71 | + .contains(randUser1) |
| 72 | + .should('be.visible') |
| 73 | + }) |
| 74 | +}) |
0 commit comments