diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json new file mode 100644 index 000000000..da18d9352 --- /dev/null +++ b/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} \ No newline at end of file diff --git a/cypress/integration/dashboard.js b/cypress/integration/dashboard.js index ad6ee2945..d4f1c0749 100644 --- a/cypress/integration/dashboard.js +++ b/cypress/integration/dashboard.js @@ -1,36 +1,33 @@ -// import { DASHBOARD_SELECTORS } from "../elements/dashboard/dashboard-selectors"; +import { DASHBOARD_SELECTORS } from "../elements/dashboard/dashboard-selectors"; -// // -// describe("User authorization", () => { -// beforeEach(() => { -// cy.clearSessionData().loginUserViaRequest(); -// }); +// +describe("User authorization", () => { + beforeEach(() => { + cy.clearSessionData().loginUserViaRequest(); + }); -// xit("should all elements be visible on the dashboard", () => { -// cy.visit("/"); -// softAssertVisibility(DASHBOARD_SELECTORS.sales); -// softAssertVisibility(DASHBOARD_SELECTORS.orders); -// softAssertVisibility(DASHBOARD_SELECTORS.activity); -// softAssertVisibility(DASHBOARD_SELECTORS.topProducts); -// softAssertVisibility(DASHBOARD_SELECTORS.ordersReadyToFulfill); -// softAssertVisibility(DASHBOARD_SELECTORS.paymentsWaitingForCapture); -// softAssertVisibility(DASHBOARD_SELECTORS.productsOutOfStock); -// }); + it("should all elements be visible on the dashboard", () => { + cy.visit("/"); + softAssertVisibility(DASHBOARD_SELECTORS.sales); + softAssertVisibility(DASHBOARD_SELECTORS.orders); + softAssertVisibility(DASHBOARD_SELECTORS.activity); + softAssertVisibility(DASHBOARD_SELECTORS.topProducts); + softAssertVisibility(DASHBOARD_SELECTORS.ordersReadyToFulfill); + softAssertVisibility(DASHBOARD_SELECTORS.paymentsWaitingForCapture); + softAssertVisibility(DASHBOARD_SELECTORS.productsOutOfStock); + }); -// xit("aa", () => { -// // cy.fixture('addresses').then((json) => { -// // cy.createCustomer("Test9","Test9", json.plAddress); -// // }); -// // createChannel(); -// // createRateShipping(); -// // addChannelToProduct(); -// // createOrder(); -// }); + xit("aa", () => { + cy.fixture("addresses").then(json => { + cy.createCustomer("Test9", "Test9", json.plAddress); + }); + createChannel(); + createRateShipping(); + addChannelToProduct(); + createOrder(); + }); -// function softAssertVisibility(selector){ -// const {softExpect} = chai; -// cy.get(selector).then( element => { -// softExpect(element).to.be.visible; -// }) -// } -// }); + function softAssertVisibility(selector) { + cy.get(selector).then(element => chai.softExpect(element).to.be.visible); + } +}); diff --git a/cypress/support/shippingMethod.js b/cypress/support/shippingMethod/index.js similarity index 94% rename from cypress/support/shippingMethod.js rename to cypress/support/shippingMethod/index.js index 84fa3cfd7..949b97651 100644 --- a/cypress/support/shippingMethod.js +++ b/cypress/support/shippingMethod/index.js @@ -10,6 +10,7 @@ Cypress.Commands.add("createShippingRate", (name, shippingZone) => { }) } `; + return mutation; }); Cypress.Commands.add("createShippingZone", (name, country) => { @@ -25,6 +26,7 @@ Cypress.Commands.add("createShippingZone", (name, country) => { } } `; + return mutation; }); Cypress.Commands.add("", (shippingRateId, channelId) => { @@ -45,4 +47,5 @@ Cypress.Commands.add("", (shippingRateId, channelId) => { } } `; + return mutation; }); diff --git a/cypress/support/softAsserations/index.js b/cypress/support/softAsserations/index.js index 3405514da..07dc3dcff 100644 --- a/cypress/support/softAsserations/index.js +++ b/cypress/support/softAsserations/index.js @@ -1,81 +1,78 @@ -// let isSoftAssertion = false; -// let errors = []; +let isSoftAssertion = false; +let errors = []; -// chai.softExpect = function ( ...args ) { -// isSoftAssertion = true; -// return chai.expect(...args); -// }, -// chai.softAssert = function ( ...args ) { -// isSoftAssertion = true; -// return chai.assert(...args); -// } +chai.softExpect = function(...args) { + isSoftAssertion = true; + return chai.expect(...args); +}; +chai.softAssert = function(...args) { + isSoftAssertion = true; + return chai.assert(...args); +}; -// const origAssert = chai.Assertion.prototype.assert; -// chai.Assertion.prototype.assert = function (...args) { -// if ( isSoftAssertion ) { -// try { -// origAssert.call(this, ...args) -// } catch ( error ) { -// errors.push(error); -// } -// isSoftAssertion = false; -// } else { +const origAssert = chai.Assertion.prototype.assert; +chai.Assertion.prototype.assert = function(...args) { + if (isSoftAssertion) { + try { + origAssert.call(this, ...args); + } catch (error) { + errors.push(error); + } + isSoftAssertion = false; + } else { + origAssert.call(this, ...args); + } +}; -// origAssert.call(this, ...args) -// } -// }; +// monkey-patch `Cypress.log` so that the last `cy.then()` isn't logged to command log +const origLog = Cypress.log; +Cypress.log = function(data) { + if (data && data.error && /soft assertions/i.test(data.error.message)) { + data.error.message = "\n\n\t" + data.error.message + "\n\n"; + throw data.error; + } + return origLog.call(Cypress, ...arguments); +}; -// // monkey-patch `Cypress.log` so that the last `cy.then()` isn't logged to command log -// const origLog = Cypress.log; -// Cypress.log = function ( data ) { -// if ( data && data.error && /soft assertions/i.test(data.error.message) ) { -// data.error.message = '\n\n\t' + data.error.message + '\n\n'; -// throw data.error; -// } -// return origLog.call(Cypress, ...arguments); -// }; +// monkey-patch `it` callback so we insert `cy.then()` as a last command +// to each test case where we'll assert if there are any soft assertion errors +function itCallback(func) { + func(); + cy.then(() => { + if (errors.length) { + const _ = Cypress._; + let msg = ""; -// // monkey-patch `it` callback so we insert `cy.then()` as a last command -// // to each test case where we'll assert if there are any soft assertion errors -// function itCallback ( func ) { -// func(); -// cy.then(() => { -// if ( errors.length ) { -// const _ = Cypress._; -// let msg = ''; + if (Cypress.browser.isHeaded) { + msg = "Failed soft assertions... check log above ↑"; + } else { + _.each(errors, error => { + msg += "\n" + error; + }); -// if ( Cypress.browser.isHeaded ) { + msg = msg.replace(/^/gm, "\t"); + } -// msg = 'Failed soft assertions... check log above ↑'; -// } else { + throw new Error(msg); + } + }); +} -// _.each( errors, error => { -// msg += '\n' + error; -// }); +const origIt = window.it; +window.it = (title, func) => { + origIt(title, func && (() => itCallback(func))); +}; +window.it.only = (title, func) => { + origIt.only(title, func && (() => itCallback(func))); +}; +window.it.skip = (title, func) => { + origIt.skip(title, func); +}; -// msg = msg.replace(/^/gm, '\t'); -// } - -// throw new Error(msg); -// } -// }); -// } - -// const origIt = window.it; -// window.it = (title, func) => { -// origIt(title, func && (() => itCallback(func))); -// }; -// window.it.only = (title, func) => { -// origIt.only(title, func && (() => itCallback(func))); -// }; -// window.it.skip = (title, func) => { -// origIt.skip(title, func); -// }; - -// beforeEach(() => { -// errors = []; -// }); -// afterEach(() => { -// errors = []; -// isSoftAssertion = false; -// }); +beforeEach(() => { + errors = []; +}); +afterEach(() => { + errors = []; + isSoftAssertion = false; +});