Skip to content

Commit

Permalink
Use isArray to check columns, rows type
Browse files Browse the repository at this point in the history
  • Loading branch information
quaertym authored and buschtoens committed Jul 13, 2018
1 parent 61247e5 commit e345fec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions addon/classes/Table.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { A as emberArray } from '@ember/array';
import { A as emberArray, isArray } from '@ember/array';
import { assert } from '@ember/debug';
import EmberObject, { computed, get } from '@ember/object';
import Row from 'ember-light-table/classes/Row';
Expand Down Expand Up @@ -149,8 +149,8 @@ export default class Table extends EmberObject.extend({
constructor(columns = [], rows = [], options = {}) {
super();

assert('[ember-light-table] columns must be an array if defined', columns instanceof Array);
assert('[ember-light-table] rows must be an array if defined', rows instanceof Array);
assert('[ember-light-table] columns must be an array if defined', isArray(columns));
assert('[ember-light-table] rows must be an array if defined', isArray(rows));

let _options = mergeOptionsWithGlobals(options);
let _columns = emberArray(Table.createColumns(columns));
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/classes/table-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { A as emberArray } from '@ember/array';
import { Table, Column, Row } from 'ember-light-table';
import { module, test } from 'qunit';
import DS from 'ember-data';
import EmberObject from '@ember/object';

module('Unit | Classes | Table', function() {
test('create table - default options', function(assert) {
Expand Down Expand Up @@ -33,6 +35,28 @@ module('Unit | Classes | Table', function() {
}, /\[ember-light-table] columns must be an array if defined/, 'columns is not an array');
});

test('create table - with RecordArray instance as rows', function(assert) {
assert.expect(3);

let models = ['Tom', 'Yehuda', 'Tomster'].map((name) => {
return EmberObject.create({ name });
});

let rows = DS.RecordArray.create({
content: emberArray(models),
objectAtContent(index) {
return this.get('content')[index];
}
});

let columns = [{ label: 'Name', valuePath: 'name' }];
let table = new Table(columns, rows);

assert.ok(table);
assert.equal(table.get('rows.length'), 3);
assert.equal(table.get('columns.length'), 1);
});

test('reopen table', function(assert) {
assert.equal(typeof Table.reopen, 'function', 'reopen is a function');
assert.equal(typeof Table.reopenClass, 'function', 'reopenClass is a function');
Expand Down

0 comments on commit e345fec

Please sign in to comment.