diff --git a/packages/core-tests/components.test.ts b/packages/core-tests/components.test.ts index daf29f36..44783bab 100644 --- a/packages/core-tests/components.test.ts +++ b/packages/core-tests/components.test.ts @@ -13,6 +13,7 @@ import { FormSettings, PropertyObjectState, PropertyState } from '@hydrofoil/sha import { propertyShape } from '@shaperone/testing/util.js' import type { SinonStubbedInstance } from 'sinon' import { SingleEditorActions } from '@hydrofoil/shaperone-core/models/components/index.js' +import { setEnv } from '@hydrofoil/shaperone-core/env.js' describe('components', () => { describe('enumSelect', () => { @@ -23,6 +24,10 @@ describe('components', () => { let focusNode: GraphPointer let actions: SinonStubbedInstance + before(() => { + setEnv($rdf) + }) + beforeEach(() => { form = { labelProperties: [rdfs.label], @@ -101,7 +106,7 @@ describe('components', () => { property, renderer, }, actions) - await deferred + await deferred.promise // then expect(updateComponentState).to.have.been.calledWith(sinon.match({ diff --git a/packages/core-tests/models/forms/effects/addObject.test.ts b/packages/core-tests/models/forms/effects/addObject.test.ts index a53655cf..d4521741 100644 --- a/packages/core-tests/models/forms/effects/addObject.test.ts +++ b/packages/core-tests/models/forms/effects/addObject.test.ts @@ -40,13 +40,14 @@ describe('models/forms/effects/addObject', () => { // then const dispatch = store.getDispatch() - expect(dispatch.forms.addFormField).to.have.been.calledWith(sinon.match({ + const spy = dispatch.forms.addFormField as sinon.SinonSpy + expect(spy.firstCall.firstArg).to.containSubset({ form, property, focusNode, editors, selectedEditor: dash.TextFieldEditor, - })) + }) }) it('sets overrides to state', () => { @@ -97,12 +98,13 @@ describe('models/forms/effects/addObject', () => { // then const dispatch = store.getDispatch() - expect(dispatch.forms.addFormField).to.have.been.calledWith(sinon.match({ + const spy = dispatch.forms.addFormField as sinon.SinonSpy + expect(spy.firstCall.firstArg).to.containSubset({ form, property, focusNode, selectedEditor: dash.FooEditor, - })) + }) }) context('with overrides', () => { diff --git a/packages/core-tests/models/forms/effects/resources/setRoot.test.ts b/packages/core-tests/models/forms/effects/resources/setRoot.test.ts index d7a890b9..c3514acb 100644 --- a/packages/core-tests/models/forms/effects/resources/setRoot.test.ts +++ b/packages/core-tests/models/forms/effects/resources/setRoot.test.ts @@ -65,10 +65,11 @@ describe('models/forms/effects/resources/setRoot', () => { }) // then - expect(store.getDispatch().forms.createFocusNodeState).to.have.been.calledWith(sinon.match({ + const spy = store.getDispatch().forms.createFocusNodeState as sinon.SinonSpy + expect(spy.firstCall.firstArg).to.containSubset({ form, focusNode: rootPointer, replaceStack: true, - })) + }) }) }) diff --git a/packages/core-tests/models/forms/effects/shapes/setGraph.test.ts b/packages/core-tests/models/forms/effects/shapes/setGraph.test.ts index 3bed7ef0..6558fc88 100644 --- a/packages/core-tests/models/forms/effects/shapes/setGraph.test.ts +++ b/packages/core-tests/models/forms/effects/shapes/setGraph.test.ts @@ -1,8 +1,7 @@ import { describe, it } from 'mocha' -import { expect } from 'chai' import $rdf from '@shaperone/testing/env.js' import { rdf, sh } from '@tpluscode/rdf-ns-builders' -import { sinon } from '@shaperone/testing' +import { expect } from 'chai' import { testStore } from '@shaperone/testing/models/form.js' import setGraph from '@hydrofoil/shaperone-core/models/forms/effects/shapes/setGraph.js' import { Store } from '@hydrofoil/shaperone-core/state' @@ -35,11 +34,10 @@ describe('models/forms/effects/shapes/setGraph', () => { }) // then - formState.focusStack.forEach((focusNode) => { - expect(store.getDispatch().forms.createFocusNodeState).to.have.been.calledWith(sinon.match({ - form, - focusNode, - })) - }) + const spy = store.getDispatch().forms.createFocusNodeState as sinon.SinonSpy + expect(spy.getCalls().map(c => c.firstArg)).to.containSubset([ + { form, focusNode: resourceGraph.node(ex.Foo) }, + { form, focusNode: resourceGraph.node(ex.Bar) }, + ]) }) }) diff --git a/packages/core-tests/models/resources/effects/forms/setObjectValue.test.ts b/packages/core-tests/models/resources/effects/forms/setObjectValue.test.ts index 7aea84da..f38bd6f3 100644 --- a/packages/core-tests/models/resources/effects/forms/setObjectValue.test.ts +++ b/packages/core-tests/models/resources/effects/forms/setObjectValue.test.ts @@ -9,6 +9,7 @@ import setObjectValue from '@hydrofoil/shaperone-core/models/resources/effects/f import { Store } from '@hydrofoil/shaperone-core/state' import { propertyShape } from '@shaperone/testing/util.js' import { Dataset } from '@zazuko/env/lib/Dataset' +import toCanonical from 'rdf-dataset-ext/toCanonical.js' describe('models/resources/effects/forms/setObject', () => { let store: Store @@ -108,7 +109,7 @@ describe('models/resources/effects/forms/setObject', () => { // then const expected = $rdf.clownface().namedNode('propertyShape') expected.addOut(sh.path, schema.name) - expect(focusNode.dataset.toCanonical()).to.eq(expected.dataset.toCanonical()) + expect(toCanonical(focusNode.dataset)).to.eq(toCanonical(expected.dataset)) }) it('replaces one subgraph with another', () => { @@ -143,7 +144,7 @@ describe('models/resources/effects/forms/setObject', () => { // then const expected = $rdf.clownface().namedNode('propertyShape') expected.addOut(sh.path, path => path.addList(sh.alternativePath, [schema.knows, schema.name])) - expect(focusNode.dataset.toCanonical()).to.eq(expected.dataset.toCanonical()) + expect(toCanonical(focusNode.dataset)).to.eq(toCanonical(expected.dataset)) }) it('does not remove subgraph if used multiple times in the data graph', () => { @@ -179,7 +180,7 @@ describe('models/resources/effects/forms/setObject', () => { location.addOut(schema.streetAddress, 'Wisteria Lane') }) .addOut(schema.employmentUnit, $rdf.namedNode('external-id')) - expect(focusNode.dataset.toCanonical()).to.eq(expected.dataset.toCanonical()) + expect(toCanonical(focusNode.dataset)).to.eq(toCanonical(expected.dataset)) }) }) @@ -221,7 +222,7 @@ describe('models/resources/effects/forms/setObject', () => { graph: namedGraph, }).namedNode('propertyShape') expected.addOut(sh.path, path => path.addOut(sh.inversePath, schema.knows)) - expect(focusNode.dataset.toCanonical()).to.eq(expected.dataset.toCanonical()) + expect(toCanonical(focusNode.dataset)).to.eq(toCanonical(expected.dataset)) }) }) }) diff --git a/packages/core-tests/models/resources/effects/forms/setPropertyObjects.test.ts b/packages/core-tests/models/resources/effects/forms/setPropertyObjects.test.ts index 51617d10..e205f648 100644 --- a/packages/core-tests/models/resources/effects/forms/setPropertyObjects.test.ts +++ b/packages/core-tests/models/resources/effects/forms/setPropertyObjects.test.ts @@ -8,6 +8,7 @@ import setPropertyObjects from '@hydrofoil/shaperone-core/models/resources/effec import { Store } from '@hydrofoil/shaperone-core/state' import { propertyShape } from '@shaperone/testing/util.js' import { Dataset } from '@zazuko/env/lib/Dataset' +import toCanonical from 'rdf-dataset-ext/toCanonical.js' describe('models/resources/effects/forms/setPropertyObjects', () => { let store: Store @@ -72,6 +73,6 @@ describe('models/resources/effects/forms/setPropertyObjects', () => { .addOut(schema.contactPoints, graph.blankNode('a2'), (addr) => { addr.addOut(schema.streetAddress, 'Broadway') }) - expect(focusNode.dataset.toCanonical()).to.eq(expected.dataset.toCanonical()) + expect(toCanonical(focusNode.dataset)).to.eq(toCanonical(expected.dataset)) }) }) diff --git a/packages/core-tests/package.json b/packages/core-tests/package.json index 92014399..24deb58c 100644 --- a/packages/core-tests/package.json +++ b/packages/core-tests/package.json @@ -20,6 +20,7 @@ "chai-subset": "^1.6.0", "chai-quantifiers": "^1.0.10", "deepmerge": "^4.2.2", - "promise-the-world": "^1.0.1" + "promise-the-world": "^1.0.1", + "rdf-dataset-ext": "^1.1.0" } } diff --git a/packages/testing/HydraFactory.ts b/packages/testing/HydraFactory.ts index 81c2215d..e42d4494 100644 --- a/packages/testing/HydraFactory.ts +++ b/packages/testing/HydraFactory.ts @@ -1,12 +1,13 @@ import sinon from 'sinon' +import type { HydraClient } from 'alcaeus/alcaeus' export default class AlcaeusFactory { - hydra!: { + hydra!: HydraClient & { loadResource: sinon.SinonStub } init() { - this.hydra = { + this.hydra = { loadResource: sinon.stub(), } }