-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #546 from LD4P/refactor-pt-outline
Refactor ResourceTemplateForm and PropertyTemplateOutline
- Loading branch information
Showing
14 changed files
with
696 additions
and
672 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) | ||
|
||
}) |
Oops, something went wrong.