-
Notifications
You must be signed in to change notification settings - Fork 820
Commit
* feat(form-element): Add tightened modifier * Add snapshots and documentation * Add snapshots and documentation * Fix path * Update snapshots * Lint * Make sure examples have unique IDs * 😢 * Update record detail * Update AT on edit button * feat(form-element): Add tests * Remove unused props * Update example to use stacked checkbox variant
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved | ||
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license | ||
/* eslint-env jest */ | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { shallow, render } from 'enzyme'; | ||
|
||
import { FormElement } from '../base/example'; | ||
import { Input } from '../../input/base/example'; | ||
|
||
describe('Form Element', () => { | ||
it('renders without crashing', () => { | ||
ReactDOM.render(<FormElement />, document.createElement('div')); | ||
}); | ||
|
||
it('renders a label targeting the html element', () => { | ||
const example = shallow( | ||
<FormElement label="Form label" inputId="input-1"> | ||
<Input id="input-1" /> | ||
</FormElement> | ||
); | ||
const rendered = example.render(); | ||
expect(example.find('.slds-form-element__label')).toHaveLength(1); | ||
expect(rendered.find('[for="input-1"]')).toHaveLength(1); | ||
expect(example.find('#input-1')).toHaveLength(1); | ||
}); | ||
|
||
it('renders a required field', () => { | ||
const example = shallow( | ||
<FormElement label="Form label" inputId="input-1" required> | ||
<Input id="input-1" required /> | ||
</FormElement> | ||
); | ||
expect(example.find('.slds-required')).toHaveLength(1); | ||
}); | ||
|
||
it('renders a form field with an error', () => { | ||
const example = shallow( | ||
<FormElement | ||
className="slds-has-error" | ||
label="Form label" | ||
inputId="input-1" | ||
errorId="error-1" | ||
required | ||
message="This field is required" | ||
> | ||
<Input id="input-1" required aria-describedby="error-1" /> | ||
</FormElement> | ||
); | ||
expect(example.find('#error-1')).toHaveLength(1); | ||
expect(example.find('[aria-describedby="error-1"]')).toHaveLength(1); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved | ||
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license | ||
/* eslint-env jest */ | ||
|
||
import React from 'react'; | ||
import createHelpers from '../../../../jest.setup'; | ||
import { FormElement } from '../base/example'; | ||
import { Input } from '../../input/base/example'; | ||
import ButtonIcon from '../../button-icons/'; | ||
|
||
const { matchesMarkupAndStyle } = createHelpers(__dirname); | ||
|
||
describe('Form Element', () => { | ||
it('renders base form element with input', () => | ||
matchesMarkupAndStyle( | ||
<FormElement label="Form label" inputId="input-1"> | ||
<Input id="input-1" /> | ||
</FormElement> | ||
)); | ||
it('renders base required form element with input', () => | ||
matchesMarkupAndStyle( | ||
<FormElement label="Form label" inputId="input-1" required> | ||
<Input id="input-1" required /> | ||
</FormElement> | ||
)); | ||
it('renders base errored form element with input', () => | ||
matchesMarkupAndStyle( | ||
<FormElement | ||
className="slds-has-error" | ||
label="Form label" | ||
inputId="input-1" | ||
errorId="error-1" | ||
required | ||
message="This field is required" | ||
> | ||
<Input id="input-1" required aria-describedby="error-1" /> | ||
</FormElement> | ||
)); | ||
it('renders inline editable form element in view mode', () => | ||
matchesMarkupAndStyle( | ||
<div className="slds-form-element slds-form-element_small slds-form-element_edit slds-hint-parent"> | ||
<span className="slds-form-element__label">Status</span> | ||
<div className="slds-form-element__control"> | ||
<span className="slds-form-element__static slds-border_bottom"> | ||
In Progress | ||
</span> | ||
<ButtonIcon | ||
iconClassName="slds-button__icon_hint" | ||
symbol="edit" | ||
assistiveText="Edit: Status" | ||
title="Edit: Status" | ||
/> | ||
</div> | ||
</div> | ||
)); | ||
it('renders condensed form element in view mode', () => | ||
matchesMarkupAndStyle( | ||
<div className="slds-form-element slds-form-element_small slds-form-element_edit slds-form-element_small"> | ||
<span className="slds-form-element__label">Status</span> | ||
<div className="slds-form-element__control"> | ||
<span className="slds-form-element__static slds-border_bottom"> | ||
In Progress | ||
</span> | ||
</div> | ||
</div> | ||
)); | ||
}); |