Skip to content

Commit

Permalink
test: missing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Nov 5, 2022
1 parent 322b0dc commit 86bd1fe
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
32 changes: 31 additions & 1 deletion packages/core-tests/models/forms/effects/addObject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cf from 'clownface'
import $rdf from 'rdf-ext'
import { expect } from 'chai'
import { sinon } from '@shaperone/testing'
import { dash } from '@tpluscode/rdf-ns-builders'
import { dash } from '@tpluscode/rdf-ns-builders/loose'
import { testStore } from '@shaperone/testing/models/form.js'
import { addObject } from '@hydrofoil/shaperone-core/models/forms/effects/addObject.js'
import { Store } from '@hydrofoil/shaperone-core/state'
Expand Down Expand Up @@ -43,6 +43,36 @@ describe('models/forms/effects/addObject', () => {
property,
focusNode,
editors,
selectedEditor: dash.TextFieldEditor,
}))
})

it('takes property editor as default match', () => {
// given
const property = propertyShape({
editor: dash.FooEditor,
})
const focusNode = cf({ dataset: $rdf.dataset() }).blankNode()
store.getState().editors.matchSingleEditors = () => [{
term: dash.TextFieldEditor,
score: 5,
meta: <any> {},
}]

// when
addObject(store)({
form,
property,
focusNode,
})

// then
const dispatch = store.getDispatch()
expect(dispatch.forms.addFormField).to.have.been.calledWith(sinon.match({
form,
property,
focusNode,
selectedEditor: dash.FooEditor,
}))
})
})
1 change: 1 addition & 0 deletions packages/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@hydrofoil/shaperone-core": "*",
"@rdf-esm/dataset": "^0.5.1",
"@rdf-esm/namespace": "^0.5.2",
"@rdfine/dash": "^0.2.4",
"@rdfine/shacl": "^0.8.7",
"@tpluscode/rdfine": "^0.5.39",
"@tpluscode/rdf-ns-builders": "^2.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/testing/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import RdfResource, { Initializer, ResourceIdentifier } from '@tpluscode/rdfine/
import clownface, { GraphPointer } from 'clownface'
import * as $rdf from '@rdf-esm/dataset'
import PropertyShapeEx from '@hydrofoil/shaperone-core/models/shapes/lib/PropertyShape.js'
import { PropertyShapeMixinEx } from '@rdfine/dash/extensions/sh'

RdfResource.factory.addMixin(PropertyShapeEx)
RdfResource.factory.addMixin(PropertyShapeEx, PropertyShapeMixinEx)

function isPointer(arg: GraphPointer<ResourceIdentifier> | Initializer<PropertyShape.PropertyShape> | undefined): arg is GraphPointer<ResourceIdentifier> {
return (arg && '_context' in arg) || false
Expand Down

0 comments on commit 86bd1fe

Please sign in to comment.