Add mutation query
This commit is contained in:
parent
f1d4b11a81
commit
f9e8090120
4 changed files with 106 additions and 104 deletions
5
cypress/fixtures/example.json
Normal file
5
cypress/fixtures/example.json
Normal 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"
|
||||
}
|
|
@ -1,36 +1,33 @@
|
|||
// import { DASHBOARD_SELECTORS } from "../elements/dashboard/dashboard-selectors";
|
||||
import { DASHBOARD_SELECTORS } from "../elements/dashboard/dashboard-selectors";
|
||||
|
||||
// // <reference types="cypress" />
|
||||
// describe("User authorization", () => {
|
||||
// beforeEach(() => {
|
||||
// cy.clearSessionData().loginUserViaRequest();
|
||||
// });
|
||||
// <reference types="cypress" />
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
});
|
|
@ -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;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue