Skip to content

Commit

Permalink
test: final fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Mar 25, 2024
1 parent 9e7d36b commit 66e99e7
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 23 deletions.
7 changes: 6 additions & 1 deletion packages/core-tests/components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -23,6 +24,10 @@ describe('components', () => {
let focusNode: GraphPointer<BlankNode>
let actions: SinonStubbedInstance<SingleEditorActions>

before(() => {
setEnv($rdf)
})

beforeEach(() => {
form = {
labelProperties: [rdfs.label],
Expand Down Expand Up @@ -101,7 +106,7 @@ describe('components', () => {
property,
renderer,
}, actions)
await deferred
await deferred.promise

// then
expect(updateComponentState).to.have.been.calledWith(sinon.match({
Expand Down
10 changes: 6 additions & 4 deletions packages/core-tests/models/forms/effects/addObject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}))
})
})
})
14 changes: 6 additions & 8 deletions packages/core-tests/models/forms/effects/shapes/setGraph.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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) },
])
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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))
})
})

Expand Down Expand Up @@ -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))
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
})
})
3 changes: 2 additions & 1 deletion packages/core-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
5 changes: 3 additions & 2 deletions packages/testing/HydraFactory.ts
Original file line number Diff line number Diff line change
@@ -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 = <any>{
loadResource: sinon.stub(),
}
}
Expand Down

0 comments on commit 66e99e7

Please sign in to comment.