application/__tests__/components/content/content-grid-test.js
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import Immutable from 'immutable';
import sinon from 'sinon';
import AltTestingUtils from 'alt-utils/lib/AltTestingUtils';
import fetch from './../../../util/mock-fetch';
import {ContentService, ContentStore} from './../../../services/content-service';
import LoadingIndicator from './../../../components/common/loading-indicator';
import {UnwrappedContentGrid, UnwrappedContentTile} from './../../../components/content/content-grid';
describe('ContentGridComponent', () => {
beforeEach(() => {
jasmine.clock().uninstall();
sinon.stub(window, 'fetch').returns(fetch({
'items': [
{
id: 1,
uuid: '123-456',
attachment: {}
},
{
id: 2,
uuid: '987-654',
attachment: {}
}
],
'first': 1,
'before': 1,
'current': 1,
'last': 1,
'next': 1,
'total_pages': 1,
'total_items': 1,
'limit': 1
}));
});
afterEach(() => {
window.fetch.restore();
});
it('loads indicator', () => {
const fetching = {'isFetching':true};
const el = TestUtils.renderIntoDocument(<UnwrappedContentGrid content={fetching} />);
const indicator = TestUtils.findRenderedComponentWithType(el, LoadingIndicator);
expect(indicator).not.toBeUndefined();
});
it('loads content', () => {
const items = Immutable.fromJS([
{
id: 1,
uuid: '123-456',
attachment: {}
},
{
id: 2,
uuid: '987-654',
attachment: {}
}
]);
const fetching = {'isFetching':true};
const el = TestUtils.renderIntoDocument(<UnwrappedContentGrid content={fetching} items={items} />);
expect(el.props.items.size).toEqual(2);
setTimeout(() => {
const rows = TestUtils.scryRenderedDOMComponentsWithClass(el, 'grid-tile');
// two rows plus header
expect(rows.length).toEqual(2);
}, 100);
})
});