Skip to content

Commit

Permalink
tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ivansfdc committed Oct 28, 2015
1 parent 66c4f26 commit 12fb822
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 38 deletions.
14 changes: 8 additions & 6 deletions components/SLDSLookup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,14 @@ class SLDSLookup extends React.Component {
}

getFooter () {
const Footer = this.props.footerRenderer;
return <Footer ref='footer' {... this.props}
focusIndex={this.state.focusIndex}
listLength={this.state.listLength}
onClose={this.handleClose.bind(this)}
/>;
if(this.props.footerRenderer){
const Footer = this.props.footerRenderer;
return <Footer ref='footer' {... this.props}
focusIndex={this.state.focusIndex}
listLength={this.state.listLength}
onClose={this.handleClose.bind(this)}
/>;
}
}

//=================================================
Expand Down
3 changes: 2 additions & 1 deletion demo/pages/HomePage/LookupBaseDynamicSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ module.exports = React.createClass( {
<div className="slds-p-around--medium">
Dynamic list
<div className="slds-p-vertical--large">

<SLDSLookup
items={this.state.items}
label="Accounts"
type="account"
onChange={this.onChange}
onItemSelect={this.selectItem}
onItemSelect={this.handleItemSelect}
/>

</div>

</div>
Expand Down
4 changes: 2 additions & 2 deletions demo/static/bundle.js

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions dist/design-system-react.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/design-system-react.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/design-system-react.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/design-system-react.min.js.map

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions lib/SLDSLookup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,14 @@ var SLDSLookup = (function (_React$Component) {
}, {
key: 'getFooter',
value: function getFooter() {
var Footer = this.props.footerRenderer;
return _react2['default'].createElement(Footer, _extends({ ref: 'footer' }, this.props, {
focusIndex: this.state.focusIndex,
listLength: this.state.listLength,
onClose: this.handleClose.bind(this)
}));
if (this.props.footerRenderer) {
var Footer = this.props.footerRenderer;
return _react2['default'].createElement(Footer, _extends({ ref: 'footer' }, this.props, {
focusIndex: this.state.focusIndex,
listLength: this.state.listLength,
onClose: this.handleClose.bind(this)
}));
}
}

//=================================================
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "design-system-react",
"version": "0.0.18",
"version": "0.0.19",
"description": "Salesforce Lightning Design System React components",
"scripts": {
"start": "node server.js",
Expand Down
37 changes: 24 additions & 13 deletions tests/SLDSLookup/lookup.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,39 @@ describe('SLDSLookup: ', function(){
{label:'Acme Construction'}
];

let generateLookup = function(lookupInstance) {
const generateLookup = function(lookupInstance) {
let reactCmp = TestUtils.renderIntoDocument(lookupInstance);
return React.findDOMNode(reactCmp);
};

const getLookup = function(withHeader) {
return <SLDSLookup
items={items}
label="Leads"
type="lead"
headerRenderer={withHeader?SLDSLookup.DefaultHeader:null}
footerRenderer={SLDSLookup.DefaultFooter}
/>;
};

describe('component renders', function() {
it('lookup renders', function() {
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
let lookup = generateLookup(getLookup());
expect(lookup).to.not.equal(undefined);
});
});

describe('component basic props render', function() {
it('renders label', function() {
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
let lookup = generateLookup(getLookup());
let label = lookup.getElementsByTagName("label")[0];
expect(label.innerText).to.equal('Leads');
});
});

describe('accessibility markup passes', function() {
it('label for matches input id', function() {
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
let lookup = generateLookup(getLookup());
let labelFor = lookup.getElementsByTagName("label")[0].getAttribute("for");
let inputId = lookup.getElementsByTagName("input")[0].getAttribute("id");
expect(labelFor).to.equal(inputId);
Expand All @@ -45,18 +55,18 @@ describe('SLDSLookup: ', function(){

describe('accessibility aria attributes pass', function() {
it('aria-haspopup is true', function() {
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
let lookup = generateLookup(getLookup());
let ariaHaspopup = lookup.getElementsByTagName("input")[0].getAttribute("aria-haspopup");
expect(ariaHaspopup).to.equal('true');
});
it('aria-expanded is false initally', function() {
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
let lookup = generateLookup(getLookup());
let ariaExpanded = lookup.getElementsByTagName("input")[0].getAttribute("aria-expanded");
expect(ariaExpanded).to.equal('false');
});

it('aria-expanded is true when clicking on input field', function() {
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
let lookup = generateLookup(getLookup());
let input = lookup.getElementsByTagName("input")[0];
TestUtils.Simulate.click(input);
let ariaExpanded = lookup.getElementsByTagName("input")[0].getAttribute("aria-expanded");
Expand All @@ -68,7 +78,7 @@ describe('SLDSLookup: ', function(){
describe('selecting item works', function() {

it('no fixed header: focuses correct item', function() {
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
let lookup = generateLookup(getLookup());
let input = lookup.getElementsByTagName("input")[0];
TestUtils.Simulate.click(input);
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
Expand All @@ -78,7 +88,7 @@ describe('SLDSLookup: ', function(){
});

it('with fixed header: focuses correct item', function() {
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" header={<div>header</div>}/>);
let lookup = generateLookup(getLookup(true));
let input = lookup.getElementsByTagName("input")[0];
TestUtils.Simulate.click(input);
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
Expand All @@ -88,7 +98,7 @@ describe('SLDSLookup: ', function(){
});

it('selects correct item', function() {
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
let lookup = generateLookup(getLookup());
let input = lookup.getElementsByTagName("input")[0];
TestUtils.Simulate.click(input);
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
Expand All @@ -100,7 +110,7 @@ describe('SLDSLookup: ', function(){
});

it('closes lookup menu on esc', function() {
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
let lookup = generateLookup(getLookup());
let input = lookup.getElementsByTagName("input")[0];
TestUtils.Simulate.click(input);
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
Expand All @@ -110,7 +120,7 @@ describe('SLDSLookup: ', function(){
});

it('aria-expanded is false after selecting item', function() {
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
let lookup = generateLookup(getLookup());
let input = lookup.getElementsByTagName("input")[0];
TestUtils.Simulate.click(input);
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
Expand All @@ -119,13 +129,14 @@ describe('SLDSLookup: ', function(){
});

it('aria-expanded is false after selecting item', function() {
let lookup = generateLookup(<SLDSLookup items={items} label="Leads" type="lead" />);
let lookup = generateLookup(getLookup());
let input = lookup.getElementsByTagName("input")[0];
TestUtils.Simulate.click(input);
TestUtils.Simulate.keyDown(input, {key: "Down", keyCode: 40, which: 40});
let focusedItem = lookup.getElementsByTagName("ul")[0].getElementsByTagName('li')[0];
expect(focusedItem.className).to.have.string('slds-theme--shade');
});

});

});

0 comments on commit 12fb822

Please sign in to comment.