Skip to content

Commit

Permalink
Test treeFromSchemes()
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Sep 5, 2024
1 parent f7ce720 commit 449ddde
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 2 deletions.
144 changes: 144 additions & 0 deletions arches_lingo/src/arches_lingo/fixtures/test_scheme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"schemes": [
{
"id": "c9c8548f-6ecc-40d5-ad67-42e9a7e7242e",
"labels": [
{
"language": "en",
"value": "Test Scheme",
"valuetype": "prefLabel"
}
],
"top_concepts": [
{
"id": "943a70f1-236e-4c28-b5ab-69a4b83a63e9",
"labels": [
{
"language": "en",
"value": "Concept 1",
"valuetype": "prefLabel"
}
],
"narrower": [
{
"id": "8f7a7ca8-8548-464b-8fb7-01b3cec6487d",
"labels": [
{
"language": "en",
"value": "Concept 3",
"valuetype": "prefLabel"
}
],
"narrower": [
{
"id": "15bb81ff-194e-4fea-b495-b222f431caee",
"labels": [
{
"language": "en",
"value": "Concept 4",
"valuetype": "prefLabel"
}
],
"narrower": [
{
"id": "edf8dd01-a3fe-445e-a330-dc3bd04c7302",
"labels": [
{
"language": "en",
"value": "Concept 5",
"valuetype": "prefLabel"
}
],
"narrower": []
}
]
}
]
},
{
"id": "53ee9df5-3fa8-4686-a25b-ea8034cc4a5c",
"labels": [
{
"language": "en",
"value": "Concept 2",
"valuetype": "prefLabel"
}
],
"narrower": [
{
"id": "8f7a7ca8-8548-464b-8fb7-01b3cec6487d",
"labels": [
{
"language": "en",
"value": "Concept 3",
"valuetype": "prefLabel"
}
],
"narrower": [
{
"id": "15bb81ff-194e-4fea-b495-b222f431caee",
"labels": [
{
"language": "en",
"value": "Concept 4",
"valuetype": "prefLabel"
}
],
"narrower": [
{
"id": "edf8dd01-a3fe-445e-a330-dc3bd04c7302",
"labels": [
{
"language": "en",
"value": "Concept 5",
"valuetype": "prefLabel"
}
],
"narrower": []
}
]
}
]
}
]
},
{
"id": "15bb81ff-194e-4fea-b495-b222f431caee",
"labels": [
{
"language": "en",
"value": "Concept 4",
"valuetype": "prefLabel"
}
],
"narrower": [
{
"id": "edf8dd01-a3fe-445e-a330-dc3bd04c7302",
"labels": [
{
"language": "en",
"value": "Concept 5",
"valuetype": "prefLabel"
}
],
"narrower": []
}
]
},
{
"id": "edf8dd01-a3fe-445e-a330-dc3bd04c7302",
"labels": [
{
"language": "en",
"value": "Concept 5",
"valuetype": "prefLabel"
}
],
"narrower": []
}
]
}
]
}
]
}
29 changes: 29 additions & 0 deletions arches_lingo/src/arches_lingo/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ENGLISH } from "@/arches_lingo/constants.ts";
import { treeFromSchemes } from "@/arches_lingo/utils.ts";
import schemesFixture from "./fixtures/test_scheme.json";

import type { IconLabels, Scheme } from "@/arches_lingo/types";

const iconLabels: IconLabels = {
concept: "Concept",
scheme: "Scheme",
};

describe("Build scheme hierarchy", () => {
it("Should shape schemes into TreeNodes", () => {
const nodes = treeFromSchemes(
schemesFixture["schemes"] as Scheme[],
ENGLISH,
iconLabels,
null,
);
const schemeNode = nodes[0];
expect(schemeNode.label).toEqual("Test Scheme");
expect(schemeNode.iconLabel).toEqual("Scheme");
expect(schemeNode.data.top_concepts.length).toEqual(1);

const topConcept = schemeNode.data.top_concepts[0];
expect(topConcept.labels[0].value).toEqual("Concept 1");
expect(topConcept.narrower.length).toEqual(4);
});
});
2 changes: 1 addition & 1 deletion arches_lingo/src/arches_lingo/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const treeFromSchemes = (
selectedLanguage: Language,
iconLabels: IconLabels,
focusedNode: TreeNode | null,
) => {
): TreeNode[] => {
// Use a closure to avoid passing around params (selectedLanguage, etc).
const conceptAsNodeAndInstruction = (
concept: Concept,
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def setUpTestData(cls):
MAX_DEPTH = 5
CONCEPT_COUNT = 5
cls.concepts = [
ResourceInstance(graph_id=SCHEMES_GRAPH_ID) for _ in range(CONCEPT_COUNT)
ResourceInstance(graph_id=CONCEPTS_GRAPH_ID) for _ in range(CONCEPT_COUNT)
]
for concept in cls.concepts:
concept.save()
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"types": ["vitest/globals"],
"allowImportingTsExtensions": true
}
}

0 comments on commit 449ddde

Please sign in to comment.