Skip to content

Commit 1da287a

Browse files
committed
Add karma-spec-reporter and refactor button tests wtih Adam
1 parent 671ee23 commit 1da287a

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

components/SLDSLookup/index.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class SLDSLookup extends React.Component {
3636
};
3737
}
3838

39+
componentDidUpdate(){
40+
React.findDOMNode(this.refs.lookup).focus();
41+
}
42+
3943
//=================================================
4044
// Using down/up keys, set Focus on list item and assign it to aria-activedescendant attribute in input.
4145
// Need to keep track of filtered list length to be able to increment/decrement the focus index so it's contained to the number of available list items.
@@ -72,7 +76,6 @@ class SLDSLookup extends React.Component {
7276
handleDeleteSelected() {
7377
this.setState({
7478
selectedIndex: null,
75-
isOpen: false
7679
});
7780
}
7881

@@ -181,6 +184,7 @@ class SLDSLookup extends React.Component {
181184
<InputIcon name="search"/>
182185
<input
183186
id="lookup"
187+
ref="lookup"
184188
className={inputClasses}
185189
type="text"
186190
aria-label="lookup"

demo/pages/HomePage/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ module.exports = React.createClass( {
5858
</div>
5959
<main className='stage-main slds-grid slds-wrap slds-grow' role='main'>
6060
<div className='region region--main slds-grow slds-size--1-of-1 slds-medium-size--1-of-2 slds-large-size--8-of-12 slds-col-rule--right slds-p-around--large'>
61+
<LookupBaseSection />
6162

6263
<ButtonSection />
6364

6465
<PicklistBaseSection />
6566

6667
<ModalSection />
6768

68-
<LookupBaseSection />
6969

7070
<DatePickerSingleSelectSection />
7171

karma.conf.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = function(config) {
3939
// test results reporter to use
4040
// possible values: 'dots', 'progress'
4141
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
42-
reporters: ['progress'],
42+
reporters: ['spec'],
4343

4444

4545
// web server port
@@ -77,7 +77,8 @@ module.exports = function(config) {
7777
require('karma-chai-sinon'),
7878
require('karma-sourcemap-loader'),
7979
require('karma-phantomjs-launcher'),
80-
require('karma-chrome-launcher')
80+
require('karma-chrome-launcher'),
81+
require('karma-spec-reporter'),
8182
]
8283
})
8384
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"compile": "babel -d lib/ components/",
1010
"prepublish": "npm run compile",
1111
"test": "scripts/test --single-run"
12-
1312
},
1413
"repository": {
1514
"type": "git",
@@ -50,6 +49,7 @@
5049
"karma-mocha": "^0.2.0",
5150
"karma-phantomjs-launcher": "^0.2.1",
5251
"karma-sourcemap-loader": "^0.3.5",
52+
"karma-spec-reporter": "0.0.20",
5353
"karma-webpack": "^1.7.0",
5454
"mocha": "^2.3.3",
5555
"phantomjs": "^1.9.18",

tests/SLDSButton/button.test.jsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ describe('SLDSButton: ', function(){
99
alert('Button Clicked');
1010
};
1111

12+
//TODO: create function to generate button component and pass to each it block
13+
1214
beforeEach(function() {
1315
sandbox = sinon.sandbox.create();
1416
reactCmp = TestUtils.renderIntoDocument(<SLDSButton label='Test' variant='brand' icon='download' onClick={handleClick} />);
@@ -19,6 +21,19 @@ describe('SLDSButton: ', function(){
1921
sandbox.restore();
2022
});
2123

24+
describe('variants', function() {
25+
});
26+
27+
describe('behavior', function() {
28+
it('button onClick invokes method from props', function() {
29+
let onClick = sinon.spy();
30+
let reactCmp = TestUtils.renderIntoDocument(<SLDSButton label='Test' onClick={onClick} />);
31+
let button = React.findDOMNode(reactCmp);
32+
TestUtils.Simulate.click(button);
33+
expect(onClick.calledOnce).to.be.true;
34+
});
35+
});
36+
2237
it('button renders', function() {
2338
expect(button).to.not.equal(null);
2439
});
@@ -28,14 +43,4 @@ describe('SLDSButton: ', function(){
2843
expect(label).to.equal('Test');
2944
});
3045

31-
it('button onClick invokes method from props', function() {
32-
let _savedAlert = window.alert;
33-
try {
34-
let spy = sinon.spy(window, 'alert');
35-
TestUtils.Simulate.click(button);
36-
sinon.assert.called(spy);
37-
}
38-
finally { window.alert = _savedAlert; }
39-
});
40-
4146
});

0 commit comments

Comments
 (0)