UNPKG

@dasch-swiss/dsp-js

Version:

JavaScript library that handles API requests to Knora

130 lines 6.45 kB
import { Cardinality } from "../../../models/v2/ontologies/class-definition"; import { ResourceClassDefinition } from "../../../models/v2/ontologies/resource-class-definition"; import { CardinalityUtil } from "./cardinality-util"; describe("CardinalityUtil", function () { describe("Determine if a value can be created", function () { describe("check cardinality 0-1", function () { var classDef = new ResourceClassDefinition(); classDef.propertiesList = [{ propertyIndex: "myProp", cardinality: Cardinality._0_1, isInherited: false }]; it("create the first value ", function () { var createValueAllowed = CardinalityUtil.createValueForPropertyAllowed("myProp", 0, classDef); expect(createValueAllowed).toBeTruthy(); }); it("create a second value ", function () { var createValueAllowed = CardinalityUtil.createValueForPropertyAllowed("myProp", 1, classDef); expect(createValueAllowed).toBeFalsy(); }); }); describe("check cardinality 1", function () { var classDef = new ResourceClassDefinition(); classDef.propertiesList = [{ propertyIndex: "myProp", cardinality: Cardinality._1, isInherited: false }]; it("create the first value (impossible use case)", function () { var createValueAllowed = CardinalityUtil.createValueForPropertyAllowed("myProp", 0, classDef); expect(createValueAllowed).toBeFalsy(); }); it("create a second value (impossible use case)", function () { var createValueAllowed = CardinalityUtil.createValueForPropertyAllowed("myProp", 1, classDef); expect(createValueAllowed).toBeFalsy(); }); }); describe("check cardinality 1-n", function () { var classDef = new ResourceClassDefinition(); classDef.propertiesList = [{ propertyIndex: "myProp", cardinality: Cardinality._1_n, isInherited: false }]; it("create first value (impossible use case)", function () { var createValueAllowed = CardinalityUtil.createValueForPropertyAllowed("myProp", 0, classDef); expect(createValueAllowed).toBeFalsy(); }); it("create a second value", function () { var createValueAllowed = CardinalityUtil.createValueForPropertyAllowed("myProp", 1, classDef); expect(createValueAllowed).toBeTruthy(); }); }); describe("check cardinality 0-n", function () { var classDef = new ResourceClassDefinition(); classDef.propertiesList = [{ propertyIndex: "myProp", cardinality: Cardinality._0_n, isInherited: false }]; it("create first value", function () { var createValueAllowed = CardinalityUtil.createValueForPropertyAllowed("myProp", 0, classDef); expect(createValueAllowed).toBeTruthy(); }); it("create a second value", function () { var createValueAllowed = CardinalityUtil.createValueForPropertyAllowed("myProp", 1, classDef); expect(createValueAllowed).toBeTruthy(); }); }); }); describe("Determine if a value can be deleted", function () { describe("check cardinality 0-1", function () { var classDef = new ResourceClassDefinition(); classDef.propertiesList = [{ propertyIndex: "myProp", cardinality: Cardinality._0_1, isInherited: false }]; it("delete the single value ", function () { var createValueAllowed = CardinalityUtil.deleteValueForPropertyAllowed("myProp", 1, classDef); expect(createValueAllowed).toBeTruthy(); }); }); describe("check cardinality 1", function () { var classDef = new ResourceClassDefinition(); classDef.propertiesList = [{ propertyIndex: "myProp", cardinality: Cardinality._1, isInherited: false }]; it("delete the single value ", function () { var createValueAllowed = CardinalityUtil.deleteValueForPropertyAllowed("myProp", 1, classDef); expect(createValueAllowed).toBeFalsy(); }); }); describe("check cardinality 1-n", function () { var classDef = new ResourceClassDefinition(); classDef.propertiesList = [{ propertyIndex: "myProp", cardinality: Cardinality._1_n, isInherited: false }]; it("delete a single value", function () { var createValueAllowed = CardinalityUtil.deleteValueForPropertyAllowed("myProp", 1, classDef); expect(createValueAllowed).toBeFalsy(); }); it("delete of of multiple values", function () { var createValueAllowed = CardinalityUtil.deleteValueForPropertyAllowed("myProp", 2, classDef); expect(createValueAllowed).toBeTruthy(); }); }); describe("check cardinality 0-n", function () { var classDef = new ResourceClassDefinition(); classDef.propertiesList = [{ propertyIndex: "myProp", cardinality: Cardinality._0_n, isInherited: false }]; it("delete a single value", function () { var createValueAllowed = CardinalityUtil.deleteValueForPropertyAllowed("myProp", 1, classDef); expect(createValueAllowed).toBeTruthy(); }); it("delete of of multiple values", function () { var createValueAllowed = CardinalityUtil.deleteValueForPropertyAllowed("myProp", 2, classDef); expect(createValueAllowed).toBeTruthy(); }); }); }); }); //# sourceMappingURL=cardinality-util.spec.js.map