From ec448ea2a56f177a6d130ab10ec526396216b5f9 Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Fri, 7 May 2021 15:35:01 +0200 Subject: [PATCH] Test the applicablePredicates utility function (#455) --- .../src/utilities/relation-utilities-test.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 frontend/src/utilities/relation-utilities-test.ts diff --git a/frontend/src/utilities/relation-utilities-test.ts b/frontend/src/utilities/relation-utilities-test.ts new file mode 100644 index 00000000..ce3c34b2 --- /dev/null +++ b/frontend/src/utilities/relation-utilities-test.ts @@ -0,0 +1,36 @@ +import { constant } from 'lodash'; + +import { startStore, endStore } from '../test-util'; +import mockOntology from '../mock-data/mock-ontology'; + +import ldChannel from '../common-rdf/radio'; +import { readit, skos } from '../common-rdf/ns'; +import Node from '../common-rdf/node'; +import Graph from '../common-rdf/graph'; + +import { applicablePredicates } from './relation-utilities'; + +describe('relation utilities', function() { + beforeEach(startStore); + + beforeEach(function() { + const ontology = new Graph(mockOntology); + ldChannel.reply('ontology:graph', constant(ontology)); + }); + + afterEach(function() { + ldChannel.stopReplying('ontology:graph'); + }); + + afterEach(endStore); + + describe('applicablePredicates', function() { + it('returns the predicates applicable to a given class', function() { + const Reader = ldChannel.request('obtain', readit('Reader')); + const predicates = applicablePredicates(Reader); + expect(predicates.length).toBe(2); + expect(predicates.at(0).get(skos.prefLabel)).toBe('description of'); + expect(predicates.at(1).get(skos.prefLabel)).toBe('inverse of description of'); + }); + }); +});