Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Jul 5, 2021
1 parent cbd8d34 commit 65177e9
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 66 deletions.
22 changes: 22 additions & 0 deletions cypress/helpers/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const save = (path) => {
cy.url().then(($url) => {
if ($url.includes(path)) {
//cy.get('.ui.button.save').click();
cy.get('#toolbar-save').click();
cy.url().should('eq', Cypress.config().baseUrl + path);
} else {
cy.log('Wrong path');
}
});
};

export const cancel = (path) => {
cy.url().then(($url) => {
if ($url.includes(path)) {
cy.get('.ui.button.cancel').click();
cy.url().should('eq', Cypress.config().baseUrl + path);
} else {
cy.log('Wrong path');
}
});
};
38 changes: 32 additions & 6 deletions cypress/helpers/blocks/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
import { openSidebar, closeSidebar } from '../index';

export const changePageTitle = (title) => {
export const changePageTitle = (title, delay = 10) => {
cy.get('.documentFirstHeading > .public-DraftStyleDefault-block')
.clear()
.type(title)
.get('.documentFirstHeading span[data-text]')
.contains(title);

cy.get('.documentFirstHeading > .public-DraftStyleDefault-block').type(
'{enter}',
);
};

export const addBlock = (groupTitle, groupId, blockId) => {
closeSidebar();
cy.get('.ui.basic.icon.button.block-add-button').first().click();
cy.get('.blocks-chooser .title').contains(groupTitle).click();
cy.get(`.content.active.${groupId} .button.${blockId}`).click();
cy.get(`#page-edit div.block-editor-${blockId}`);
openSidebar();
cy.getIfExists(
'#page-edit div.block-editor-slate',
() => {
cy.get('#page-edit div.block-editor-slate').last().click();
},
() => {
cy.getIfExists('#page-edit div.block-editor-text', () => {
cy.get('#page-edit div.block-editor-text').last().click();
});
},
);
cy.get('.ui.basic.icon.button.block-add-button').last().click();
cy.getIfExists(
`.content.active.${groupId}`,
() => {
cy.get(`.content.active.${groupId} .button.${blockId}`).click();
cy.get(`#page-edit div.block-editor-${blockId}`).type('{enter}');
openSidebar();
},
() => {
cy.get('.blocks-chooser .title').contains(groupTitle).click();
cy.get(`.content.active.${groupId} .button.${blockId}`).click();
cy.get(`#page-edit div.block-editor-${blockId}`);
cy.get(`#page-edit div.block-editor-${blockId}`).type('{enter}');
openSidebar();
},
);
};

export const selectBlock = (blockId) => {
Expand Down
7 changes: 4 additions & 3 deletions cypress/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { openSidebar, closeSidebar, openSidebarTab } from './sidebar';
export { changePageTitle, addBlock, selectBlock } from './blocks';
export { setInputValue, filtersModal } from './utils';
export * from './actions';
export * from './blocks';
export * from './sidebar';
export * from './utils';
16 changes: 3 additions & 13 deletions cypress/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ export const setInputValue = (selector, value, type = 'input') => {
});
};

export const save = (path) => {
cy.url().then(($url) => {
if ($url.includes(path)) {
//cy.get('.ui.button.save').click();
cy.get('#toolbar-save').click();
cy.url().should('eq', Cypress.config().baseUrl + path);
} else {
cy.log('Wrong path');
}
});
};

export const filtersModal = {
addFilter: (id, value) => {
cy.get(id).click();
Expand All @@ -62,6 +50,8 @@ export const filtersModal = {
search: (text) => {
cy.get('.filters-container .search-input-container input').type(text);
cy.wait(2000);
cy.get('.filters-container .search-input-container input').type('{enter}');
cy.get('.filters-container .search-input-container span.suggestion-term')
.contains(text)
.click();
},
};
81 changes: 37 additions & 44 deletions cypress/integration/sites.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { setupBeforeEach, tearDownAfterEach } from '../support';
import { changePageTitle, addBlock } from '../helpers';
import { openSidebarTab } from '../helpers';
import { setInputValue, filtersModal, save } from '../helpers/utils';
import { setInputValue, filtersModal } from '../helpers/utils';
import { tableBlockData } from '../helpers/data';

describe('Sites in DiscodataTableBlock', () => {
Expand All @@ -10,48 +10,41 @@ describe('Sites in DiscodataTableBlock', () => {

it('Add Blocks', () => {
changePageTitle('Sites in DiscodataTableBlock');
save('/cypress/my-page');
cy.contains('Sites in DiscodataTableBlock');
// Add block
// addBlock('Text', 'text', 'slate');
// addBlock('Most used', 'most_used', 'image');

// // addBlock('Eprtr Blocks', 'eprtr_blocks', 'eprtr_filters_block');
// addBlock(
// 'Discodata components',
// 'discodata_components',
// 'discodata_components_table_block',
// );
// openSidebarTab('Block');
// setInputValue(
// 'textarea#field-field-widget-importExport',
// tableBlockData,
// 'textarea',
// );
// cy.get('textarea#field-field-widget-importExport').type(' ');
// cy.get('#toolbar-save').click();
// cy.wait(2000);
// filtersModal.open();
// filtersModal.addFilter('#countries_0', 'Romania');
// filtersModal.addFilter('#reporting_years_0', '2018');
// filtersModal.triggerSearch();
// cy.get('.browse-table .ui.pagination.menu a:nth-last-child(2)').should(
// 'have.text',
// '42',
// );
// cy.wait(2000);
// filtersModal.search('Site: 101AR0000.SITE');
// cy.get('.browse-table .ui.pagination.menu a:nth-last-child(2)').should(
// 'have.text',
// '1',
// );
// cy.wait(2000);
// cy.get(
// '#page-document > div.browse-table > table > tbody > tr:nth-last-child(2) > td:nth-child(1) > p',
// ).should('have.text', 'Site: 101AR0000.SITE');
// filtersModal.open();
// filtersModal.triggerClear();
// filtersModal.triggerSearch();
// });
addBlock('Eprtr Blocks', 'eprtr_blocks', 'eprtr_filters_block');
addBlock(
'Discodata components',
'discodata_components',
'discodata_components_table_block',
);
openSidebarTab('Block');
setInputValue(
'textarea#field-field-widget-importExport',
tableBlockData,
'textarea',
);
cy.get('textarea#field-field-widget-importExport').type(' ');
cy.get('#toolbar-save').click();
cy.wait(2000);
filtersModal.open();
filtersModal.addFilter('#countries_0', 'Romania');
filtersModal.addFilter('#reporting_years_0', '2018');
filtersModal.triggerSearch();
cy.get('.browse-table .ui.pagination.menu a:nth-last-child(2)').should(
'have.text',
'42',
);
cy.wait(2000);
filtersModal.search('Site: 101AR0000.SITE');
cy.get('.browse-table .ui.pagination.menu a:nth-last-child(2)').should(
'have.text',
'1',
);
cy.wait(2000);
cy.get(
'#page-document > div.browse-table > table > tbody > tr:nth-last-child(2) > td:nth-child(1) > p',
).should('have.text', 'Site: 101AR0000.SITE');
filtersModal.open();
filtersModal.triggerClear();
filtersModal.triggerSearch();
});
});
16 changes: 16 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ function setBaseAndExtent(...args) {
document.getSelection().setBaseAndExtent(...args);
}

function getIfExists(
selector,
successAction = () => {},
failAction = () => {},
) {
cy.get('body').then((body) => {
if (body.find(selector).length > 0 && successAction) {
successAction();
} else if (failAction) {
failAction();
}
});
}

Cypress.Commands.add('navigate', (route = '') => {
return cy.window().its('appHistory').invoke('push', route);
});
Expand All @@ -314,6 +328,8 @@ Cypress.Commands.add('settings', (key, value) => {
return cy.window().its('settings');
});

Cypress.Commands.add('getIfExists', getIfExists);

Cypress.Commands.add(
'controlledTextAreaChange',
{ prevSubject: 'element' },
Expand Down

0 comments on commit 65177e9

Please sign in to comment.