Last active
June 18, 2021 19:55
-
-
Save sneridagh/75212d81d8bbb28a49540bb5c69f2574 to your computer and use it in GitHub Desktop.
Slate editor Cypress test, selecting and existing one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context('Blocks Acceptance Tests', () => { | |
beforeEach(() => { | |
cy.visit('/'); | |
cy.setCookie('lang', 'de'); | |
cy.createContent({ | |
contentType: 'Document', | |
contentId: 'document', | |
contentTitle: 'Document', | |
path: '/de', | |
}); | |
cy.autologin(); | |
}); | |
it('As editor I can add a link to a text block', function () { | |
cy.visit('/document/edit'); | |
// Complete chained commands | |
cy.get('.slate-editor [contenteditable=true]') | |
.focus() | |
.click() | |
.wait(1000) | |
.type('Colorless green ideas sleep furiously.'); | |
cy.get('.slate-editor.selected [contenteditable=true]').setSelection( | |
'furiously', | |
); | |
// This also works | |
cy.get('.slate-editor [contenteditable=true]') | |
.focus() | |
.click() | |
.wait(1000) | |
.type('Colorless green ideas sleep furiously.') | |
.setSelection('furiously'); | |
// As a function | |
const getSlateEditorAndType = (selector, type) => { | |
return cy.get(selector).focus().click().wait(1000).type(type); | |
}; | |
getSlateEditorAndType( | |
'.slate-editor [contenteditable=true]', | |
'Colorless green ideas sleep furiously.', | |
).setSelection('furiously'); | |
cy.get('.slate-inline-toolbar .button-wrapper:nth-of-type(3)').click(); | |
cy.get('.link-form-container input').type('https://google.com{enter}'); | |
cy.get('#toolbar-save').click(); | |
cy.url().should('eq', Cypress.config().baseUrl + '/document'); | |
cy.waitForResourceToLoad('@navigation'); | |
cy.waitForResourceToLoad('@breadcrumbs'); | |
cy.waitForResourceToLoad('@actions'); | |
cy.waitForResourceToLoad('@types'); | |
cy.waitForResourceToLoad('document'); | |
// then the page view should contain a link | |
cy.get('.ui.container p').contains( | |
'Colorless green ideas sleep furiously.', | |
); | |
cy.get('.ui.container p a') | |
.should('have.attr', 'href') | |
.and('include', 'https://google.com'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment