Skip to content

Commit

Permalink
Fix tests, update cypress version
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinwy committed Nov 19, 2024
1 parent 7744e4a commit d812623
Show file tree
Hide file tree
Showing 5 changed files with 378 additions and 155 deletions.
10 changes: 7 additions & 3 deletions tests/cypress/e2e/admin.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ describe('KOMOJU for WooCommerce: Admin', () => {

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.contains('Save changes').then(($button) => {
if (!$button.is(':disabled')) {
cy.wrap($button).click();
}
});
});
})

Expand All @@ -33,14 +37,14 @@ describe('KOMOJU for WooCommerce: Admin', () => {
cy.visit('/wp-admin/admin.php?page=wc-settings&tab=komoju_settings&section=api_settings');

cy.get('.komoju-endpoint-komoju_woocommerce_api_endpoint').contains('Edit').click();
cy.get('#komoju_woocommerce_api_endpoint').type('{selectAll}https://example.com');
cy.get('#komoju_woocommerce_api_endpoint').clear().type('https://example.com');
cy.contains('Save changes').click();

cy.contains('Payment methods').click();
cy.get('#mainform').should('include.text', 'Unable to reach KOMOJU. Is your secret key correct?');
cy.contains('API settings').click();

cy.get('.komoju-endpoint-komoju_woocommerce_api_endpoint').contains('Reset').click();
cy.get('#komoju_woocommerce_api_endpoint').clear().type('https://komoju.com');
cy.contains('Save changes').click();

cy.contains('Payment methods').click();
Expand Down
21 changes: 12 additions & 9 deletions tests/cypress/e2e/checkout.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ describe('KOMOJU for WooCommerce: Checkout', () => {
cy.setupKomoju(['credit_card']);
cy.clickPaymentTab();
cy.enablePaymentGateway('komoju_credit_card');
cy.contains('Save changes').click();
cy.goToStore();

cy.addItemAndProceedToCheckout();
Expand All @@ -67,7 +66,6 @@ describe('KOMOJU for WooCommerce: Checkout', () => {
cy.setupKomoju(['credit_card', 'konbini', 'web_money']);
cy.clickPaymentTab();
cy.enablePaymentGateway('komoju_web_money');
cy.contains('Save changes').click();
cy.goToStore();

cy.addItemAndProceedToCheckout();
Expand All @@ -94,22 +92,27 @@ describe('KOMOJU for WooCommerce: Checkout', () => {

cy.get('#woocommerce_komoju_credit_card_showIcon').then(input => {
cy.log(input.attr('checked'));
if (input.attr('checked')) cy.wrap(input).click()
if (input.prop('checked')) {
cy.wrap(input).uncheck({ force: true });
cy.contains('Save changes').click()
}
})
cy.contains('Save changes').click()
cy.contains('Your settings have been saved.').should('exist')

cy.goToStore();
cy.addItemAndProceedToCheckout();
cy.get('label[for="radio-control-wc-payment-method-options-komoju_credit_card"] img').should('not.exist')

// radio-control-wc-payment-method-options-komoju_credit_card__label
cy.visit('/wp-admin/admin.php?page=wc-settings&tab=checkout')
cy.get('[data-gateway_id="komoju_credit_card"] a.button')
.click()

cy.get('#woocommerce_komoju_credit_card_showIcon').click()
cy.contains('Save changes').click()
cy.contains('Your settings have been saved.').should('exist')
cy.get('#woocommerce_komoju_credit_card_showIcon').then(input => {
cy.log(input.attr('checked'));
if (!input.prop('checked')) {
cy.wrap(input).check({ force: true });
cy.contains('Save changes').click()
}
})

cy.goToStore();
cy.addItemAndProceedToCheckout();
Expand Down
20 changes: 12 additions & 8 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,18 @@ Cypress.Commands.add('goToStore', () => {
});

Cypress.Commands.add('fillInAddress', () => {
cy.get('#billing-last_name').clear().type('Johnson');
cy.get('#billing-first_name').clear().type('Test');
cy.get('#billing-country').find('#components-form-token-input-0').type('Japan').first().click();
cy.get('#billing-state').find('input').type('Tokyo').first().click();
cy.get('#billing-postcode').clear().type('180-0004');
cy.get('#billing-city').clear().type('Musashino');
cy.get('#billing-address_1').clear().type('address');
cy.get('#billing-phone').clear().type('123123213213213');
cy.get('.wc-block-components-address-address-wrapper').then(($el) => {
if ($el.hasClass('is-editing')) {
cy.get('#billing-last_name').clear().type('Johnson');
cy.get('#billing-first_name').clear().type('Test');
cy.get('#billing-country').select('Japan');
cy.get('#billing-state').select('Tokyo');
cy.get('#billing-postcode').clear().type('180-0004');
cy.get('#billing-city').clear().type('Musashino');
cy.get('#billing-address_1').clear().type('address');
cy.get('#billing-phone').clear().type('123123213213213');
}
});
});

Cypress.Commands.add('iframe', { prevSubject: 'element' }, ($iframe) => {
Expand Down
Loading

0 comments on commit d812623

Please sign in to comment.