Skip to content

Commit

Permalink
Merge pull request #439 from LD4P/multiplelookups_348
Browse files Browse the repository at this point in the history
Multiplelookups 348
  • Loading branch information
jermnelson committed Apr 2, 2019
2 parents 231540c + 3cc12ed commit e40a76e
Show file tree
Hide file tree
Showing 6 changed files with 520 additions and 312 deletions.
65 changes: 64 additions & 1 deletion __tests__/components/editor/InputLookupQA.test.js
@@ -1,6 +1,8 @@
// Copyright 2018 Stanford University see Apache2.txt for license
import 'jsdom-global/register'
import React from 'react'
import { shallow } from 'enzyme'
import { mount } from "enzyme"
import InputLookup from '../../../src/components/editor/InputLookupQA'

const plProps = {
Expand All @@ -23,7 +25,37 @@ const plProps = {
"propertyURI": "http://id.loc.gov/ontologies/bflc/target",
"propertyLabel": "Name Lookup"
}
}
};
const p2Props = {
"propertyTemplate":
{
"mandatory": "false",
"repeatable": "true",
"type": "lookup",
"resourceTemplates": [],
"valueConstraint": {
"valueTemplateRefs": [],
"useValuesFrom": [
'lookupQaLocNames',
'lookupQaLocSubjects'
],
"valueDataType": {
"dataTypeURI": "http://id.loc.gov/ontologies/bibframe/Agent"
},
"defaults": []
},
"propertyURI": "http://id.loc.gov/ontologies/bflc/target",
"propertyLabel": "Name Lookup"
}
};

const multipleResults = [{"authLabel":"Person",
"authURI":"PersonURI",
"body":[{"uri":"puri","label":"plabel"}]},
{"authLabel":"Subject",
"authURI":"SubjectURI",
"body":[{"uri":"suri","label":"slabel"}]
}];

describe('<InputLookup />', () => {
// our mock formData function to replace the one provided by mapDispatchToProps
Expand Down Expand Up @@ -82,4 +114,35 @@ describe('<InputLookup />', () => {
const propertyRemark = wrapper.find('label > PropertyRemark')
expect(propertyRemark).toBeTruthy()
})

//Institute wrapper with multiple lookup options
const multipleWrapper = shallow(<InputLookup.WrappedComponent {...p2Props} handleSelectedChange={mockFormDataFn} />)
it('should pass multiple lookup results in state with search event', () => {
const event = (wrap) => {
wrap.setState({options: multipleResults})
}
multipleWrapper.find('#lookupComponent').simulate('search', event(multipleWrapper))
expect(multipleWrapper.state().options[0]).toEqual(multipleResults[0])
expect(multipleWrapper.state().options[1]).toEqual(multipleResults[1])

})
//Headers expected

it('should show menu headers with lookup source labels and values in the dropdown when provided results', () => {
const instance = multipleWrapper.instance();
const menuWrapper = shallow(instance.renderMenuFunc(multipleResults, p2Props));
const menuChildrenNumber = menuWrapper.children().length;
//One top level menu component
expect(menuWrapper.find('ul').length).toEqual(1);
//Four children, with two headings and two items
expect(menuChildrenNumber).toEqual(4);
expect(menuWrapper.childAt(0).html()).toEqual("<li class=\"dropdown-header\">Person</li>");
expect(menuWrapper.childAt(1).childAt(0).text()).toEqual("plabel");
expect(menuWrapper.childAt(2).html()).toEqual("<li class=\"dropdown-header\">Subject</li>");
expect(menuWrapper.childAt(3).childAt(0).text()).toEqual("slabel");
})




})
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e40a76e

Please sign in to comment.