Skip to content

Commit

Permalink
test: refactor tests to make sure it waits for ajax call done
Browse files Browse the repository at this point in the history
  • Loading branch information
aliaghdam committed Sep 18, 2024
1 parent c1674ee commit ef24f1e
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,69 @@ import {
openInnerBlocksExtension,
} from '@blockera/dev-cypress/js/helpers';

describe('Home Link Block', () => {
beforeEach(() => {
createPost();
});
describe(
'Home Link Block',
{
defaultCommandTimeout: 50000,
},
() => {
beforeEach(() => {
createPost();
});

it('Block should be supported + switch to parent should work', () => {
appendBlocks('<!-- wp:navigation /-->');

cy.getBlock('core/navigation').click();

it('Block should be supported + switch to parent should work', () => {
appendBlocks('<!-- wp:navigation /-->');
// Make sure the tree is visible (Ajax call done)
cy.get('.block-editor-list-view-tree').should('be.visible');

cy.getBlock('core/navigation').click();
cy.get('.block-editor-list-view-tree').within(() => {
// Open blocks menu
cy.get('[aria-label="Add block"]').first().click();
});

// Open blocks menu
cy.get('[aria-label="Add block"]').first().click();
// search for home link
cy.get('.block-editor-inserter__popover input[type="search"]').type(
'Home Link'
);

// search for custom link
cy.get('input[type="search"]:focus').last().type('Home Link');
// insert
cy.get('button.editor-block-list-item-home-link').last().click();

// insert
cy.get('button.editor-block-list-item-home-link').last().click();
// switch to target block
cy.getBlock('core/home-link').first().click();

// switch to target block
cy.getBlock('core/home-link').first().click();
// assert block card
cy.get('.blockera-extension-block-card.master-block-card').should(
'exist'
);

// assert block card
cy.get('.blockera-extension-block-card.master-block-card').should(
'exist'
);
// switch to parent navigation block
cy.get('.blockera-extension-block-card.master-block-card').within(
() => {
cy.get(
'button[data-test="back-to-parent-navigation"]'
).should('exist');
cy.get(
'button[data-test="back-to-parent-navigation"]'
).click();
}
);

// switch to parent navigation block
cy.get('.blockera-extension-block-card.master-block-card').within(
() => {
cy.get('button[data-test="back-to-parent-navigation"]').should(
'exist'
//
// Assert block switched to parent navigation block
//
cy.get('.blockera-extension-block-card.master-block-card').should(
'not.exist'
);
cy.get('.block-editor-block-card').should('exist');
cy.get('.block-editor-block-card').within(() => {
cy.get('.block-editor-block-card__title').contains(
'Navigation'
);
cy.get('button[data-test="back-to-parent-navigation"]').click();
}
);

//
// Assert block switched to parent navigation block
//
cy.get('.blockera-extension-block-card.master-block-card').should(
'not.exist'
);
cy.get('.block-editor-block-card').should('exist');
cy.get('.block-editor-block-card').within(() => {
cy.get('.block-editor-block-card__title').contains('Navigation');
});
});
});
});
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,74 @@ import {
openInnerBlocksExtension,
} from '@blockera/dev-cypress/js/helpers';

describe('Navigation Link Block', () => {
beforeEach(() => {
createPost();
});
describe(
'Navigation Link Block',
{
defaultCommandTimeout: 50000,
},
() => {
beforeEach(() => {
createPost();
});

it('Block should be supported + switch to parent should work', () => {
appendBlocks('<!-- wp:navigation /-->');

cy.getBlock('core/navigation').click();

it('Block should be supported + switch to parent should work', () => {
appendBlocks('<!-- wp:navigation /-->');
// Make sure the tree is visible (Ajax call done)
cy.get('.block-editor-list-view-tree').should('be.visible');

cy.getBlock('core/navigation').click();
cy.get('.block-editor-list-view-tree').within(() => {
// Open blocks menu
cy.get('[aria-label="Add block"]').first().click();
});

// Open blocks menu
cy.get('[aria-label="Add block"]').first().click();
// search for custom link
cy.get('.block-editor-inserter__popover input[type="search"]').type(
'Custom Link'
);

// search for custom link
cy.get('input[type="search"]:focus').last().type('Custom Link');
// insert
cy.get('button.editor-block-list-item-navigation-link')
.last()
.click();

// insert
cy.get('button.editor-block-list-item-navigation-link').last().click();
// enter link value
cy.get('input[type="text"]:focus').type('#test{enter}');

// enter link value
cy.get('input[type="text"]:focus').type('#test{enter}');
// switch to target block
cy.getBlock('core/navigation-link').first().click();

// switch to target block
cy.getBlock('core/navigation-link').first().click();
// assert block card
cy.get('.blockera-extension-block-card.master-block-card').should(
'exist'
);

// assert block card
cy.get('.blockera-extension-block-card.master-block-card').should(
'exist'
);
// switch to parent navigation block
cy.get('.blockera-extension-block-card.master-block-card').within(
() => {
cy.get(
'button[data-test="back-to-parent-navigation"]'
).should('exist');
cy.get(
'button[data-test="back-to-parent-navigation"]'
).click();
}
);

// switch to parent navigation block
cy.get('.blockera-extension-block-card.master-block-card').within(
() => {
cy.get('button[data-test="back-to-parent-navigation"]').should(
'exist'
//
// Assert block switched to parent navigation block
//
cy.get('.blockera-extension-block-card.master-block-card').should(
'not.exist'
);
cy.get('.block-editor-block-card').should('exist');
cy.get('.block-editor-block-card').within(() => {
cy.get('.block-editor-block-card__title').contains(
'Navigation'
);
cy.get('button[data-test="back-to-parent-navigation"]').click();
}
);

//
// Assert block switched to parent navigation block
//
cy.get('.blockera-extension-block-card.master-block-card').should(
'not.exist'
);
cy.get('.block-editor-block-card').should('exist');
cy.get('.block-editor-block-card').within(() => {
cy.get('.block-editor-block-card__title').contains('Navigation');
});
});
});
});
}
);

0 comments on commit ef24f1e

Please sign in to comment.