Skip to content

Commit

Permalink
PropertyComponent: display textFieldType error case to user
Browse files Browse the repository at this point in the history
  • Loading branch information
ndushay committed Aug 2, 2019
1 parent bfad58a commit 8136aae
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
40 changes: 40 additions & 0 deletions __tests__/__fixtures__/lookupWithValueTemplateRefs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"id": "Sinopia:RT:Fixture:LookupWithValueTemplateRefs",
"resourceURI": "http://examples.org/bogusOntologies/Resource",
"remark": "This is a sample Resource Template, content is meaningless",
"resourceLabel": "test lookup type misconfigured with valueTemplateRefs",
"author": "surrogate for Nancy Lorimer",
"schema": "https://ld4p.github.io/sinopia/schemas/0.0.9/resource-template.json",
"propertyTemplates": [
{
"mandatory": "false",
"repeatable": "true",
"type": "lookup",
"valueConstraint": {
"defaults": [],
"useValuesFrom": [],
"valueDataType": {},
"valueTemplateRefs": [
"resourceTemplate:bf2:Note"
]
},
"propertyLabel": "lookup type with valueTemplateRefs",
"propertyURI": "http://examples.org/bogusOntologies/lookup1"
},
{
"mandatory": "false",
"repeatable": "true",
"type": "resource",
"valueConstraint": {
"defaults": [],
"useValuesFrom": [],
"valueDataType": {},
"valueTemplateRefs": [
"resourceTemplate:bf2:Title:Note"
]
},
"propertyLabel": "resource type with valueTemplateRefs",
"propertyURI": "http://examples.org/bogusOntologies/lookup2"
}
]
}
1 change: 1 addition & 0 deletions __tests__/fixtureLoaderHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const rtFileNames = [
'literalRepeatDefaultLiteralNonEnglish.json',
'literalRepeatDefaultLiteralOnly.json',
'literalRepeatNoDefault.json',
'lookupWithValueTemplateRefs.json',
'propertyURIRepeated.json',
'rdaItemMonograph.json',
]
Expand Down
22 changes: 22 additions & 0 deletions __tests__/integration/propertyTemplateMisconfigured.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2019 Stanford University see LICENSE for license

import pupExpect from 'expect-puppeteer'
import { testUserLogin } from './loginHelper'

describe('Errors with Misconfigured Property Templates', () => {
beforeAll(async () => {
await testUserLogin()
})

beforeEach(async () => {
await page.goto('http://127.0.0.1:8888/templates')
await page.waitForSelector('.react-bootstrap-table')
})

it('lookup type misconfigured with valueTemplateRefs', async () => {
// expect.assertions(3)
await pupExpect(page).toClick('a[href="/editor"]', { text: 'test lookup type misconfigured with valueTemplateRefs' })
await pupExpect(page).toClick('button.btn-add[data-id="lookup1"]')
await pupExpect(page).toMatch('This propertyTemplate should not be of type lookup.')
})
})
13 changes: 13 additions & 0 deletions src/components/editor/property/PropertyComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ import { getTagNameForPropertyTemplate } from 'utilities/propertyTemplates'

const PropertyComponent = (props) => {
const tag = getTagNameForPropertyTemplate(props.propertyTemplate)
if (!tag) {
return (
<div className="row">
<div className="col-md-12" style={{ marginTop: '10px' }}>
<div className="alert alert-danger alert-dismissible">
<button className="close" data-dismiss="alert" aria-label="close">&times;</button>
This propertyTemplate should not be of type {props.propertyTemplate.type}.
</div>
</div>
</div>
)
}

const TagName = React.lazy(() => import(`./${tag}`))
return (
<React.Suspense fallback={<div>Loading...</div>}>
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/propertyTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const textFieldType = (config, propertyTemplate) => {
case 'resource':
return 'InputURI'
default:
console.error(`Unknown propertyTemplate type (component=${config}, type=${propertyTemplate.type})`)
// error case handled by caller
return null
}
}
Expand Down

0 comments on commit 8136aae

Please sign in to comment.