Skip to content

Commit

Permalink
test: try tests from volto addon
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinab25 committed Aug 28, 2023
1 parent 2356c61 commit ac1ffaa
Show file tree
Hide file tree
Showing 13 changed files with 973 additions and 64 deletions.
Empty file removed cypress/.gitkeep
Empty file.
129 changes: 129 additions & 0 deletions cypress/e2e/01-blocks-accordion.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { slateBeforeEach, slateAfterEach } from '../support/e2e';

describe('Blocks Tests', () => {
beforeEach(slateBeforeEach);
afterEach(slateAfterEach);

it('Accordion Block: Empty', () => {
// Change page title
cy.clearSlateTitle();
cy.getSlateTitle().type('My Add-on Page');

cy.get('.documentFirstHeading').contains('My Add-on Page');

cy.getSlate().click();

// Add metadata block
cy.get('.ui.basic.icon.button.block-add-button').first().click();
cy.get('.blocks-chooser .title').contains('Common').click();
cy.get('.content.active.common .button.accordion')
.contains('Accordion')
.click({ force: true });

// Save
cy.get('#toolbar-save').click();
cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');

// then the page view should contain our changes
cy.contains('My Add-on Page');
});

it('Accordion Block: Change Title', () => {
cy.clearSlateTitle();
cy.getSlateTitle().type('My Add-on Page');

cy.get('.documentFirstHeading').contains('My Add-on Page');

cy.getSlate().click();

// Add accordion block
cy.get('.ui.basic.icon.button.block-add-button').first().click();
cy.get('.blocks-chooser .title').contains('Common').click();
cy.get('.content.active.common .button.accordion')
.contains('Accordion')
.click({ force: true });

// By default all should be collapsed (no active class on first)
cy.get('.accordion:nth-child(2)').should('not.have.class', 'active');

cy.get('.accordion:nth-child(2) > .title input')
.click()
.type('Accordion panel 1')
.should('have.value', 'Accordion panel 1');

cy.get('[id="field-title_size"] .react-select__value-container')
.click()
.type('h2{enter}');

// Save
cy.get('#toolbar-save').click();
cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');

// then the page view should contain our changes
cy.contains('My Add-on Page');
cy.get('h2.accordion-title').contains('Accordion panel 1');
});

it('Accordion Block: add accordion content', () => {
// Change page title
cy.clearSlateTitle();
cy.getSlateTitle().type('My Add-on Page');

cy.get('.documentFirstHeading').contains('My Add-on Page');

cy.getSlate().click();

// Add block
cy.get('.ui.basic.icon.button.block-add-button').first().click();
cy.get('.blocks-chooser .title').contains('Common').click();
cy.get('.content.active.common .button.accordion')
.contains('Accordion')
.click({ force: true });

// enter title for first item in accordion (it is first of the accordion but second as child)
cy.get('.accordion:nth-child(2) > .title input')
.click()
.type('panel 1')
.should('have.value', 'panel 1');

// enter title for third item in accordion
// enter content
cy.get('.accordion:nth-child(3) > .title input').click();
cy.get('.accordion:nth-child(3) > .title input').type('panel 2');
cy.get('.accordion:nth-child(3) > .title > .icon').click();
cy.wait(500);

// the cypress test runs with both slate and draftjs.
cy.getIfExists(
'.accordion:nth-child(3) .content .public-DraftStyleDefault-block:nth-child(1)',
() => {
cy.get(
'.accordion:nth-child(3) .content .public-DraftStyleDefault-block:nth-child(1)',
)
.should('have.value', '')
.invoke('attr', 'tabindex', 1)
.type('children', { delay: 50 });
},
() => {
cy.get('.accordion:nth-child(3) .content 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 });
cy.wait(1000);

//after saving
cy.get('div.accordion-title > span').contains('panel 2');
// after save, the 3 child becomes second
cy.get('.accordion:nth-child(2) > .title > .icon').click();
cy.get('div.content')
.should('have.class', 'active')
.within(() => {
cy.get('p').contains('children');
});
});
});
159 changes: 159 additions & 0 deletions cypress/e2e/02-dexterity-controlpanel-layout.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { slateLayoutBeforeEach, slateLayoutAfterEach } from '../support/e2e';

describe('ControlPanel: Dexterity Content-Types Layout', () => {
beforeEach(slateLayoutBeforeEach);
afterEach(slateLayoutAfterEach);

it('Edit Blocks Layout for Book', () => {
cy.visit('/controlpanel/dexterity-types');
cy.waitForResourceToLoad('@navigation');
cy.waitForResourceToLoad('@breadcrumbs');
cy.waitForResourceToLoad('@actions');
cy.waitForResourceToLoad('@types');

cy.get('a[href="/controlpanel/dexterity-types/book"]').should(
'have.text',
'book',
);

cy.visit('/controlpanel/dexterity-types/book/layout');
cy.get('#page-controlpanel-layout').contains(
'Can not edit Layout for book',
);
cy.get('#page-controlpanel-layout button').click();

// Wait a bit for draftjs to load, without this the title block
// custom placeholder is missing and cypress gives a timeout error
cy.wait(1000);
cy.get('input[id="field-placeholder"]').type('Book title');
cy.get('label[for="field-required"]').click();
cy.get('label[for="field-fixed"]').click();

cy.getSlate().click();

cy.get('.ui.basic.icon.button.block-add-button:visible').click();
cy.get('.blocks-chooser .title').contains('Common').click();
cy.get('.content.active.common .button.accordion')
.contains('Accordion')
.click();

cy.get('#field-allowedBlocks.react-select-container')
.click()
.type('Image{enter}');
cy.get('#field-allowedBlocks.react-select-container')
.click()
.type('Text{enter}');

// By default all should be collapsed (no active class on first)
cy.get('.accordion:nth-child(2)').should('not.have.class', 'active');

cy.get('.accordion:nth-child(2) > .title input')
.click()
.type('Chapter 1')
.should('have.value', 'Chapter 1');

cy.get('.accordion:nth-child(2) > .title > .icon').click();
cy.wait(500);

cy.get(
'.accordion:nth-child(2) .content .slate-editor [contenteditable=true]',
)
.last()
.focus()
.click()
.type('Once upon a time...{enter}');

cy.get(
'.accordion:nth-child(2) .content .slate-editor [contenteditable=true]',
)
.last()
.focus()
.click()
.type('/');
cy.wait(500);
cy.get('.power-user-menu a.item').should('have.length', 1);

cy.get('.accordion:nth-child(3) > .title input')
.click()
.type('Chapter 2')
.should('have.value', 'Chapter 2');

cy.get('#toolbar-save').click();

cy.visit('/cypress');
cy.waitForResourceToLoad('@navigation');
cy.waitForResourceToLoad('@breadcrumbs');
cy.waitForResourceToLoad('@actions');
cy.waitForResourceToLoad('@types');

cy.get('button[class="add"]').click();
cy.get('#toolbar-add-book').click();
cy.get('.block.title').contains('Book title');

// Change book title
cy.clearSlateTitle();
cy.getSlateTitle().type('My First Book');
cy.get('.documentFirstHeading').contains('My First Book');

cy.get('.accordion:nth-child(3) > .title > .icon').click();
cy.wait(500);
cy.get(
'.accordion:nth-child(3) .content .slate-editor [contenteditable=true]',
)
.last()
.focus()
.click()
.type('The quick brown fox jumps over the lazy dog{enter}');

cy.get(
'.accordion:nth-child(3) .content .slate-editor [contenteditable=true]',
)
.last()
.focus()
.click()
.type('/');
cy.wait(500);
cy.get('.power-user-menu a.item').should('have.length', 1);
cy.get(
'.accordion:nth-child(3) .content .slate-editor [contenteditable=true]',
)
.last()
.focus()
.click()
.type('Image{enter}');
cy.get('.accordion:nth-child(3) .content .block.image input[type="text"]')
.click()
.type(
'https://eea.github.io/volto-eea-design-system/img/eea_icon.png{enter}',
);

cy.get('.accordion:nth-child(4) > .title input')
.click()
.type('Chapter 3')
.should('have.value', 'Chapter 3');

cy.get('.accordion-block legend').click();
cy.get('[id="field-title_size"] .react-select__value-container')
.click()
.type('h2{enter}');

cy.get('#toolbar-save').click();
cy.get('.documentFirstHeading').contains('My First Book');
cy.get('.accordion:nth-child(1) > h2.title').contains('Chapter 1');
cy.get('.accordion:nth-child(2) > h2.title').contains('Chapter 2');
cy.get('.accordion:nth-child(3) > h2.title').contains('Chapter 3');

cy.get('.accordion:nth-child(1) > h2.title').click();
cy.get('.accordion:nth-child(1) .content').contains('Once upon a time...');

cy.get('.accordion:nth-child(2) > h2.title').click();
cy.get('.accordion:nth-child(2) .content').contains(
'The quick brown fox jumps over the lazy dog',
);
cy.get('.accordion:nth-child(2) .content img').should(
'have.attr',
'src',
'https://eea.github.io/volto-eea-design-system/img/eea_icon.png',
);
});
});
Binary file removed cypress/fixtures/broccoli.jpg
Binary file not shown.
2 changes: 1 addition & 1 deletion cypress/fixtures/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
}
Binary file removed cypress/fixtures/file.pdf
Binary file not shown.
Binary file removed cypress/fixtures/image.png
Binary file not shown.
Empty file removed cypress/integration/.gitkeep
Empty file.
9 changes: 9 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
Expand All @@ -11,7 +12,15 @@
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
/* coverage-start
require('@cypress/code-coverage/task')(on, config)
on('file:preprocessor', require('@cypress/code-coverage/use-babelrc'))
return config
coverage-end */
};
Loading

0 comments on commit ac1ffaa

Please sign in to comment.