|
13 | 13 | })(this, function (exports) { |
14 | 14 | 'use strict'; |
15 | 15 |
|
| 16 | + var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; |
| 17 | + |
| 18 | + var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); |
| 19 | + |
| 20 | + var _get = function get(_x2, _x3, _x4) { var _again = true; _function: while (_again) { var object = _x2, property = _x3, receiver = _x4; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x2 = parent; _x3 = property; _x4 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; |
| 21 | + |
| 22 | + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } |
| 23 | + |
| 24 | + function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } |
| 25 | + |
16 | 26 | var ReactTestUtils = React.addons.TestUtils; |
17 | 27 | var expect = chai.expect; |
18 | 28 |
|
|
2151 | 2161 | expect(this.clicked).to.eq(true); |
2152 | 2162 | }); |
2153 | 2163 | }); |
| 2164 | + |
| 2165 | + describe('table with no data', function () { |
| 2166 | + context('when noDataText prop is null', function () { |
| 2167 | + before(function () { |
| 2168 | + this.component = ReactDOM.render(React.createElement(Reactable.Table, { data: [], columns: ['State', 'Description', 'Tag'] }), ReactableTestUtils.testNode()); |
| 2169 | + }); |
| 2170 | + |
| 2171 | + after(ReactableTestUtils.resetTestEnvironment); |
| 2172 | + |
| 2173 | + it('does not render the reactable-no-data element', function () { |
| 2174 | + expect($('.reactable-no-data').length).to.eq(0); |
| 2175 | + }); |
| 2176 | + }); |
| 2177 | + |
| 2178 | + context('when initialized without <Tr>s', function () { |
| 2179 | + before(function () { |
| 2180 | + this.component = ReactDOM.render(React.createElement(Reactable.Table, { className: 'table', id: 'table', columns: ['State', 'Description', 'Tag'], noDataText: 'No matching records found.' }), ReactableTestUtils.testNode()); |
| 2181 | + }); |
| 2182 | + |
| 2183 | + after(ReactableTestUtils.resetTestEnvironment); |
| 2184 | + |
| 2185 | + it('shows the "no data" message', function () { |
| 2186 | + var $text = $('.reactable-no-data').text(); |
| 2187 | + expect($text).to.eq('No matching records found.'); |
| 2188 | + }); |
| 2189 | + }); |
| 2190 | + |
| 2191 | + context('when filtered without any matches', function () { |
| 2192 | + before(function () { |
| 2193 | + this.component = ReactDOM.render(React.createElement( |
| 2194 | + Reactable.Table, |
| 2195 | + { className: 'table', id: 'table', |
| 2196 | + filterable: ['State', 'Tag'], |
| 2197 | + filterPlaceholder: 'Filter Results', |
| 2198 | + filterBy: 'xxxxx', |
| 2199 | + noDataText: 'No matching records found.', |
| 2200 | + columns: ['State', 'Description', 'Tag'] }, |
| 2201 | + React.createElement( |
| 2202 | + Reactable.Tr, |
| 2203 | + null, |
| 2204 | + React.createElement( |
| 2205 | + Reactable.Td, |
| 2206 | + { column: 'State' }, |
| 2207 | + 'New York' |
| 2208 | + ), |
| 2209 | + React.createElement( |
| 2210 | + Reactable.Td, |
| 2211 | + { column: 'Description' }, |
| 2212 | + 'this is some text' |
| 2213 | + ), |
| 2214 | + React.createElement( |
| 2215 | + Reactable.Td, |
| 2216 | + { column: 'Tag' }, |
| 2217 | + 'new' |
| 2218 | + ) |
| 2219 | + ), |
| 2220 | + React.createElement( |
| 2221 | + Reactable.Tr, |
| 2222 | + null, |
| 2223 | + React.createElement( |
| 2224 | + Reactable.Td, |
| 2225 | + { column: 'State' }, |
| 2226 | + 'New Mexico' |
| 2227 | + ), |
| 2228 | + React.createElement( |
| 2229 | + Reactable.Td, |
| 2230 | + { column: 'Description' }, |
| 2231 | + 'lorem ipsum' |
| 2232 | + ), |
| 2233 | + React.createElement( |
| 2234 | + Reactable.Td, |
| 2235 | + { column: 'Tag' }, |
| 2236 | + 'old' |
| 2237 | + ) |
| 2238 | + ), |
| 2239 | + React.createElement( |
| 2240 | + Reactable.Tr, |
| 2241 | + null, |
| 2242 | + React.createElement( |
| 2243 | + Reactable.Td, |
| 2244 | + { column: 'State' }, |
| 2245 | + 'Colorado' |
| 2246 | + ), |
| 2247 | + React.createElement( |
| 2248 | + Reactable.Td, |
| 2249 | + { column: 'Description' }, |
| 2250 | + 'new description that shouldnt match filter' |
| 2251 | + ), |
| 2252 | + React.createElement( |
| 2253 | + Reactable.Td, |
| 2254 | + { column: 'Tag' }, |
| 2255 | + 'old' |
| 2256 | + ) |
| 2257 | + ), |
| 2258 | + React.createElement( |
| 2259 | + Reactable.Tr, |
| 2260 | + null, |
| 2261 | + React.createElement( |
| 2262 | + Reactable.Td, |
| 2263 | + { column: 'State' }, |
| 2264 | + 'Alaska' |
| 2265 | + ), |
| 2266 | + React.createElement( |
| 2267 | + Reactable.Td, |
| 2268 | + { column: 'Description' }, |
| 2269 | + 'bacon' |
| 2270 | + ), |
| 2271 | + React.createElement( |
| 2272 | + Reactable.Td, |
| 2273 | + { column: 'Tag' }, |
| 2274 | + 'renewed' |
| 2275 | + ) |
| 2276 | + ) |
| 2277 | + ), ReactableTestUtils.testNode()); |
| 2278 | + }); |
| 2279 | + |
| 2280 | + after(ReactableTestUtils.resetTestEnvironment); |
| 2281 | + |
| 2282 | + it('shows the "no data" message', function () { |
| 2283 | + var text = $('.reactable-no-data').text(); |
| 2284 | + expect(text).to.eq('No matching records found.'); |
| 2285 | + }); |
| 2286 | + }); |
| 2287 | + |
| 2288 | + context('when initialized with an empty array for `data` prop', function () { |
| 2289 | + before(function () { |
| 2290 | + this.component = ReactDOM.render(React.createElement(Reactable.Table, { data: [], className: 'table', id: 'table', columns: ['State', 'Description', 'Tag'], noDataText: 'No matching records found.' }), ReactableTestUtils.testNode()); |
| 2291 | + }); |
| 2292 | + |
| 2293 | + after(ReactableTestUtils.resetTestEnvironment); |
| 2294 | + |
| 2295 | + it('shows the "no data" message', function () { |
| 2296 | + var $text = $('.reactable-no-data').text(); |
| 2297 | + expect($text).to.eq('No matching records found.'); |
| 2298 | + }); |
| 2299 | + }); |
| 2300 | + }); |
| 2301 | + |
| 2302 | + describe('visibleItems()', function () { |
| 2303 | + var _Reactable = Reactable; |
| 2304 | + var Table = _Reactable.Table; |
| 2305 | + var Thead = _Reactable.Thead; |
| 2306 | + var Tr = _Reactable.Tr; |
| 2307 | + var Th = _Reactable.Th; |
| 2308 | + var Td = _Reactable.Td; |
| 2309 | + |
| 2310 | + var data = [{ name: "Lee SomeoneElse", age: 18 }, { name: "Lee Salminen", age: 23 }, { name: "No Age", age: null }]; |
| 2311 | + |
| 2312 | + var Tester = (function (_React$Component) { |
| 2313 | + _inherits(Tester, _React$Component); |
| 2314 | + |
| 2315 | + function Tester() { |
| 2316 | + _classCallCheck(this, Tester); |
| 2317 | + |
| 2318 | + _get(Object.getPrototypeOf(Tester.prototype), 'constructor', this).apply(this, arguments); |
| 2319 | + } |
| 2320 | + |
| 2321 | + _createClass(Tester, [{ |
| 2322 | + key: 'componentDidMount', |
| 2323 | + value: function componentDidMount() { |
| 2324 | + this.props.run && this.props.run(this); |
| 2325 | + } |
| 2326 | + }, { |
| 2327 | + key: 'render', |
| 2328 | + value: function render() { |
| 2329 | + return React.createElement( |
| 2330 | + Table, |
| 2331 | + _extends({ ref: 'table', className: 'table', id: 'table', |
| 2332 | + filterable: ['Name', 'Age'] }, this.props), |
| 2333 | + React.createElement( |
| 2334 | + Thead, |
| 2335 | + null, |
| 2336 | + React.createElement( |
| 2337 | + Th, |
| 2338 | + { column: 'Name' }, |
| 2339 | + 'The Name' |
| 2340 | + ), |
| 2341 | + React.createElement( |
| 2342 | + Th, |
| 2343 | + { column: 'Age' }, |
| 2344 | + 'The Age' |
| 2345 | + ) |
| 2346 | + ), |
| 2347 | + data.map(function (item, i) { |
| 2348 | + return React.createElement( |
| 2349 | + Tr, |
| 2350 | + { key: i, i: i < 2 ? i : null }, |
| 2351 | + React.createElement(Td, { column: 'Name', data: item.name }), |
| 2352 | + React.createElement(Td, { column: 'Age', data: item.age }) |
| 2353 | + ); |
| 2354 | + }), |
| 2355 | + React.createElement( |
| 2356 | + Tr, |
| 2357 | + { i: true }, |
| 2358 | + React.createElement(Td, { column: 'Name', data: "hi" }), |
| 2359 | + React.createElement(Td, { column: 'Age', data: 5 }) |
| 2360 | + ), |
| 2361 | + React.createElement( |
| 2362 | + Tr, |
| 2363 | + { id: "id" }, |
| 2364 | + React.createElement(Td, { column: 'Name', data: "hi" }), |
| 2365 | + React.createElement(Td, { column: 'Age', data: 7 }) |
| 2366 | + ) |
| 2367 | + ); |
| 2368 | + } |
| 2369 | + }]); |
| 2370 | + |
| 2371 | + return Tester; |
| 2372 | + })(React.Component); |
| 2373 | + |
| 2374 | + var doTest = function doTest(runMe) { |
| 2375 | + var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; |
| 2376 | + return ReactDOM.render(React.createElement(Tester, _extends({ run: runMe }, options)), ReactableTestUtils.testNode()); |
| 2377 | + }; |
| 2378 | + |
| 2379 | + after(ReactableTestUtils.resetTestEnvironment); |
| 2380 | + |
| 2381 | + it('works', function () { |
| 2382 | + doTest(function (me) { |
| 2383 | + var items = me.refs.table.visibleItems(); |
| 2384 | + expect(items.length).to.eql(5); |
| 2385 | + expect(items[0].Age).to.eql(18); |
| 2386 | + }); |
| 2387 | + }); |
| 2388 | + it('works when filtered', function () { |
| 2389 | + doTest(function (me) { |
| 2390 | + var items = me.refs.table.visibleItems(); |
| 2391 | + expect(items.length).to.eql(2); |
| 2392 | + expect(items[1].Age).to.eql(23); |
| 2393 | + }, { filterBy: 'lee' }); |
| 2394 | + }); |
| 2395 | + it('works when paged', function () { |
| 2396 | + doTest(function (me) { |
| 2397 | + var items = me.refs.table.visibleItems(); |
| 2398 | + expect(items.length).to.eql(1); |
| 2399 | + expect(items[0].Age).to.eql(18); |
| 2400 | + }, { itemsPerPage: 1 }); |
| 2401 | + }); |
| 2402 | + it('has keys', function () { |
| 2403 | + doTest(function (me) { |
| 2404 | + var items = me.refs.table.visibleItems(); |
| 2405 | + expect(items[1].id).to.eql(1); |
| 2406 | + // id is not defined and key is a string |
| 2407 | + expect(items[2].id).to.eql("2"); |
| 2408 | + // Falsy ids still count |
| 2409 | + expect(items[0].id).to.eql(0); |
| 2410 | + expect(items[3].id).to.eql(true); |
| 2411 | + expect(items[4].id).to.eql("id"); |
| 2412 | + }); |
| 2413 | + }); |
| 2414 | + }); |
2154 | 2415 | }); |
2155 | 2416 | }); |
0 commit comments