Skip to content

Commit

Permalink
test(e2e): add canvas body element selector
Browse files Browse the repository at this point in the history
- also update tests for addon-backgrounds
  • Loading branch information
yannbf committed Sep 22, 2020
1 parent ac83fa9 commit 6d74f70
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cypress/generated/addon-backgrounds.spec.ts
Expand Up @@ -11,7 +11,7 @@ describe('addon-backgrounds', () => {
cy.get('[title="Change the background of the preview"]').click();
cy.get('#dark').click();

cy.getCanvasElement().should('have.css', 'background-color', 'rgb(51, 51, 51)');
cy.getCanvasBodyElement().should('have.css', 'background-color', 'rgb(51, 51, 51)');
});

it('should apply a grid', () => {
Expand All @@ -21,6 +21,6 @@ describe('addon-backgrounds', () => {
// Toggle grid view
cy.get('[title="Apply a grid to the preview"]').click();

cy.getCanvasElement().should('have.css', 'background-image');
cy.getCanvasBodyElement().should('have.css', 'background-image');
});
});
9 changes: 9 additions & 0 deletions cypress/support/commands.js
Expand Up @@ -81,6 +81,15 @@ Cypress.Commands.add('getCanvasElement', {}, () => {
.then((iframe) => cy.wrap(iframe, { log: false }));
});

Cypress.Commands.add('getCanvasBodyElement', {}, () => {
cy.log('getCanvasBodyElement');
return cy
.getCanvasElement()
.its('0.contentDocument.body', { log: false })
.should('not.be.empty')
.then((body) => cy.wrap(body, { log: false }));
});

Cypress.Commands.add('navigateToStory', (kind, name) => {
const kindId = kind.replace(/ /g, '-').toLowerCase();
const storyId = name.replace(/ /g, '-').toLowerCase();
Expand Down
5 changes: 5 additions & 0 deletions cypress/support/index.d.ts
Expand Up @@ -24,6 +24,11 @@ declare namespace Cypress {
*/
getCanvasElement(): Chainable<Element>;

/**
* Custom command to select the DOM element of the body from the preview iframe in the canvas tab.
*/
getCanvasBodyElement(): Chainable<Element>;

/**
* Navigate to a story.
* 'Storybook Example/Button'
Expand Down

0 comments on commit 6d74f70

Please sign in to comment.