|
| 1 | +import React from 'react'; |
| 2 | +import ReactDOM from 'react-dom'; |
| 3 | +import {renderIntoDocument} from 'react-addons-test-utils'; |
| 4 | +import { expect} from 'chai'; |
| 5 | +import { Provider } from 'react-redux'; |
| 6 | +import { browserHistory } from 'react-router'; |
| 7 | +import { SearchPanel, Login, ContentPenal, Column, FeedTab } from 'components'; |
| 8 | +import createStore from 'redux/create'; |
| 9 | +import ApiClient from 'helpers/ApiClient'; |
| 10 | +const client = new ApiClient();`` |
| 11 | + |
| 12 | +describe('component', () => { |
| 13 | + describe('ContentPenal', () => { |
| 14 | + function ContentPenalInit(mockStore) { |
| 15 | + const store = createStore(browserHistory, client, mockStore); |
| 16 | + const renderer = renderIntoDocument( |
| 17 | + <Provider store={store} key="provider"> |
| 18 | + <ContentPenal /> |
| 19 | + </Provider> |
| 20 | + ); |
| 21 | + const dom = ReactDOM.findDOMNode(renderer); |
| 22 | + return {dom:dom, renderer: renderer} |
| 23 | + } |
| 24 | + var mockStore = { |
| 25 | + manage: { |
| 26 | + contents: [ |
| 27 | + { |
| 28 | + rd: false, |
| 29 | + st: false, |
| 30 | + _id: '123456', |
| 31 | + pub: 1456727194546, |
| 32 | + tt: 'css article', |
| 33 | + fnm: 'css', |
| 34 | + con: 'content...' |
| 35 | + } |
| 36 | + ], |
| 37 | + entryIndex: 0 |
| 38 | + }, |
| 39 | + auth: { |
| 40 | + user: 'test' |
| 41 | + } |
| 42 | + } |
| 43 | + const {dom, renderer} = ContentPenalInit(mockStore) |
| 44 | + it('should render correctly', () => { |
| 45 | + return expect(renderer).to.be.ok |
| 46 | + }) |
| 47 | + }) |
| 48 | + describe('Column', () => { |
| 49 | + function ColumnInit(mockStore) { |
| 50 | + const store = createStore(browserHistory, client, mockStore); |
| 51 | + const renderer = renderIntoDocument( |
| 52 | + <Provider store={store} key="provider"> |
| 53 | + <Column /> |
| 54 | + </Provider> |
| 55 | + ); |
| 56 | + const dom = ReactDOM.findDOMNode(renderer); |
| 57 | + return {dom:dom, renderer: renderer} |
| 58 | + } |
| 59 | + var mockStore = { |
| 60 | + manage: { |
| 61 | + contents: [ |
| 62 | + { |
| 63 | + rd: false, |
| 64 | + st: false, |
| 65 | + _id: '123456', |
| 66 | + pub: 1456727194546, |
| 67 | + tt: 'css article', |
| 68 | + fnm: 'css', |
| 69 | + con: 'content...' |
| 70 | + } |
| 71 | + ], |
| 72 | + selected: ['css', 0], |
| 73 | + entryIndex: 0 |
| 74 | + }, |
| 75 | + stat: { |
| 76 | + status: 'unread' |
| 77 | + }, |
| 78 | + auth: { |
| 79 | + user: 'test' |
| 80 | + } |
| 81 | + } |
| 82 | + const {dom, renderer} = ColumnInit(mockStore) |
| 83 | + it('should render correctly', () => { |
| 84 | + return expect(renderer).to.be.ok |
| 85 | + }) |
| 86 | + it('should render correct content', () => { |
| 87 | + const children = dom.getElementsByTagName('li')[0].childNodes |
| 88 | + const mockContent = mockStore.manage.contents[0] |
| 89 | + expect(children[1].textContent).to.equal(mockContent.tt) |
| 90 | + expect(children[2].textContent).to.equal(mockContent.con) |
| 91 | + expect(children[3].textContent).to.equal(mockContent.fnm) |
| 92 | + }) |
| 93 | + it('correct data-type', () => { |
| 94 | + const s = dom.getElementsByTagName('span')[0].dataset.type |
| 95 | + expect(s).to.equal('starred') |
| 96 | + }) |
| 97 | + }) |
| 98 | + describe('SearchPanel', () => { |
| 99 | + function SearchPanelInit(mockStore) { |
| 100 | + const store = createStore(browserHistory, client, mockStore); |
| 101 | + const renderer = renderIntoDocument( |
| 102 | + <Provider store={store} key="provider"> |
| 103 | + <SearchPanel /> |
| 104 | + </Provider> |
| 105 | + ); |
| 106 | + const dom = ReactDOM.findDOMNode(renderer); |
| 107 | + return {dom:dom, renderer: renderer} |
| 108 | + } |
| 109 | + describe('loading', () => { |
| 110 | + var mockStore = { |
| 111 | + feedly: { |
| 112 | + loading: true, |
| 113 | + loaded: false, |
| 114 | + closed: false |
| 115 | + }, |
| 116 | + auth: { |
| 117 | + user: 'test' |
| 118 | + } |
| 119 | + } |
| 120 | + const {dom, renderer} = SearchPanelInit(mockStore) |
| 121 | + it('should render correctly', () => { |
| 122 | + return expect(renderer).to.be.ok |
| 123 | + }) |
| 124 | + it('should render correct value', () => { |
| 125 | + const text = dom.getElementsByTagName('ul')[0].childNodes[0].textContent |
| 126 | + expect(text).to.equal('LOADING') |
| 127 | + }) |
| 128 | + }) |
| 129 | + describe('loaded', () => { |
| 130 | + var mockStore = { |
| 131 | + auth: { |
| 132 | + user: 'test' |
| 133 | + }, |
| 134 | + feedly: { |
| 135 | + closed: false, |
| 136 | + loading: false, |
| 137 | + loaded: true, |
| 138 | + data: { |
| 139 | + results: [ |
| 140 | + { |
| 141 | + website: 'https://www.google.com/s2/favicons?domain=css-tricks.com&alt=feed', |
| 142 | + title: 'css-tricks', |
| 143 | + description: 'web design' |
| 144 | + } |
| 145 | + ] |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + const {dom, renderer} = SearchPanelInit(mockStore) |
| 150 | + it('should render correctly', () => { |
| 151 | + return expect(renderer).to.be.ok |
| 152 | + }) |
| 153 | + it('should render correct value', () => { |
| 154 | + const text = dom.getElementsByTagName('p')[0].textContent |
| 155 | + expect(text).to.equal(mockStore.feedly.data.results[0].description) |
| 156 | + }) |
| 157 | + }) |
| 158 | + }) |
| 159 | +}) |
0 commit comments