Skip to content

Commit

Permalink
fix cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
nileshgulia1 committed Dec 19, 2022
1 parent dda578e commit c272bda
Showing 1 changed file with 80 additions and 8 deletions.
88 changes: 80 additions & 8 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,111 @@

// Import commands.js using ES2015 syntax:
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')

/* coverage-start
//Generate code-coverage
import '@cypress/code-coverage/support';
coverage-end */

export const setupBeforeEach = () => {
export const slateBeforeEach = (contentType = 'Document') => {
cy.autologin();
cy.createContent({
contentType: 'Document',
contentId: 'cypress',
contentTitle: 'Cypress',
});
cy.createContent({
contentType: 'Document',
contentType: contentType,
contentId: 'my-page',
contentTitle: 'My Page',
path: 'cypress',
});
cy.visit('/cypress/my-page');
//cy.waitForResourceToLoad('@navigation');
cy.waitForResourceToLoad('@navigation');
cy.waitForResourceToLoad('@breadcrumbs');
cy.waitForResourceToLoad('@actions');
cy.waitForResourceToLoad('@types');
cy.waitForResourceToLoad('my-page');
cy.navigate('/cypress/my-page/edit');
cy.get(`.block.title [data-contents]`);
};

export const tearDownAfterEach = () => {
export const slateAfterEach = () => {
cy.autologin();
cy.removeContent('cypress');
};

export const slateJsonBeforeEach = (contentType = 'slate') => {
cy.autologin();
cy.addContentType(contentType);
cy.addSlateJSONField(contentType, 'slate');
slateBeforeEach(contentType);
};

export const slateJsonAfterEach = (contentType = 'slate') => {
cy.autologin();
cy.removeContentType(contentType);
slateAfterEach();
};

export const getSelectedSlateEditor = () => {
return cy.get('.slate-editor.selected [contenteditable=true]').click();
};

export const createSlateBlock = () => {
cy.get('.ui.basic.icon.button.block-add-button').first().click();
cy.get('.blocks-chooser .title').contains('Text').click();
cy.get('.ui.basic.icon.button.slate').contains('Text').click();
return getSelectedSlateEditor();
};

export const getSlateBlockValue = (sb) => {
return sb.invoke('attr', 'data-slate-value').then((str) => {
return typeof str === 'undefined' ? [] : JSON.parse(str);
});
};

export const createSlateBlockWithList = ({
numbered,
firstItemText,
secondItemText,
}) => {
let s1 = createSlateBlock();

s1.typeInSlate(firstItemText + secondItemText);

// select all contents of slate block
// - this opens hovering toolbar
cy.contains(firstItemText + secondItemText).then((el) => {
selectSlateNodeOfWord(el);
});

// TODO: do not hardcode these selectors:
if (numbered) {
// this is the numbered list option in the hovering toolbar
cy.get('.slate-inline-toolbar > :nth-child(9)').click();
} else {
// this is the bulleted list option in the hovering toolbar
cy.get('.slate-inline-toolbar > :nth-child(10)').click();
}

// move the text cursor
const sse = getSelectedSlateEditor();
sse.type('{leftarrow}');
for (let i = 0; i < firstItemText.length; ++i) {
sse.type('{rightarrow}');
}

// simulate pressing Enter
getSelectedSlateEditor().lineBreakInSlate();

return s1;
};

export const selectSlateNodeOfWord = (el) => {
return cy.window().then((win) => {
var event = new CustomEvent('Test_SelectWord', {
detail: el[0],
});
win.document.dispatchEvent(event);
});
};

0 comments on commit c272bda

Please sign in to comment.