Ejemplo n.º 1
0
test('render', function() {
  const DashCard = <DashboardCard {...this.props} />
  this.component = TestUtils.renderIntoDocument(DashCard)
  const $html = $(ReactDOM.findDOMNode(this.component))
  ok($html.attr('class').match(/DashboardCard/))
  const renderSpy = sandbox.spy(this.component, 'render')
  ok(!renderSpy.called, 'precondition')
  CourseActivitySummaryStore.setState({streams: {1: {stream: this.stream}}})
  ok(renderSpy.called, 'should re-render on state update')
})
test('getStateForCourse', function() {
  ok(
    has(CourseActivitySummaryStore.getStateForCourse(), 'streams'),
    'should return root state object when no courseId is provided'
  )
  const spy = sandbox.stub(CourseActivitySummaryStore, '_fetchForCourse').returns(true)
  ok(
    isEmpty(CourseActivitySummaryStore.getStateForCourse(1)),
    'should return empty object for course id not already in state'
  )
  ok(spy.called, 'should call _fetchForCourse to fetch stream info for course')
  CourseActivitySummaryStore.setState({streams: {1: {stream: this.stream}}})
  deepEqual(
    CourseActivitySummaryStore.getStateForCourse(1),
    {stream: this.stream},
    'should return stream if present'
  )
})
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

import TestUtils from 'react-addons-test-utils'
import {has, isEmpty} from 'lodash'
import CourseActivitySummaryStore from 'jsx/dashboard_card/CourseActivitySummaryStore'

QUnit.module('CourseActivitySummaryStore', {
  setup() {
    CourseActivitySummaryStore.setState({streams: {}})
    this.server = sinon.fakeServer.create()
    this.stream = [
      {
        type: 'DiscussionTopic',
        unread_count: 2,
        count: 7
      },
      {
        type: 'Conversation',
        unread_count: 0,
        count: 3
      }
    ]
  },
  teardown() {