Skip to content

Instantly share code, notes, and snippets.

View nancruz's full-sized avatar
💻

Nuno Cruz nancruz

💻
View GitHub Profile
@nancruz
nancruz / test.js
Created March 31, 2020 17:29
Cypress test example
it("Should select a single node", () => {
const johnSnowId = "Customer::id::C1";
return cy
.wait("@queryGraph")
.waitUntilGraphSimulationEnd()
.selectionHasNode(johnSnowId)
.then((isNodeSelected) => expect(isNodeSelected).to.be.false)
.getGraphNodeInformationById(johnSnowId)
.then((johnSnow) => cy.clickOnGraphNode(johnSnow))
@nancruz
nancruz / cypressCommands.js
Created March 31, 2020 17:27
Implementation of 2 of the custom commands that interact with the graph API
// Gets the node informations such as x and y position given a nodeId
Cypress.Commands.add("getGraphNodeInformationById", (nodeId) => {
return cy.window().then((window) => {
return window.__FDZ_GENOME_GRAPH_API__.getGraphNodes().get(nodeId);
});
});
// Waits for the simulation to end
Cypress.Commands.add("waitUntilGraphSimulationEnd", () => {
return cy.window().then((window) => {
@nancruz
nancruz / exposeGraphApi.js
Created March 31, 2020 17:26
waitUntilGraphSimulationEnd function
waitUntilGraphSimulationEnd: () => {
return new Promise((resolve) => {
// We are checking if when the hasSimulationEnded flag is set to true
const delay = window.setInterval(() => {
if (this.componentRef.state.hasSimulationEnded) {
resolve();
window.clearInterval(delay);
}
}, 500);
});
@nancruz
nancruz / GenomeGraph.js
Created March 31, 2020 17:23
Graph API HOC usage
class GenomGraph extends PureComponent {...}
const GraphComponent = TESTING ? exposeGraphAPI(GenomeGraph) : GenomeGraph;
export default GraphComponent;
@nancruz
nancruz / exposeGraphApi.js
Created March 31, 2020 17:19
HOC for Graph API
export default function exposeGraphAPI(GraphComponent) {
class ExposeGraphApi extends PureComponent {
componentDidMount() {
window.__FDZ_GENOME_GRAPH_API__ = {
getGraphNodes: () => {...},
waitUntilGraphSimulationEnd: () => {...},
....
}
}
render() {
@nancruz
nancruz / distritos-concelhos-freguesias-Portugal.json
Created March 22, 2020 10:59 — forked from tomahock/distritos-concelhos-freguesias-Portugal.json
Level 1 = Distrito, Level 2 = Concelho, Level 3 = Freguesia. Update de 12-07-2016
[
{
"level": 1,
"code": 1,
"name": "Aveiro"
},
{
"level": 2,
"code": 101,
"name": "Águeda"