Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the abilty to select a language for a Literal item from a list o…
…f LOC language terms; specifies follow-up work to be done
- Loading branch information
Showing
12 changed files
with
409 additions
and
34 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
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,66 @@ | ||
// Copyright 2018 Stanford University see Apache2.txt for license | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import InputLang from '../../../src/components/editor/InputLang' | ||
|
||
const plProps = { | ||
"propertyTemplate": | ||
{ | ||
"propertyLabel": "Instance of", | ||
"propertyURI": "http://id.loc.gov/ontologies/bibframe/instanceOf", | ||
"type": "literal", | ||
}, | ||
"textValue": "test1" | ||
} | ||
|
||
describe('<InputLang />', () => { | ||
// our mock formData function to replace the one provided by mapDispatchToProps | ||
const mockFormDataFn = jest.fn() | ||
const wrapper = shallow(<InputLang.WrappedComponent {...plProps} handleSelectedChange={mockFormDataFn} />) | ||
|
||
it('contains a label with the value of propertyLabel', () => { | ||
const expected = "Select langauge for test1" | ||
expect(wrapper.find('label').text()).toEqual( | ||
expect.stringContaining(expected) | ||
) | ||
}) | ||
|
||
it('typeahead component should useCache attribute', () => { | ||
expect(wrapper.find('#langComponent').props().useCache).toBeTruthy() | ||
}) | ||
|
||
it('typeahead component should use selectHintOnEnter', () => { | ||
expect(wrapper.find('#langComponent').props().selectHintOnEnter).toBeTruthy() | ||
}) | ||
|
||
it('should call the onChange event and set the state with the selected option', () => { | ||
const event = (wrap) => { | ||
wrap.setState({options: ["{id: 'test1', uri: 'URI', label: 'LABEL'}"]}) | ||
} | ||
wrapper.find('#langComponent').simulate('change', event(wrapper)) | ||
expect(wrapper.state().options[0]).toBe("{id: 'test1', uri: 'URI', label: 'LABEL'}") | ||
}) | ||
|
||
it('should call the onFocus event and set the selected option', () => { | ||
const opts = {id: 'URI', label: 'LABEL', uri: 'URI'} | ||
wrapper.instance().opts = opts | ||
const event = (wrap) => { | ||
global.fetch = jest.fn().mockImplementation(async () => await ({ok: true, resp: wrapper.instance().opts })) | ||
wrap.setState({options: [ wrapper.instance().opts ]}) | ||
wrap.setState({selected: [ wrapper.instance().opts ]}) | ||
} | ||
wrapper.find('#langComponent').simulate('focus', event(wrapper)) | ||
expect(wrapper.state().options[0]).toEqual(opts) | ||
|
||
wrapper.find('#langComponent').simulate('change', event(wrapper)) | ||
expect(wrapper.state().selected[0]).toEqual(opts) | ||
|
||
wrapper.find('#langComponent').simulate('blur', event(wrapper)) | ||
expect(wrapper.state("isLoading")).toBeFalsy() | ||
|
||
}) | ||
|
||
it('sets the formData store with the total number of objects sent to selected', () => { | ||
expect(mockFormDataFn.mock.calls.length).toBe(2) | ||
}) | ||
}) |
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
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,57 @@ | ||
import lang from '../../src/reducers/lang' | ||
|
||
describe('changing the reducer state', () => { | ||
const item_one = { "id": "http://uri1", "uri": "http://uri1", "label": "selection1" } | ||
const item_two = { "id": "http://uri2", "uri": "http://uri2", "label": "selection2" } | ||
|
||
it('should handle initial state', () => { | ||
expect( | ||
lang(undefined, {}) | ||
).toEqual({formData: []}) | ||
}) | ||
|
||
|
||
|
||
it('should handle SET_LANG', () => { | ||
expect( | ||
lang({formData: []}, { | ||
type: 'SET_LANG', | ||
payload: {id:'Run the tests', items: [ item_one ]} | ||
}) | ||
).toEqual({ | ||
"formData": [{ | ||
"id": "Run the tests", "items": [ item_one ] | ||
}] | ||
}) | ||
|
||
expect( | ||
lang({ | ||
"formData": [{ | ||
"id": "Run the tests", "items": [ item_one ] | ||
}]}, { | ||
type: 'SET_LANG', | ||
payload: {id: "Run the tests", items: [ item_two ]} | ||
}) | ||
).toEqual({ | ||
"formData": [ | ||
{"id": "Run the tests", "items": [ item_two ]} | ||
] | ||
}) | ||
|
||
|
||
expect( | ||
lang({ | ||
"formData": [{ | ||
"id": "Run the tests", "items": [ item_one ] | ||
}]}, { | ||
type: 'SET_LANG', | ||
payload: {id: "add this!", items: [ item_two ]} | ||
}) | ||
).toEqual({ | ||
"formData": [ | ||
{"id": "Run the tests", "items": [ item_one ]}, | ||
{"id": "add this!", "items": [ item_two ]} | ||
] | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.