Add mutation query

This commit is contained in:
Karolina Rakoczy 2021-01-21 11:05:54 +01:00
parent f1d4b11a81
commit f9e8090120
4 changed files with 106 additions and 104 deletions

View file

@ -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"
}

View file

@ -1,36 +1,33 @@
// import { DASHBOARD_SELECTORS } from "../elements/dashboard/dashboard-selectors"; import { DASHBOARD_SELECTORS } from "../elements/dashboard/dashboard-selectors";
// // <reference types="cypress" /> // <reference types="cypress" />
// describe("User authorization", () => { describe("User authorization", () => {
// beforeEach(() => { beforeEach(() => {
// cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
// }); });
// xit("should all elements be visible on the dashboard", () => { it("should all elements be visible on the dashboard", () => {
// cy.visit("/"); cy.visit("/");
// softAssertVisibility(DASHBOARD_SELECTORS.sales); softAssertVisibility(DASHBOARD_SELECTORS.sales);
// softAssertVisibility(DASHBOARD_SELECTORS.orders); softAssertVisibility(DASHBOARD_SELECTORS.orders);
// softAssertVisibility(DASHBOARD_SELECTORS.activity); softAssertVisibility(DASHBOARD_SELECTORS.activity);
// softAssertVisibility(DASHBOARD_SELECTORS.topProducts); softAssertVisibility(DASHBOARD_SELECTORS.topProducts);
// softAssertVisibility(DASHBOARD_SELECTORS.ordersReadyToFulfill); softAssertVisibility(DASHBOARD_SELECTORS.ordersReadyToFulfill);
// softAssertVisibility(DASHBOARD_SELECTORS.paymentsWaitingForCapture); softAssertVisibility(DASHBOARD_SELECTORS.paymentsWaitingForCapture);
// softAssertVisibility(DASHBOARD_SELECTORS.productsOutOfStock); softAssertVisibility(DASHBOARD_SELECTORS.productsOutOfStock);
// }); });
// xit("aa", () => { xit("aa", () => {
// // cy.fixture('addresses').then((json) => { cy.fixture("addresses").then(json => {
// // cy.createCustomer("Test9","Test9", json.plAddress); cy.createCustomer("Test9", "Test9", json.plAddress);
// // }); });
// // createChannel(); createChannel();
// // createRateShipping(); createRateShipping();
// // addChannelToProduct(); addChannelToProduct();
// // createOrder(); createOrder();
// }); });
// function softAssertVisibility(selector){ function softAssertVisibility(selector) {
// const {softExpect} = chai; cy.get(selector).then(element => chai.softExpect(element).to.be.visible);
// cy.get(selector).then( element => { }
// softExpect(element).to.be.visible; });
// })
// }
// });

View file

@ -10,6 +10,7 @@ Cypress.Commands.add("createShippingRate", (name, shippingZone) => {
}) })
} }
`; `;
return mutation;
}); });
Cypress.Commands.add("createShippingZone", (name, country) => { Cypress.Commands.add("createShippingZone", (name, country) => {
@ -25,6 +26,7 @@ Cypress.Commands.add("createShippingZone", (name, country) => {
} }
} }
`; `;
return mutation;
}); });
Cypress.Commands.add("", (shippingRateId, channelId) => { Cypress.Commands.add("", (shippingRateId, channelId) => {
@ -45,4 +47,5 @@ Cypress.Commands.add("", (shippingRateId, channelId) => {
} }
} }
`; `;
return mutation;
}); });

View file

@ -1,81 +1,78 @@
// let isSoftAssertion = false; let isSoftAssertion = false;
// let errors = []; let errors = [];
// chai.softExpect = function ( ...args ) { chai.softExpect = function(...args) {
// isSoftAssertion = true; isSoftAssertion = true;
// return chai.expect(...args); return chai.expect(...args);
// }, };
// chai.softAssert = function ( ...args ) { chai.softAssert = function(...args) {
// isSoftAssertion = true; isSoftAssertion = true;
// return chai.assert(...args); return chai.assert(...args);
// } };
// const origAssert = chai.Assertion.prototype.assert; const origAssert = chai.Assertion.prototype.assert;
// chai.Assertion.prototype.assert = function (...args) { chai.Assertion.prototype.assert = function(...args) {
// if ( isSoftAssertion ) { if (isSoftAssertion) {
// try { try {
// origAssert.call(this, ...args) origAssert.call(this, ...args);
// } catch ( error ) { } catch (error) {
// errors.push(error); errors.push(error);
// } }
// isSoftAssertion = false; isSoftAssertion = false;
// } else { } 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 // monkey-patch `it` callback so we insert `cy.then()` as a last command
// const origLog = Cypress.log; // to each test case where we'll assert if there are any soft assertion errors
// Cypress.log = function ( data ) { function itCallback(func) {
// if ( data && data.error && /soft assertions/i.test(data.error.message) ) { func();
// data.error.message = '\n\n\t' + data.error.message + '\n\n'; cy.then(() => {
// throw data.error; if (errors.length) {
// } const _ = Cypress._;
// return origLog.call(Cypress, ...arguments); let msg = "";
// };
// // monkey-patch `it` callback so we insert `cy.then()` as a last command if (Cypress.browser.isHeaded) {
// // to each test case where we'll assert if there are any soft assertion errors msg = "Failed soft assertions... check log above ↑";
// function itCallback ( func ) { } else {
// func(); _.each(errors, error => {
// cy.then(() => { msg += "\n" + error;
// if ( errors.length ) { });
// const _ = Cypress._;
// let msg = '';
// if ( Cypress.browser.isHeaded ) { msg = msg.replace(/^/gm, "\t");
}
// msg = 'Failed soft assertions... check log above ↑'; throw new Error(msg);
// } else { }
});
}
// _.each( errors, error => { const origIt = window.it;
// msg += '\n' + error; 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'); beforeEach(() => {
// } errors = [];
});
// throw new Error(msg); afterEach(() => {
// } errors = [];
// }); isSoftAssertion = false;
// } });
// 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;
// });