Skip to content

Commit

Permalink
test(Form): test Form for v1 API
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Aug 21, 2016
1 parent 8fbae79 commit b2e3d68
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 49 deletions.
24 changes: 0 additions & 24 deletions test/specs/collections/Form/Field-test.js

This file was deleted.

22 changes: 0 additions & 22 deletions test/specs/collections/Form/Fields-test.js

This file was deleted.

7 changes: 4 additions & 3 deletions test/specs/collections/Form/Form-test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Form } from 'stardust'
import Form from 'src/collections/Form/Form'
import FormField from 'src/collections/Form/FormField'
import FormFields from 'src/collections/Form/FormFields'

import * as common from 'test/specs/commonTests'

describe('Form', () => {
common.isConformant(Form)
common.hasUIClassName(Form)
common.hasSubComponents(Form, [FormField, FormFields])
common.hasSubComponents(Form, [FormField])
common.rendersChildren(Form)
common.implementsWidthProp(Form, { propKey: 'widths' })
})
59 changes: 59 additions & 0 deletions test/specs/collections/Form/FormField-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react'

import FormField from 'src/collections/Form/FormField'
import FormFieldButton from 'src/collections/Form/FormFieldButton'
import FormFieldCheckbox from 'src/collections/Form/FormFieldCheckbox'
import FormFieldDropdown from 'src/collections/Form/FormFieldDropdown'
import FormFieldGroup from 'src/collections/Form/FormFieldGroup'
import FormFieldInput from 'src/collections/Form/FormFieldInput'
import FormFieldRadio from 'src/collections/Form/FormFieldRadio'
import FormFieldSelect from 'src/collections/Form/FormFieldSelect'
import FormFieldTextArea from 'src/collections/Form/FormFieldTextArea'
import * as common from 'test/specs/commonTests'

describe('FormField', () => {
common.isConformant(FormField)
common.implementsWidthProp(FormField, { propKey: 'width', canEqual: false })
common.propKeyOnlyToClassName(FormField, 'error')
common.propKeyOnlyToClassName(FormField, 'disabled')
common.propKeyOnlyToClassName(FormField, 'inline')
common.propKeyOnlyToClassName(FormField, 'required', { label: '' })
common.rendersChildren(FormField)
common.hasSubComponents(FormField, [
FormFieldButton,
FormFieldCheckbox,
FormFieldDropdown,
FormFieldTextArea,
FormFieldGroup,
FormFieldInput,
FormFieldRadio,
FormFieldSelect,
])

describe('html controls', () => {
it('adds an HTML element child of the same type', () => {
const controls = ['button', 'input', 'select', 'textarea']

controls.forEach((control) => {
shallow(<FormField control={control} />)
.should.have.descendants(control)
})
})
})

describe('label', () => {
it('does not add a label child by default', () => {
shallow(<FormField />)
.should.not.have.descendants('label')
})
it('adds a label child', () => {
const wrapper = shallow(<FormField label='First Name' />)
wrapper
.should.have.descendants('label')

wrapper
.find('label')
.should.contain.text('First Name')
})
})
})
15 changes: 15 additions & 0 deletions test/specs/collections/Form/FormFieldButton-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'

import FormFieldButton from 'src/collections/Form/FormFieldButton'
import Button from 'src/elements/Button/Button'
import * as common from 'test/specs/commonTests'

describe('FormFieldButton', () => {
common.isConformant(FormFieldButton)

it('renders a FormField with a Button control', () => {
shallow(<FormFieldButton />)
.find('FormField')
.should.have.prop('control', Button)
})
})
15 changes: 15 additions & 0 deletions test/specs/collections/Form/FormFieldCheckbox-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'

import FormFieldCheckbox from 'src/collections/Form/FormFieldCheckbox'
import Checkbox from 'src/modules/Checkbox/Checkbox'
import * as common from 'test/specs/commonTests'

describe('FormFieldCheckbox', () => {
common.isConformant(FormFieldCheckbox)

it('renders a FormField with a Checkbox control', () => {
shallow(<FormFieldCheckbox />)
.find('FormField')
.should.have.prop('control', Checkbox)
})
})
15 changes: 15 additions & 0 deletions test/specs/collections/Form/FormFieldDropdown-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'

import FormFieldDropdown from 'src/collections/Form/FormFieldDropdown'
import Dropdown from 'src/modules/Dropdown/Dropdown'
import * as common from 'test/specs/commonTests'

describe('FormFieldDropdown', () => {
common.isConformant(FormFieldDropdown)

it('renders a FormField with a Dropdown control', () => {
shallow(<FormFieldDropdown />)
.find('FormField')
.should.have.prop('control', Dropdown)
})
})
10 changes: 10 additions & 0 deletions test/specs/collections/Form/FormFieldGroup-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import FormFieldGroup from 'src/collections/Form/FormFieldGroup'
import * as common from 'test/specs/commonTests'

describe('FormFieldGroup', () => {
common.isConformant(FormFieldGroup)
common.rendersChildren(FormFieldGroup)
common.propKeyOnlyToClassName(FormFieldGroup, 'grouped')
common.propKeyOnlyToClassName(FormFieldGroup, 'inline')
common.implementsWidthProp(FormFieldGroup, { propKey: 'widths', canEqual: true })
})
15 changes: 15 additions & 0 deletions test/specs/collections/Form/FormFieldInput-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'

import FormFieldInput from 'src/collections/Form/FormFieldInput'
import Input from 'src/elements/Input/Input'
import * as common from 'test/specs/commonTests'

describe('FormFieldInput', () => {
common.isConformant(FormFieldInput)

it('renders a FormField with a Input control', () => {
shallow(<FormFieldInput />)
.find('FormField')
.should.have.prop('control', Input)
})
})
15 changes: 15 additions & 0 deletions test/specs/collections/Form/FormFieldRadio-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'

import FormFieldRadio from 'src/collections/Form/FormFieldRadio'
import Radio from 'src/addons/Radio/Radio'
import * as common from 'test/specs/commonTests'

describe('FormFieldRadio', () => {
common.isConformant(FormFieldRadio)

it('renders a FormField with a Radio control', () => {
shallow(<FormFieldRadio />)
.find('FormField')
.should.have.prop('control', Radio)
})
})
15 changes: 15 additions & 0 deletions test/specs/collections/Form/FormFieldSelect-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'

import FormFieldSelect from 'src/collections/Form/FormFieldSelect'
import Select from 'src/addons/Select/Select'
import * as common from 'test/specs/commonTests'

describe('FormFieldSelect', () => {
common.isConformant(FormFieldSelect)

it('renders a FormField with a Select control', () => {
shallow(<FormFieldSelect />)
.find('FormField')
.should.have.prop('control', Select)
})
})
15 changes: 15 additions & 0 deletions test/specs/collections/Form/FormFieldTextArea-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'

import FormFieldTextArea from 'src/collections/Form/FormFieldTextArea'
import TextArea from 'src/addons/TextArea/TextArea'
import * as common from 'test/specs/commonTests'

describe('FormFieldTextArea', () => {
common.isConformant(FormFieldTextArea)

it('renders a FormField with a TextArea control', () => {
shallow(<FormFieldTextArea />)
.find('FormField')
.should.have.prop('control', TextArea)
})
})

0 comments on commit b2e3d68

Please sign in to comment.