diff --git a/packages/graph-explorer/src/connector/gremlin/templates/edgeLabelsTemplate.ts b/packages/graph-explorer/src/connector/gremlin/templates/edgeLabelsTemplate.ts index ed932a9f1..6ddfdb286 100644 --- a/packages/graph-explorer/src/connector/gremlin/templates/edgeLabelsTemplate.ts +++ b/packages/graph-explorer/src/connector/gremlin/templates/edgeLabelsTemplate.ts @@ -1,8 +1,6 @@ /** * It returns a Gremlin template to get all edges labels and their counts */ -const edgeLabelsTemplate = () => { +export default function edgeLabelsTemplate() { return "g.E().groupCount().by(label)"; -}; - -export default edgeLabelsTemplate; +} diff --git a/packages/graph-explorer/src/connector/gremlin/templates/edgesSchemaTemplate.ts b/packages/graph-explorer/src/connector/gremlin/templates/edgesSchemaTemplate.ts index 1b9bd54b9..41fd88f36 100644 --- a/packages/graph-explorer/src/connector/gremlin/templates/edgesSchemaTemplate.ts +++ b/packages/graph-explorer/src/connector/gremlin/templates/edgesSchemaTemplate.ts @@ -13,10 +13,8 @@ import { uniq } from "lodash"; * .by(V().bothE("contain").limit(1)) * .limit(1) */ -const edgesSchemaTemplate = ({ types }: { types: string[] }) => { +export default function edgesSchemaTemplate({ types }: { types: string[] }) { const labels = uniq(types.flatMap(type => type.split("::"))); return `g.E().project(${labels.map(l => `"${l}"`).join(",")})${labels.map(l => `.by(V().bothE("${l}").limit(1))`).join("")}.limit(1)`; -}; - -export default edgesSchemaTemplate; +} diff --git a/packages/graph-explorer/src/connector/gremlin/templates/keywordSearchTemplate.test.ts b/packages/graph-explorer/src/connector/gremlin/templates/keywordSearchTemplate.test.ts index e870e5065..503364a0c 100644 --- a/packages/graph-explorer/src/connector/gremlin/templates/keywordSearchTemplate.test.ts +++ b/packages/graph-explorer/src/connector/gremlin/templates/keywordSearchTemplate.test.ts @@ -1,10 +1,11 @@ import keywordSearchTemplate from "./keywordSearchTemplate"; +import { normalizeWithNoSpace as normalize } from "../../../utils/testing"; describe("Gremlin > keywordSearchTemplate", () => { it("Should return a template only with default range", () => { const template = keywordSearchTemplate({}); - expect(template).toBe("g.V().range(0,10)"); + expect(normalize(template)).toBe(normalize("g.V().range(0,10)")); }); it("Should return a template only for vertex type", () => { @@ -12,7 +13,9 @@ describe("Gremlin > keywordSearchTemplate", () => { vertexTypes: ["airport"], }); - expect(template).toBe('g.V().hasLabel("airport").range(0,10)'); + expect(normalize(template)).toBe( + normalize('g.V().hasLabel("airport").range(0,10)') + ); }); it("Should return a template for searched attributes containing the search term", () => { @@ -21,8 +24,10 @@ describe("Gremlin > keywordSearchTemplate", () => { searchByAttributes: ["city", "code"], }); - expect(template).toBe( - 'g.V().or(has("city",containing("JFK")),has("code",containing("JFK"))).range(0,10)' + expect(normalize(template)).toBe( + normalize( + 'g.V().or(has("city",containing("JFK")),has("code",containing("JFK"))).range(0,10)' + ) ); }); @@ -33,8 +38,8 @@ describe("Gremlin > keywordSearchTemplate", () => { exactMatch: true, }); - expect(template).toBe( - 'g.V().or(has("city","JFK"),has("code","JFK")).range(0,10)' + expect(normalize(template)).toBe( + normalize('g.V().or(has("city","JFK"),has("code","JFK")).range(0,10)') ); }); @@ -45,7 +50,9 @@ describe("Gremlin > keywordSearchTemplate", () => { exactMatch: true, }); - expect(template).toBe('g.V().or(has("code","\\"JFK\\"")).range(0,10)'); + expect(normalize(template)).toBe( + normalize('g.V().or(has("code","\\"JFK\\"")).range(0,10)') + ); }); it("Should return a template for the ID token attribute exactly matching the search term", () => { @@ -57,8 +64,8 @@ describe("Gremlin > keywordSearchTemplate", () => { searchByAttributes: ["__id"], }); - expect(template).toBe( - 'g.V().hasLabel("airport").or(has(id,"JFK")).range(0,10)' + expect(normalize(template)).toBe( + normalize('g.V().hasLabel("airport").or(has(id,"JFK")).range(0,10)') ); }); @@ -71,8 +78,10 @@ describe("Gremlin > keywordSearchTemplate", () => { searchByAttributes: ["__id"], }); - expect(template).toBe( - 'g.V().hasLabel("airport").or(has(id,containing("JFK"))).range(0,10)' + expect(normalize(template)).toBe( + normalize( + 'g.V().hasLabel("airport").or(has(id,containing("JFK"))).range(0,10)' + ) ); }); @@ -83,8 +92,16 @@ describe("Gremlin > keywordSearchTemplate", () => { searchByAttributes: ["city", "code", "__all"], }); - expect(template).toBe( - 'g.V().or(has(id,containing("JFK")),has("city",containing("JFK")),has("code",containing("JFK"))).range(0,10)' + expect(normalize(template)).toBe( + normalize(` + g.V() + .or( + has(id, containing("JFK")), + has("city", containing("JFK")), + has("code", containing("JFK")) + ) + .range(0,10) + `) ); }); @@ -95,7 +112,9 @@ describe("Gremlin > keywordSearchTemplate", () => { limit: 25, }); - expect(template).toBe('g.V().hasLabel("airport").range(25,50)'); + expect(normalize(template)).toBe( + normalize('g.V().hasLabel("airport").range(25,50)') + ); }); it("Should return a template with an offset and limit", () => { @@ -107,8 +126,8 @@ describe("Gremlin > keywordSearchTemplate", () => { limit: 10, }); - expect(template).toBe( - 'g.V().or(has("code",containing("JFK"))).range(2,12)' + expect(normalize(template)).toBe( + normalize('g.V().or(has("code",containing("JFK"))).range(2,12)') ); }); @@ -122,8 +141,10 @@ describe("Gremlin > keywordSearchTemplate", () => { offset: 1, }); - expect(template).toBe( - 'g.V().hasLabel("airport").or(has("code",containing("JFK"))).range(1,26)' + expect(normalize(template)).toBe( + normalize( + 'g.V().hasLabel("airport").or(has("code",containing("JFK"))).range(1,26)' + ) ); }); }); diff --git a/packages/graph-explorer/src/connector/gremlin/templates/keywordSearchTemplate.ts b/packages/graph-explorer/src/connector/gremlin/templates/keywordSearchTemplate.ts index 8e3a50624..697630f8b 100644 --- a/packages/graph-explorer/src/connector/gremlin/templates/keywordSearchTemplate.ts +++ b/packages/graph-explorer/src/connector/gremlin/templates/keywordSearchTemplate.ts @@ -20,7 +20,7 @@ import { escapeString } from "../../../utils"; * ) * .range(0, 100) */ -const keywordSearchTemplate = ({ +export default function keywordSearchTemplate({ searchTerm, vertexTypes = [], searchById = true, @@ -28,7 +28,7 @@ const keywordSearchTemplate = ({ limit = 10, offset = 0, exactMatch = false, -}: KeywordSearchRequest): string => { +}: KeywordSearchRequest): string { let template = "g.V()"; if (vertexTypes.length !== 0) { @@ -67,6 +67,4 @@ const keywordSearchTemplate = ({ template += `.range(${offset},${offset + limit})`; return template; -}; - -export default keywordSearchTemplate; +} diff --git a/packages/graph-explorer/src/connector/gremlin/templates/neighborsCountTemplate.test.ts b/packages/graph-explorer/src/connector/gremlin/templates/neighborsCountTemplate.test.ts index c50ee7a72..e64f87f77 100644 --- a/packages/graph-explorer/src/connector/gremlin/templates/neighborsCountTemplate.test.ts +++ b/packages/graph-explorer/src/connector/gremlin/templates/neighborsCountTemplate.test.ts @@ -1,4 +1,5 @@ import neighborsCountTemplate from "./neighborsCountTemplate"; +import { normalizeWithNoSpace as normalize } from "../../../utils/testing"; describe("Gremlin > neighborsCountTemplate", () => { it("Should return a template for the given vertex id", () => { @@ -7,8 +8,10 @@ describe("Gremlin > neighborsCountTemplate", () => { idType: "string", }); - expect(template).toBe( - 'g.V("12").both().dedup().group().by(label).by(count())' + expect(normalize(template)).toBe( + normalize(` + g.V("12").both().dedup().group().by(label).by(count()) + `) ); }); @@ -18,8 +21,10 @@ describe("Gremlin > neighborsCountTemplate", () => { idType: "number", }); - expect(template).toBe( - "g.V(12L).both().dedup().group().by(label).by(count())" + expect(normalize(template)).toBe( + normalize(` + g.V(12L).both().dedup().group().by(label).by(count()) + `) ); }); @@ -30,8 +35,10 @@ describe("Gremlin > neighborsCountTemplate", () => { limit: 20, }); - expect(template).toBe( - 'g.V("12").both().limit(20).dedup().group().by(label).by(count())' + expect(normalize(template)).toBe( + normalize(` + g.V("12").both().limit(20).dedup().group().by(label).by(count()) + `) ); }); @@ -42,8 +49,10 @@ describe("Gremlin > neighborsCountTemplate", () => { limit: 0, }); - expect(template).toBe( - 'g.V("12").both().dedup().group().by(label).by(count())' + expect(normalize(template)).toBe( + normalize(` + g.V("12").both().dedup().group().by(label).by(count()) + `) ); }); }); diff --git a/packages/graph-explorer/src/connector/gremlin/templates/neighborsCountTemplate.ts b/packages/graph-explorer/src/connector/gremlin/templates/neighborsCountTemplate.ts index da2f9f2d8..f7e435e4f 100644 --- a/packages/graph-explorer/src/connector/gremlin/templates/neighborsCountTemplate.ts +++ b/packages/graph-explorer/src/connector/gremlin/templates/neighborsCountTemplate.ts @@ -11,11 +11,11 @@ import type { NeighborsCountRequest } from "../../useGEFetchTypes"; * g.V("44").both().limit(10).dedup() * .group().by(label).by(count()) */ -const neighborsCountTemplate = ({ +export default function neighborsCountTemplate({ vertexId, limit = 0, idType, -}: NeighborsCountRequest) => { +}: NeighborsCountRequest) { let template = ""; if (idType === "number") { template = `g.V(${vertexId}L).both()`; @@ -29,6 +29,4 @@ const neighborsCountTemplate = ({ template += `.dedup().group().by(label).by(count())`; return template; -}; - -export default neighborsCountTemplate; +} diff --git a/packages/graph-explorer/src/connector/gremlin/templates/oneHopTemplate.test.ts b/packages/graph-explorer/src/connector/gremlin/templates/oneHopTemplate.test.ts index 654bc8115..6759cef9b 100644 --- a/packages/graph-explorer/src/connector/gremlin/templates/oneHopTemplate.test.ts +++ b/packages/graph-explorer/src/connector/gremlin/templates/oneHopTemplate.test.ts @@ -1,3 +1,4 @@ +import { normalizeWithNoSpace as normalize } from "../../../utils/testing"; import oneHopTemplate from "./oneHopTemplate"; describe("Gremlin > oneHopTemplate", () => { @@ -7,10 +8,12 @@ describe("Gremlin > oneHopTemplate", () => { idType: "string", }); - expect(template).toBe( - 'g.V("12").project("vertices", "edges")' + - ".by(both().dedup().fold())" + - ".by(bothE().dedup().fold())" + expect(normalize(template)).toBe( + normalize(` + g.V("12").project("vertices", "edges") + .by(both().dedup().fold()) + .by(bothE().dedup().fold()) + `) ); }); @@ -20,10 +23,12 @@ describe("Gremlin > oneHopTemplate", () => { idType: "number", }); - expect(template).toBe( - 'g.V(12L).project("vertices", "edges")' + - ".by(both().dedup().fold())" + - ".by(bothE().dedup().fold())" + expect(normalize(template)).toBe( + normalize(` + g.V(12L).project("vertices", "edges") + .by(both().dedup().fold()) + .by(bothE().dedup().fold()) + `) ); }); @@ -35,10 +40,12 @@ describe("Gremlin > oneHopTemplate", () => { limit: 5, }); - expect(template).toBe( - 'g.V("12").project("vertices", "edges")' + - ".by(both().dedup().range(5, 10).fold())" + - ".by(bothE().dedup().fold())" + expect(normalize(template)).toBe( + normalize(` + g.V("12").project("vertices", "edges") + .by(both().dedup().range(5, 10).fold()) + .by(bothE().dedup().fold()) + `) ); }); @@ -51,10 +58,30 @@ describe("Gremlin > oneHopTemplate", () => { limit: 10, }); - expect(template).toBe( - 'g.V("12").project("vertices", "edges")' + - '.by(both().hasLabel("country").dedup().range(5, 15).fold())' + - '.by(bothE().where(otherV().hasLabel("country")).dedup().fold())' + expect(normalize(template)).toBe( + normalize(` + g.V("12").project("vertices", "edges") + .by(both().hasLabel("country").dedup().range(5, 15).fold()) + .by(bothE().where(otherV().hasLabel("country")).dedup().fold()) + `) + ); + }); + + it("Should return a template for multiple vertex type", () => { + const template = oneHopTemplate({ + vertexId: "12", + idType: "string", + filterByVertexTypes: ["country", "airport", "continent"], + offset: 5, + limit: 10, + }); + + expect(normalize(template)).toBe( + normalize(` + g.V("12").project("vertices", "edges") + .by(both().hasLabel("country", "airport", "continent").dedup().range(5, 15).fold()) + .by(bothE().where(otherV().hasLabel("country", "airport", "continent")).dedup().fold()) + `) ); }); @@ -71,12 +98,14 @@ describe("Gremlin > oneHopTemplate", () => { limit: 10, }); - expect(template).toBe( - 'g.V("12").project("vertices", "edges")' + - '.by(both().hasLabel("country")' + - '.and(has("longest",gte(10000)),has("country",containing("ES")))' + - ".dedup().range(5, 15).fold())" + - '.by(bothE().where(otherV().hasLabel("country")).dedup().fold())' + expect(normalize(template)).toBe( + normalize(` + g.V("12").project("vertices", "edges") + .by(both().hasLabel("country") + .and(has("longest",gte(10000)),has("country",containing("ES"))) + .dedup().range(5, 15).fold()) + .by(bothE().where(otherV().hasLabel("country")).dedup().fold()) + `) ); }); }); diff --git a/packages/graph-explorer/src/connector/gremlin/templates/oneHopTemplate.ts b/packages/graph-explorer/src/connector/gremlin/templates/oneHopTemplate.ts index 572e6201f..74dcece11 100644 --- a/packages/graph-explorer/src/connector/gremlin/templates/oneHopTemplate.ts +++ b/packages/graph-explorer/src/connector/gremlin/templates/oneHopTemplate.ts @@ -1,10 +1,10 @@ import type { Criterion, NeighborsRequest } from "../../useGEFetchTypes"; -const criterionNumberTemplate = ({ +function criterionNumberTemplate({ name, operator, value, -}: Omit): string => { +}: Omit): string { switch (operator.toLowerCase()) { case "eq": case "==": @@ -26,13 +26,13 @@ const criterionNumberTemplate = ({ case "!=": return `has("${name}",neq(${value}))`; } -}; +} -const criterionStringTemplate = ({ +function criterionStringTemplate({ name, operator, value, -}: Omit): string => { +}: Omit): string { switch (operator.toLowerCase()) { case "eq": case "==": @@ -44,13 +44,13 @@ const criterionStringTemplate = ({ case "like": return `has("${name}",containing("${value}"))`; } -}; +} -const criterionDateTemplate = ({ +function criterionDateTemplate({ name, operator, value, -}: Omit): string => { +}: Omit): string { switch (operator.toLowerCase()) { case "eq": case "==": @@ -72,9 +72,9 @@ const criterionDateTemplate = ({ case "!=": return `has("${name}",neq(datetime(${value})))`; } -}; +} -const criterionTemplate = (criterion: Criterion): string => { +function criterionTemplate(criterion: Criterion): string { switch (criterion.dataType) { case "Number": return criterionNumberTemplate(criterion); @@ -84,7 +84,7 @@ const criterionTemplate = (criterion: Criterion): string => { default: return criterionStringTemplate(criterion); } -}; +} /** * @example @@ -125,7 +125,7 @@ const criterionTemplate = (criterion: Criterion): string => { * bothE("route").dedup().fold() * ) */ -const oneHopTemplate = ({ +export default function oneHopTemplate({ vertexId, idType, filterByVertexTypes = [], @@ -133,7 +133,7 @@ const oneHopTemplate = ({ filterCriteria = [], limit = 0, offset = 0, -}: Omit): string => { +}: Omit): string { const range = limit > 0 ? `.range(${offset}, ${offset + limit})` : ""; let template = ""; if (idType === "number") { @@ -183,6 +183,4 @@ const oneHopTemplate = ({ } return template; -}; - -export default oneHopTemplate; +} diff --git a/packages/graph-explorer/src/connector/gremlin/templates/vertexLabelsTemplate.ts b/packages/graph-explorer/src/connector/gremlin/templates/vertexLabelsTemplate.ts index 24a992a00..6cee726cc 100644 --- a/packages/graph-explorer/src/connector/gremlin/templates/vertexLabelsTemplate.ts +++ b/packages/graph-explorer/src/connector/gremlin/templates/vertexLabelsTemplate.ts @@ -1,8 +1,6 @@ /** * It returns a Gremlin template to get all nodes labels and their counts */ -const vertexLabelsTemplate = () => { +export default function vertexLabelsTemplate() { return "g.V().groupCount().by(label)"; -}; - -export default vertexLabelsTemplate; +} diff --git a/packages/graph-explorer/src/connector/gremlin/templates/vertexTypeCountTemplate.ts b/packages/graph-explorer/src/connector/gremlin/templates/vertexTypeCountTemplate.ts index 4f24b5aa9..10303c429 100644 --- a/packages/graph-explorer/src/connector/gremlin/templates/vertexTypeCountTemplate.ts +++ b/packages/graph-explorer/src/connector/gremlin/templates/vertexTypeCountTemplate.ts @@ -1,8 +1,6 @@ /** * It returns a Gremlin template to number of vertices of a particular label */ -const vertexTypeCountTemplate = (label: string) => { +export default function vertexTypeCountTemplate(label: string) { return `g.V().hasLabel("${label}").count()`; -}; - -export default vertexTypeCountTemplate; +} diff --git a/packages/graph-explorer/src/connector/gremlin/templates/verticesSchemaTemplate.test.ts b/packages/graph-explorer/src/connector/gremlin/templates/verticesSchemaTemplate.test.ts index c40db1ee0..f5eae5adb 100644 --- a/packages/graph-explorer/src/connector/gremlin/templates/verticesSchemaTemplate.test.ts +++ b/packages/graph-explorer/src/connector/gremlin/templates/verticesSchemaTemplate.test.ts @@ -1,14 +1,17 @@ import verticesSchemaTemplate from "./verticesSchemaTemplate"; +import { normalizeWithNoSpace as normalize } from "../../../utils/testing"; describe("Gremlin > verticesSchemaTemplate", () => { it("Should return a template with the projection of each type", () => { const template = verticesSchemaTemplate({ types: ["airport", "country"] }); - expect(template).toBe( - 'g.V().project("airport","country")' + - '.by(V().hasLabel("airport").limit(1))' + - '.by(V().hasLabel("country").limit(1))' + - ".limit(1)" + expect(normalize(template)).toBe( + normalize(` + g.V().project("airport","country") + .by(V().hasLabel("airport").limit(1)) + .by(V().hasLabel("country").limit(1)) + .limit(1) + `) ); }); }); diff --git a/packages/graph-explorer/src/connector/gremlin/templates/verticesSchemaTemplate.ts b/packages/graph-explorer/src/connector/gremlin/templates/verticesSchemaTemplate.ts index 243c87e5e..18621b188 100644 --- a/packages/graph-explorer/src/connector/gremlin/templates/verticesSchemaTemplate.ts +++ b/packages/graph-explorer/src/connector/gremlin/templates/verticesSchemaTemplate.ts @@ -13,10 +13,8 @@ import { uniq } from "lodash"; * .by(V().hasLabel("country").limit(1)) * .limit(1) */ -const verticesSchemaTemplate = ({ types }: { types: string[] }) => { +export default function verticesSchemaTemplate({ types }: { types: string[] }) { const labels = uniq(types.flatMap(type => type.split("::"))); return `g.V().project(${labels.map(l => `"${l}"`).join(",")})${labels.map(l => `.by(V().hasLabel("${l}").limit(1))`).join("")}.limit(1)`; -}; - -export default verticesSchemaTemplate; +} diff --git a/packages/graph-explorer/src/connector/openCypher/templates/neighborsCountTemplate.test.ts b/packages/graph-explorer/src/connector/openCypher/templates/neighborsCountTemplate.test.ts index 6f590faa4..6bc21bde1 100644 --- a/packages/graph-explorer/src/connector/openCypher/templates/neighborsCountTemplate.test.ts +++ b/packages/graph-explorer/src/connector/openCypher/templates/neighborsCountTemplate.test.ts @@ -1,4 +1,4 @@ -import normalize from "../../../utils/testing/normalize"; +import { normalize } from "../../../utils/testing"; import neighborsCountTemplate from "./neighborsCountTemplate"; describe("OpenCypher > neighborsCountTemplate", () => { diff --git a/packages/graph-explorer/src/connector/openCypher/templates/oneHopTemplate.test.ts b/packages/graph-explorer/src/connector/openCypher/templates/oneHopTemplate.test.ts index 3ca2080d4..df7b8cf7e 100644 --- a/packages/graph-explorer/src/connector/openCypher/templates/oneHopTemplate.test.ts +++ b/packages/graph-explorer/src/connector/openCypher/templates/oneHopTemplate.test.ts @@ -1,4 +1,4 @@ -import normalize from "../../../utils/testing/normalize"; +import { normalize } from "../../../utils/testing"; import oneHopTemplate from "./oneHopTemplate"; describe("OpenCypher > oneHopTemplate", () => { diff --git a/packages/graph-explorer/src/hooks/useEntities.test.tsx b/packages/graph-explorer/src/hooks/useEntities.test.tsx index 853509db1..ed3e252bc 100644 --- a/packages/graph-explorer/src/hooks/useEntities.test.tsx +++ b/packages/graph-explorer/src/hooks/useEntities.test.tsx @@ -8,12 +8,12 @@ import { createRandomName, createRandomSchema, createRandomVertex, -} from "../utils/testing/randomData"; +} from "../utils/testing"; import { schemaAtom } from "../core/StateProvider/schema"; import { activeConfigurationAtom } from "../core/StateProvider/configuration"; import { Schema } from "../core"; import { Entities } from "../core/StateProvider/entitiesSelector"; -import renderHookWithRecoilRoot from "../utils/testing/renderHookWithRecoilRoot"; +import { renderHookWithRecoilRoot } from "../utils/testing"; import { waitForValueToChange } from "../utils/testing/waitForValueToChange"; describe("useEntities", () => { diff --git a/packages/graph-explorer/src/hooks/useNeighborsOptions.test.ts b/packages/graph-explorer/src/hooks/useNeighborsOptions.test.ts index e2eb82c43..de6eafd30 100644 --- a/packages/graph-explorer/src/hooks/useNeighborsOptions.test.ts +++ b/packages/graph-explorer/src/hooks/useNeighborsOptions.test.ts @@ -1,11 +1,13 @@ import useNeighborsOptions from "./useNeighborsOptions"; import { Vertex } from "../@types/entities"; -import renderHookWithRecoilRoot from "../utils/testing/renderHookWithRecoilRoot"; import { activeConfigurationAtom, configurationAtom, } from "../core/StateProvider/configuration"; -import { createRandomRawConfiguration } from "../utils/testing/randomData"; +import { + createRandomRawConfiguration, + renderHookWithRecoilRoot, +} from "../utils/testing"; describe("useNeighborsOptions", () => { const vertex = { diff --git a/packages/graph-explorer/src/hooks/useTextTransform.test.ts b/packages/graph-explorer/src/hooks/useTextTransform.test.ts index 155ad7dd7..597850a1d 100644 --- a/packages/graph-explorer/src/hooks/useTextTransform.test.ts +++ b/packages/graph-explorer/src/hooks/useTextTransform.test.ts @@ -3,8 +3,10 @@ import { activeConfigurationAtom, configurationAtom, } from "../core/StateProvider/configuration"; -import { createRandomRawConfiguration } from "../utils/testing/randomData"; -import renderHookWithRecoilRoot from "../utils/testing/renderHookWithRecoilRoot"; +import { + createRandomRawConfiguration, + renderHookWithRecoilRoot, +} from "../utils/testing"; import useTextTransform from "./useTextTransform"; function initializeConfigWithPrefix(snapshot: MutableSnapshot) { diff --git a/packages/graph-explorer/src/modules/EntitiesFilter/useFiltersConfig.test.ts b/packages/graph-explorer/src/modules/EntitiesFilter/useFiltersConfig.test.ts index 5b9b45977..270ff4811 100644 --- a/packages/graph-explorer/src/modules/EntitiesFilter/useFiltersConfig.test.ts +++ b/packages/graph-explorer/src/modules/EntitiesFilter/useFiltersConfig.test.ts @@ -4,10 +4,10 @@ import useFiltersConfig from "./useFiltersConfig"; import { createRandomRawConfiguration, createRandomSchema, -} from "../../utils/testing/randomData"; + renderHookWithRecoilRoot, +} from "../../utils/testing"; import { sample, sortBy } from "lodash"; import { Schema } from "../../core"; -import renderHookWithRecoilRoot from "../../utils/testing/renderHookWithRecoilRoot"; import { activeConfigurationAtom, configurationAtom, diff --git a/packages/graph-explorer/src/modules/GraphViewer/renderNode.test.ts b/packages/graph-explorer/src/modules/GraphViewer/renderNode.test.ts index 380b80574..f420545e0 100644 --- a/packages/graph-explorer/src/modules/GraphViewer/renderNode.test.ts +++ b/packages/graph-explorer/src/modules/GraphViewer/renderNode.test.ts @@ -4,10 +4,7 @@ import { describe, it, expect, jest } from "@jest/globals"; import { ICONS_CACHE, VertexIconConfig, renderNode } from "./renderNode"; -import { - createRandomColor, - createRandomName, -} from "../../utils/testing/randomData"; +import { createRandomColor, createRandomName } from "../../utils/testing"; global.fetch = jest.fn< diff --git a/packages/graph-explorer/src/modules/KeywordSearch/useKeywordSearch.test.ts b/packages/graph-explorer/src/modules/KeywordSearch/useKeywordSearch.test.ts index e3ba3b424..ecec04782 100644 --- a/packages/graph-explorer/src/modules/KeywordSearch/useKeywordSearch.test.ts +++ b/packages/graph-explorer/src/modules/KeywordSearch/useKeywordSearch.test.ts @@ -1,7 +1,7 @@ import useKeywordSearch from "./useKeywordSearch"; import { ConnectionConfig } from "../../core"; -import renderHookWithRecoilRoot from "../../utils/testing/renderHookWithRecoilRoot"; -import { createRandomRawConfiguration } from "../../utils/testing/randomData"; +import { renderHookWithRecoilRoot } from "../../utils/testing"; +import { createRandomRawConfiguration } from "../../utils/testing"; import { activeConfigurationAtom, configurationAtom, diff --git a/packages/graph-explorer/src/utils/testing/index.ts b/packages/graph-explorer/src/utils/testing/index.ts new file mode 100644 index 000000000..bd56fc5ee --- /dev/null +++ b/packages/graph-explorer/src/utils/testing/index.ts @@ -0,0 +1,4 @@ +export * from "./normalize"; +export * from "./randomData"; +export { default as renderHookWithRecoilRoot } from "./renderHookWithRecoilRoot"; +export * from "./waitForValueToChange"; diff --git a/packages/graph-explorer/src/utils/testing/normalize.ts b/packages/graph-explorer/src/utils/testing/normalize.ts index 17962c9f7..5b4d07aa6 100644 --- a/packages/graph-explorer/src/utils/testing/normalize.ts +++ b/packages/graph-explorer/src/utils/testing/normalize.ts @@ -3,6 +3,15 @@ * @param str The string to be normalized. * @returns A whitespace normalized string. */ -export default function normalize(str: string) { +export function normalize(str: string) { return str.replace(/\s+/g, " ").trim(); } + +/** + * Removes all whitespace. + * @param str The string to be normalized. + * @returns A whitespace normalized string. + */ +export function normalizeWithNoSpace(str: string) { + return str.replace(/\s+/g, ""); +}