Skip to content

Commit

Permalink
get courseList to work in react 16
Browse files Browse the repository at this point in the history
Change-Id: I18c5d2b98a1b6d5a16112b67813b3144e28f2060
Reviewed-on: https://gerrit.instructure.com/164012
Tested-by: Jenkins
Reviewed-by: Steven Burnett <[email protected]>
Product-Review: Ryan Shaw <[email protected]>
QA-Review: Ryan Shaw <[email protected]>
  • Loading branch information
ryankshaw committed Sep 11, 2018
1 parent 4234710 commit 53cdbce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
31 changes: 10 additions & 21 deletions app/jsx/epub_exports/CourseList.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,14 @@ import PropTypes from 'prop-types'
import _ from 'underscore'
import CourseListItem from '../epub_exports/CourseListItem'

const CourseList = React.createClass({
displayName: 'CourseList',
propTypes: {
courses: PropTypes.object,
},
export default function CourseList(props) {
return (
<ul className="ig-list">
{_.map(props.courses, (course, key) => <CourseListItem key={key} course={course} />)}
</ul>
)
}

//
// Rendering
//

render () {
return (
<ul className="ig-list">
{_.map(this.props.courses, function (course, key) {
return <CourseListItem key={key} course={course} />;
})}
</ul>
);
}
});

export default CourseList
CourseList.propTypes = {
courses: PropTypes.object
}
20 changes: 8 additions & 12 deletions spec/coffeescripts/jsx/epub_exports/CourseListSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
*/

import React from 'react'
import ReactDOM from 'react-dom'
import TestUtils from 'react-addons-test-utils'
import {mount} from 'enzyme'
import CourseList from 'jsx/epub_exports/CourseList'

QUnit.module('CourseListSpec', {
Expand All @@ -37,18 +36,15 @@ QUnit.module('CourseListSpec', {
})

test('render', function() {
let CourseListElement = <CourseList courses={{}} />
let component = TestUtils.renderIntoDocument(CourseListElement)
let node = ReactDOM.findDOMNode(component)
equal(node.querySelectorAll('li').length, 0, 'should not render list items')
ReactDOM.unmountComponentAtNode(node.parentNode)
CourseListElement = <CourseList courses={this.props} />
component = TestUtils.renderIntoDocument(CourseListElement)
node = ReactDOM.findDOMNode(component)
let component = mount(<CourseList courses={{}} />)
equal(component.find('li').length, 0, 'should not render list items')
component.unmount()

component = mount(<CourseList courses={this.props} />)
equal(
node.querySelectorAll('li').length,
component.find('li').length,
Object.keys(this.props).length,
'should have an li element per course in @props'
)
ReactDOM.unmountComponentAtNode(node.parentNode)
component.unmount()
})

0 comments on commit 53cdbce

Please sign in to comment.