Skip to content

Commit

Permalink
Support for repeatable when type is a Resource (#533)
Browse files Browse the repository at this point in the history
Support for repeatable when type is a Resource
  • Loading branch information
jermnelson committed May 28, 2019
2 parents 4960518 + bbdbb76 commit e2f3abd
Show file tree
Hide file tree
Showing 16 changed files with 314 additions and 124 deletions.
25 changes: 23 additions & 2 deletions __tests__/Utilities.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2019 Stanford University see Apache2.txt for license

import {isResourceWithValueTemplateRef, resourceToName } from '../src/Utilities'
import { isResourceWithValueTemplateRef, resourceToName, templateBoolean } from '../src/Utilities'

describe('Utilities', () => {

Expand Down Expand Up @@ -110,7 +110,28 @@ describe('Utilities', () => {

})

})
describe('templateBoolean()', () => {

it('returns true when "true" is passed in as a string', () => {
expect(templateBoolean("true")).toBe(true)
})

it('returns true when a boolean true is passed into the function', () => {
expect(templateBoolean(true)).toBe(true)
})

it('returns true as the default if the parameter is null, undefined, or a random string', () => {
expect(templateBoolean(null)).toBe(true)
expect(templateBoolean(undefined)).toBe(true)
expect(templateBoolean("asdfdsafds")).toBe(true)
})

it('return false when "false" is passed in as a string', () => {
expect(templateBoolean("false")).toBe(false)
})

it('returns false when a boolean false is passed into the function', () => {
expect(templateBoolean(false)).toBe(false)
})
})
})
7 changes: 6 additions & 1 deletion __tests__/components/editor/PropertyActionButtons.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ describe('<AddButton />', () => {
})

it('is not disabled by default', () => {
expect(addButtonWrapper.instance().state.disabled).toBeFalsy()
expect(addButtonWrapper.instance().props.isDisabled).toBeFalsy()
})

it('is disabled if isDisabled prop is true', () => {
const disabledAddButtonWrapper = shallow(<AddButton isDisabled={true} />)
expect(disabledAddButtonWrapper.instance().props.isDisabled).toBeTruthy()
})
})

Expand Down
15 changes: 12 additions & 3 deletions __tests__/components/editor/PropertyResourceTemplate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import React from 'react'
import 'jsdom-global/register'
import { shallow } from 'enzyme'
import { shallow, mount } from 'enzyme'
import shortid from 'shortid'
import PropertyActionButtons from '../../../src/components/editor/PropertyActionButtons'
import { PropertyActionButtons } from '../../../src/components/editor/PropertyActionButtons'
import PropertyResourceTemplate from '../../../src/components/editor/PropertyResourceTemplate'
import PropertyTemplateOutline from '../../../src/components/editor/PropertyTemplateOutline'

Expand Down Expand Up @@ -44,7 +44,7 @@ describe('<PropertyResourceTemplate />', () => {

it('<PropertyTemplateOutline /> has the expected Redux path', () => {
expect(propTemplateOutline.props().reduxPath).toEqual(
['resourceTemplate:test', 'http://schema.org/description', 'abcd45']
['resourceTemplate:test', 'abcd45']
)
})

Expand All @@ -69,4 +69,13 @@ describe('<PropertyResourceTemplate />', () => {
expect(mintEvent.preventDefault.mock.calls.length).toBe(1)
})
})

describe("<PropertyResourceTemplate /> isRepeatable is false", () => {
const wrapper = mount(<PropertyResourceTemplate isRepeatable={"false"} {...propertyRtProps} />)

it('<PropertyActionButtons /> addButtonDisabled prop is true', () => {
const actionButtons = wrapper.find(PropertyActionButtons)
expect(actionButtons.props().addButtonDisabled).toBeTruthy()
})
})
})
36 changes: 35 additions & 1 deletion __tests__/components/editor/PropertyTemplateOutline.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import React from 'react'
import 'jsdom-global/register'
import { shallow, mount } from 'enzyme'
import PropertyTemplateOutline from '../../../src/components/editor/PropertyTemplateOutline'
import { addResourceTemplate, PropertyTemplateOutline } from '../../../src/components/editor/PropertyTemplateOutline'
import RequiredSuperscript from '../../../src/components/editor/RequiredSuperscript'

describe('<PropertyTemplateOutline />', () => {
Expand Down Expand Up @@ -139,7 +139,41 @@ describe('<PropertyTemplateOutline />', () => {
expect(wrapper.find('div PropertyTypeRow').length).toEqual(1)
expect(wrapper.find('div PropertyComponent').length).toEqual(1)
})
})
})

describe('addResourceTemplate function', () => {
const noteResourceTemplate = {
"id": "resourceTemplate:bf2:Note",
"resourceURI": "http://id.loc.gov/ontologies/bibframe/Note",
"resourceLabel": "A Resource Template Note",
"propertyTemplates": [
{
"propertyURI": "http://www.w3.org/2000/01/rdf-schema#label",
"propertyLabel": "Note",
"mandatory": "false",
"repeatable": "false",
"type": "literal",
"resourceTemplates": [],
"valueConstraint": {
"valueTemplateRefs": [],
"useValuesFrom": [],
"valueDataType": {},
"editable": "true",
"repeatable": "false",
"defaults": []
}
}
]
}
const propertyTemplate = addResourceTemplate(noteResourceTemplate, ['resourceTemplate:bf2:Note'])

it("contains the Resource Template's resourceLabel as the first element", () => {
const firstElement = shallow(<h5>{noteResourceTemplate["resourceLabel"]}</h5>)
expect(firstElement.matchesElement(propertyTemplate[0])).toBeTruthy()
})

it('contains a <PropertyTemplateOutline /> as the second element', () => {
expect(propertyTemplate[1].type).toBe(PropertyTemplateOutline)
})
})
3 changes: 2 additions & 1 deletion __tests__/components/editor/ResourceTemplateForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ describe('<ResourceTemplateForm /> functional testing', () => {
})
const result = basicWrapper.instance().resourceTemplateFields(
["resourceTemplate:bf2:Note"],
"http://www.w3.org/2000/01/rdf-schema#label")
{ propertyURI: "http://www.w3.org/2000/01/rdf-schema#label",
repeatable: "true" })
expect(result[0].props.reduxPath).toEqual(["resource:schema:Name",
"http://www.w3.org/2000/01/rdf-schema#label",
"abcd45",
Expand Down
49 changes: 49 additions & 0 deletions __tests__/integration/repeatableResources.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2019 Stanford University see Apache2.txt for license

import Config from '../../src/Config'
import pupExpect from 'expect-puppeteer'

describe('Adding new embedded Resource Templates', () => {

beforeAll(async () => {
jest.setTimeout(60000); // this seems to take around 10s in practice, but be generous, just in case
await page.goto('http://127.0.0.1:8888/templates')

// attempt to enter and submit login info
try {
await page.waitForSelector('form.login-form')
await page.type('form.login-form input[name=username]', Config.cognitoTestUserName);
await page.type('form.login-form input[name=password]', Config.cognitoTestUserPass);
await page.click('form.login-form button[type=submit]');
} catch (error) {
console.info(error)
}

// sign out button should only show up after successful login
await page.waitForSelector('button.signout-btn')
})

it('loads up a resource template from the list of loaded templates', async () => {
await pupExpect(page).toClick('a', { text: 'BIBFRAME Instance' })
await pupExpect(page).toMatch("BIBFRAME Instance")
})

// TODO: Simplify CSS selectors in the tests below, see ticket #573
it('clicks on an AddButton in Notes about the Instance and looks for a second resource template', async () => {
await pupExpect(page).toClick('div.panel:nth-child(5) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > section:nth-child(2) > div:nth-child(1) > button:nth-child(2)')
await pupExpect(page).toMatchElement('div.panel:nth-child(5) > div:nth-child(2) > div:nth-child(1) > div:nth-child(2) > h4:nth-child(2)', { text: "Note"} )
})

it('clicks on a nested property with an embedded Note resource template and then clicks on the AddButton for a second resource template', async () => {
await pupExpect(page).toClick("a[data-id='note']")
await pupExpect(page).toClick(".col-sm-4 > div:nth-child(1) > button:nth-child(2)")
await pupExpect(page).toMatchElement('div.panel:nth-child(1) > div:nth-child(2) > div:nth-child(1) > div:nth-child(2) > div:nth-child(3) > div:nth-child(2) > h5:nth-child(2)',
{ text: "Note"})
})

it("checks that a non-repeatable resource template's AddButton is disabled", async () => {
await pupExpect(page).toMatchElement("div.panel:nth-child(7) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > section:nth-child(2) > div:nth-child(1) > button:nth-child(2)",
{ disabled: true})
})

})
Loading

0 comments on commit e2f3abd

Please sign in to comment.