Skip to content

Commit

Permalink
Fix InputLiteral so that retains language after edit.
Browse files Browse the repository at this point in the history
closes #1136
  • Loading branch information
justinlittman committed Aug 2, 2019
1 parent 3225c66 commit 92eacd1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion __tests__/components/editor/property/InputValue.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ describe('<InputValue>', () => {
it('calls the removeMockDataFn and mockItemsChange when Edit is clicked', () => {
mockWrapper.find('button#editItem').first().simulate('click', { target: { dataset: { item: 5 } } })
expect(removeDataFn).toHaveBeenCalled()
expect(itemsChangeFn).toHaveBeenCalled()
expect(itemsChangeFn).toHaveBeenCalledWith('foo', 'en')
})
})
50 changes: 50 additions & 0 deletions __tests__/integration/literal.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2019 Stanford University see LICENSE for license

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

describe('RDF from literal property templates', () => {
beforeAll(async () => {
await testUserLogin()
await page.goto('http://127.0.0.1:8888/templates')
await page.waitForSelector('.react-bootstrap-table')
await page.setViewport({
width: 1822,
height: 961,
})
})

it('enter a note value', async () => {
expect.assertions(4)
await pupExpect(page).toClick('a[href="/editor"]', { text: 'Note' })
await pupExpect(page).toClick('button.btn-add')
await pupExpect(page).toFill('input[placeholder=\'Note\']', 'splendid')
await page.keyboard.press('Enter')
await pupExpect(page).toMatchElement('div.rbt-token', { text: 'splendid' })
})

it('change language', async () => {
expect.assertions(7)
await pupExpect(page).toClick('button#language')
await pupExpect(page).toMatch('Languages')

await pupExpect(page).toFill('input.rbt-input-main', 'Navajo')

// Wait until autosuggest has returned something to click on
await page.waitForSelector('#rbt-menu-item-0')
await pupExpect(page).toClick('#rbt-menu-item-0')

await pupExpect(page).toClick('button', { text: 'Submit' })
await pupExpect(page).toMatchElement('button#language')
await pupExpect(page).toMatch('Language: Navajo')
})

it('retains changed language after edit', async () => {
expect.assertions(4)
await pupExpect(page).toClick('button#editItem')
await pupExpect(page).toFill('input[placeholder=\'Note\']', 'kinda splendid')
await page.keyboard.press('Enter')
await pupExpect(page).toMatchElement('button#language')
await pupExpect(page).toMatch('Language: Navajo')
})
})
7 changes: 5 additions & 2 deletions src/components/editor/property/InputLiteral.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const InputLiteral = (props) => {

const inputLiteralRef = useRef(Math.floor(100 * Math.random()))
const [content, setContent] = useState('')
const [lang, setLang] = useState(defaultLanguageId)

const disabled = !booleanPropertyFromTemplate(props.propertyTemplate, 'repeatable', true)
&& Object.keys(props.items).length > 0
Expand All @@ -34,11 +35,12 @@ const InputLiteral = (props) => {
const userInput = {
reduxPath: props.reduxPath,
items: {
[shortid.generate()]: { content: currentcontent, lang: defaultLanguageId },
[shortid.generate()]: { content: currentcontent, lang },
},
}
props.handleMyItemsChange(userInput)
setContent('')
setLang(defaultLanguageId)
}

const handleKeypress = (event) => {
Expand All @@ -48,8 +50,9 @@ const InputLiteral = (props) => {
}
}

const handleEdit = (content) => {
const handleEdit = (content, lang) => {
setContent(content)
setLang(lang)
inputLiteralRef.current.focus()
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/editor/property/InputValue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const InputValue = (props) => {
const label = isLiteral ? props.item.content : props.item.uri

const handleEditClick = () => {
props.handleEdit(label)
props.handleEdit(label, props.item.lang)
props.removeItem(props.reduxPath)
}

Expand Down

0 comments on commit 92eacd1

Please sign in to comment.