application/__tests__/components/content/content-table-test.js
jest.unmock('./../../../services/base-service');
jest.unmock('./../../../services/error-service');
jest.unmock('./../../../services/content-service');
jest.unmock('./../../../components/content/content-table');
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 ContentTable from './../../../components/content/content-table';
describe('ContentTableComponent', () => {
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 el = TestUtils.renderIntoDocument(<ContentTable />);
const indicator = TestUtils.findRenderedComponentWithType(el, LoadingIndicator);
expect(indicator).not.toBeUndefined();
});
it('loads content', (done) => {
const contents = Immutable.fromJS([
{
id: 1,
uuid: '123-456',
attachment: {}
},
{
id: 2,
uuid: '987-654',
attachment: {}
}
]);
const el = TestUtils.renderIntoDocument(<ContentTable contents={contents} />);
expect(el.props.contents.size).toEqual(2);
setTimeout(() => {
const rows = TestUtils.scryRenderedDOMComponentsWithTag(el, 'tr');
// two rows plus header
expect(rows.length).toEqual(3);
done();
}, 100);
})
});