Skip to content

Commit

Permalink
WIP: Improving cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinwy committed Jul 17, 2024
1 parent 1874c73 commit af8cff2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
19 changes: 10 additions & 9 deletions tests/cypress/e2e/admin.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
describe('KOMOJU for WooCommerce: Admin', () => {
beforeEach(() => {
cy.installWordpress();
cy.signinToWordpress();
cy.installWooCommerce();
cy.installKomoju();

cy.visit('/wp-admin/admin.php?page=wc-settings&tab=komoju_settings&section=api_settings');
cy.get('.komoju-endpoint-field').contains('Reset').click();
cy.contains('Save changes').click();
cy.signinToWordpress().then(() => {
cy.installWooCommerce();
cy.installKomoju();

cy.visit('/wp-admin/admin.php?page=wc-settings&tab=komoju_settings&section=api_settings');
cy.get('.komoju-endpoint-field').contains('Reset').click();
cy.contains('Save changes').click();
});
})

it('lets me add and remove specialized payment gateways', () => {
Expand Down Expand Up @@ -49,8 +50,8 @@ describe('KOMOJU for WooCommerce: Admin', () => {
it('updates secret key with one-click setup', () => {
cy.visit('/wp-admin/admin.php?page=wc-settings&tab=komoju_settings&section=api_settings');

cy.get('#komoju_woocommerce_secret_key').type('{selectAll}{backspace}');
cy.get('#komoju_woocommerce_webhook_secret').type('{selectAll}{backspace}');
cy.get('#komoju_woocommerce_secret_key').clear();
cy.get('#komoju_woocommerce_webhook_secret').clear();
cy.contains('Save changes').click();

cy.contains('Payment methods').click();
Expand Down
20 changes: 7 additions & 13 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,16 @@ Cypress.Commands.add('installWordpress', () => {
Cypress.Commands.add('signinToWordpress', () => {
cy.visit('/wp-admin');

cy.window().then(win => {
if (!win.document.querySelector('#loginform')) {
cy.get('body').then(($body) => {
if (!$body.find('#loginform').length) {
cy.log('Already logged in');
return;
}
cy.log('Logging in');

cy.get('#user_login').clear().type('degica');
cy.wait(100);
cy.get('#user_pass').clear().type('deg1kaX7reme!');
cy.wait(100);
cy.get('#wp-submit').click();
cy.get('#user_login').should('be.visible').clear().type('degica');
cy.get('#user_pass').should('be.visible').clear().type('deg1kaX7reme!');
cy.get('#wp-submit').should('be.visible').click();
});
cy.wait(1000);
});

Cypress.Commands.add('installWooCommerce', () => {
Expand Down Expand Up @@ -200,10 +196,8 @@ Cypress.Commands.add('addItemAndProceedToCheckout', () => {
}
});

cy.get('.wc-block-mini-cart__button').click();
cy.wait(100);
cy.contains('Go to checkout').click();
cy.wait(1000);
cy.get('.wc-block-mini-cart__button').should('be.visible').click();
cy.contains('Go to checkout').should('be.visible').click();
});

Cypress.Commands.add('clickPaymentTab', () => {
Expand Down

0 comments on commit af8cff2

Please sign in to comment.