Skip to content

Commit

Permalink
Merge pull request #546 from LD4P/refactor-pt-outline
Browse files Browse the repository at this point in the history
Refactor ResourceTemplateForm and PropertyTemplateOutline
  • Loading branch information
jermnelson committed May 23, 2019
2 parents e558280 + 887d4fe commit deee924
Show file tree
Hide file tree
Showing 14 changed files with 696 additions and 672 deletions.
46 changes: 46 additions & 0 deletions __tests__/Utilities.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2019 Stanford University see Apache2.txt for license

import {isResourceWithValueTemplateRef, resourceToName } from '../src/Utilities'

describe('Utilities', () => {
it('can check if a property template is a type of resource with valueTemplateRefs', () => {
const trueTemplate = {
"propertyURI": "http://id.loc.gov/ontologies/bibframe/note",
"type": "resource",
"valueConstraint": {
"valueTemplateRefs": [
"resourceTemplate:bf2:Note"
],
"useValuesFrom": []
}
}
expect(isResourceWithValueTemplateRef(trueTemplate)).toBeTruthy()

const falseTemplate = {
"propertyURI": "http://id.loc.gov/ontologies/bibframe/issuance",
"type": "resource",
"valueConstraint": {
"useValuesFrom": [
"https://id.loc.gov/vocabulary/issuance"
]
}
}
expect(isResourceWithValueTemplateRef(falseTemplate)).toBeFalsy()

const emptyTemplate = {}
expect(isResourceWithValueTemplateRef(emptyTemplate)).toBeFalsy()

})

describe('resourceToName utility', () => {
it('can get a resource name from the last path part of a URI', () => {
const uri = "https://trellis.sinopia.io/resources/ld4p/resourceTemplate:bf2:Note"
expect(resourceToName(uri)).toEqual("resourceTemplate:bf2:Note")
})

it('returns undefined if a URI is undefined', () => {
expect(resourceToName()).toEqual(undefined)
})
})

})
34 changes: 29 additions & 5 deletions __tests__/components/editor/PropertyActionButtons.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,36 @@ describe('<MintButton />', () => {
})

describe('<PropertyActionButtons />', () => {
const propertyActionWrapper = shallow(<PropertyActionButtons />)
const mockAddClick = jest.fn()
const mockMintClick = jest.fn()
const propertyActionWrapper = shallow(<PropertyActionButtons handleMintUri={mockMintClick} handleAddClick={mockAddClick}/>)

describe('Add Button', () => {
const addButton = propertyActionWrapper.find(AddButton)

it('contains AddButton', () => {
expect(addButton).toBeTruthy()
})

it('Add button responds when clicked', () => {
addButton.simulate('click')
expect(mockAddClick).toHaveBeenCalledTimes(1)
})

it('contains AddButton', () => {
expect(propertyActionWrapper.find(AddButton)).toBeTruthy()
})
it('contains MintButton', () => {
expect(propertyActionWrapper.find(MintButton)).toBeTruthy()

describe('Mint Button', () => {
const mintButton = propertyActionWrapper.find(MintButton)

it('contains MintButton', () => {
expect(mintButton).toBeTruthy()
})

it('Mint button responds when clicked', () => {
mintButton.simulate('click')
expect(mockMintClick).toHaveBeenCalledTimes(1)
})

})

})
108 changes: 108 additions & 0 deletions __tests__/components/editor/PropertyComponent.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright 2019 Stanford University see Apache2.txt for license

import React from 'react'
import { shallow } from 'enzyme'
import PropertyComponent from "../../../src/components/editor/PropertyComponent"

describe('<PropertyComponent />', () => {

describe('sets the configuration state based on values from the property template', () => {

describe('for templates configured as list', () => {
const template = {
"propertyURI": "http://id.loc.gov/ontologies/bibframe/issuance",
"type": "resource",
"valueConstraint": {
"useValuesFrom": [
"https://id.loc.gov/vocabulary/issuance"
]
}
}

const wrapper = shallow(<PropertyComponent propertyTemplate={template} />)

it('should find a configuration object in the lookup config', () => {
expect(typeof wrapper.state('configuration')).toEqual("object")
expect(wrapper.state('configuration').length).toEqual(1)
})

it('the configuration should be a component:list', () => {
expect(wrapper.state('configuration')[0].component).toEqual('list')
})

it('it renders the list component', () => {
expect(wrapper.find('Connect(InputListLOC)').length).toEqual(1)
})

})

describe('for templates configured as lookup', () => {
const template = {
"propertyURI": "http://id.loc.gov/ontologies/bibframe/contribution",
"type": "lookup",
"valueConstraint": {
"useValuesFrom": [
"urn:ld4p:qa:names:person",
"urn:ld4p:qa:subjects:person"
]
}
}

const wrapper = shallow(<PropertyComponent propertyTemplate={template} />)

it('should find a configuration object in the lookup config', () => {
expect(typeof wrapper.state('configuration')).toEqual("object")
expect(wrapper.state('configuration').length).toEqual(2)
})

it('the configuration should be a component:lookup', () => {
expect(wrapper.state('configuration')[0].component).toEqual('lookup')
})

it('it renders the lookup component', () => {
expect(wrapper.find('Connect(InputLookupQA)').length).toEqual(1)
})

})
})

describe('when there are no configuration values from the property template', () => {

describe('for unconfigured templates of type:literal', () => {
const template = {
"propertyURI": "http://id.loc.gov/ontologies/bibframe/heldBy",
"type": "literal"
}

const wrapper = shallow(<PropertyComponent propertyTemplate={template} />)

it('the config will be undefined', () => {
expect(wrapper.state('configuration').length).toEqual(0)
})

it('it will check for a property type of literal and render InputLiteral component', () => {
expect(wrapper.find('Connect(InputLiteral)').length).toEqual(1)
})

})

it('if the property type is not literal (i.e. resource) an empty div is returned', () => {
const template = {
"propertyURI": "http://id.loc.gov/ontologies/bibframe/note",
"type": "resource",
"valueConstraint": {
"valueTemplateRefs": [
"resourceTemplate:bf2:Note"
],
"useValuesFrom": []
}
}

const wrapper = shallow(<PropertyComponent propertyTemplate={template} />)
expect(wrapper.find('Connect(InputListLOC)').length).toEqual(0)
expect(wrapper.find('Connect(InputLookupQA)').length).toEqual(0)
expect(wrapper.find('Connect(InputLiteral)').length).toEqual(0)
})
})

})
Loading

0 comments on commit deee924

Please sign in to comment.