diff --git a/cypress/elements/dashboard/dashboard-selectors.js b/cypress/elements/dashboard/dashboard-selectors.js new file mode 100644 index 000000000..5c71fe47e --- /dev/null +++ b/cypress/elements/dashboard/dashboard-selectors.js @@ -0,0 +1,11 @@ +export const DASHBOARD_SELECTORS = { + sales: "div:nth-child(1) > [class*='HomeAnalyticsCard-cardContent']", + orders: "div:nth-child(2) > [class*='HomeAnalyticsCard-cardContent']", + activity: "[class*='Grid-root'] > div:nth-child(2) > [class*='MuiPaper']", + topProducts: + "[class*='Grid-root'] > div:nth-child(1) > [class*='MuiPaper']:nth-child(4)", + ordersReadyToFulfill: "[class*='HomeNotificationTable'] > tr:nth-child(1)", + paymentsWaitingForCapture: + "[class*='HomeNotificationTable'] > tr:nth-child(2)", + productsOutOfStock: "[class*='HomeNotificationTable'] > tr:nth-child(3)" +}; diff --git a/cypress/fixtures/addresses.json b/cypress/fixtures/addresses.json new file mode 100644 index 000000000..742bd227e --- /dev/null +++ b/cypress/fixtures/addresses.json @@ -0,0 +1,12 @@ +{ + "plAddress": { + "companyName": "Test3", + "streetAddress1": "Smolna", + "streetAddress2": "13/1", + "city": "Wrocław", + "postalCode": "53-346", + "country": "PL", + "countryArea": "Dolny Śląsk", + "phone": "123456787" + } +} \ No newline at end of file diff --git a/cypress/integration/dashboard.js b/cypress/integration/dashboard.js new file mode 100644 index 000000000..ad6ee2945 --- /dev/null +++ b/cypress/integration/dashboard.js @@ -0,0 +1,36 @@ +// import { DASHBOARD_SELECTORS } from "../elements/dashboard/dashboard-selectors"; + +// // +// 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); +// }); + +// 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; +// }) +// } +// }); diff --git a/cypress/support/customer/index.js b/cypress/support/customer/index.js new file mode 100644 index 000000000..0a900581c --- /dev/null +++ b/cypress/support/customer/index.js @@ -0,0 +1,37 @@ +Cypress.Commands.add( + "createCustomer", + (email, name, address, isActive = false) => { + const mustation = ` + mutation{ + customerCreate(input:{ + firstName: "${name}" + lastName: "${name}" + email: "${email}" + isActive: ${isActive} + defaultBillingAddress: { + companyName: "${address.companyName}" + streetAddress1: "${address.streetAddress1}" + streetAddress2: "${address.streetAddress2}" + city: "${address.city}" + postalCode: "${address.postalCode}" + country: ${address.country} + phone: "${address.phone}" + } + defaultShippingAddress: { + companyName: "${address.companyName}" + streetAddress1: "${address.streetAddress1}" + streetAddress2: "${address.streetAddress2}" + city: "${address.city}" + postalCode: "${address.postalCode}" + country: ${address.country} + phone: "${address.phone}" + } + }){ + accountErrors{ + code + } + } + } + `; + } +); diff --git a/cypress/support/index.js b/cypress/support/index.js index 531b8aab9..c863c2167 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -1,4 +1,7 @@ import "./user"; +import "./softAsserations"; +import "./customer"; +import "./shippingMethod"; Cypress.Commands.add("clearSessionData", () => { // Because of known cypress bug, not all local storage data are cleared. diff --git a/cypress/support/shippingMethod.js b/cypress/support/shippingMethod.js new file mode 100644 index 000000000..84fa3cfd7 --- /dev/null +++ b/cypress/support/shippingMethod.js @@ -0,0 +1,48 @@ +Cypress.Commands.add("createShippingRate", (name, shippingZone) => { + const mutation = ` + mutation{ + CreateShippingRate(input:{ + maximumDeliveryDays: null + minimumDeliveryDays: null + name: "${name}" + shippingZone: "${shippingZone}" + type: "PRICE" + }) + } + `; +}); + +Cypress.Commands.add("createShippingZone", (name, country) => { + const mutation = ` + mutation{ + shippingZoneCreate(input:{ + name: "${name}" + countries: "${country}" + }){ + shippingZone{ + id + } + } + } + `; +}); + +Cypress.Commands.add("", (shippingRateId, channelId) => { + const mutation = ` + mutation{ + shippingMethodChannelListingUpdate(id:"${shippingRateId}", input:{ + addChannels: { + channelId:"${channelId}" + } + }){ + shippingMethod{ + id + } + shippingErrors{ + code + message + } + } + } + `; +}); diff --git a/cypress/support/softAsserations/index.js b/cypress/support/softAsserations/index.js new file mode 100644 index 000000000..3405514da --- /dev/null +++ b/cypress/support/softAsserations/index.js @@ -0,0 +1,81 @@ +// 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); +// } + +// 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) +// } +// }; + +// // 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 = ''; + +// if ( Cypress.browser.isHeaded ) { + +// msg = 'Failed soft assertions... check log above ↑'; +// } else { + +// _.each( errors, error => { +// msg += '\n' + error; +// }); + +// 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; +// });