Skip to content

Commit

Permalink
cy: make tests run with both slate and draftjs
Browse files Browse the repository at this point in the history
  • Loading branch information
nileshgulia1 committed Nov 22, 2021
1 parent 9f515c3 commit e51f7a5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
22 changes: 17 additions & 5 deletions cypress/integration/blocks-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,26 @@ describe('Blocks Tests', () => {
cy.get('.accordion:nth-child(3) > .title > .icon').click();
cy.wait(500);

// the cypress test is run without slate, but with draftjs
// the cypress test runs with both slate and draftjs.
cy.get('.accordion:nth-child(3) .content')
.first()
.within(() => {
cy.get('.public-DraftStyleDefault-block:nth-child(1)')
.should('have.value', '')
.invoke('attr', 'tabindex', 1)
.type('children', { delay: 50 });
cy.getIfExists(
'.public-DraftStyleDefault-block:nth-child(1)',
() => {
cy.get('.public-DraftStyleDefault-block:nth-child(1)')
.should('have.value', '')
.invoke('attr', 'tabindex', 1)
.type('children', { delay: 50 });
},
() => {
cy.get('div.text-slate-editor-inner')
.should('have.value', '')
.invoke('attr', 'tabindex', 1)
.click()
.type('children', { delay: 50 });
},
);
});

cy.get('#toolbar-save path').click({ force: true });
Expand Down
14 changes: 14 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,19 @@ function getTextNode(el, match) {
}
}
}
function getIfExists(
selector,
successAction = () => {},
failAction = () => {},
) {
cy.get('div.blocks-form').then((body) => {
if (body.find(selector).length > 0 && successAction) {
successAction();
} else if (failAction) {
failAction();
}
});
}

function setBaseAndExtent(...args) {
const document = args[0].ownerDocument;
Expand All @@ -313,3 +326,4 @@ Cypress.Commands.add('store', () => {
Cypress.Commands.add('settings', (key, value) => {
return cy.window().its('settings');
});
Cypress.Commands.add('getIfExists', getIfExists);

0 comments on commit e51f7a5

Please sign in to comment.