Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion addon/core/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class TableHandler {
return this._renderingResolver;
}

this._renderingResolver = new BaseRenderingResolver(this._context)
this._renderingResolver = new BaseRenderingResolver(this._context);
return this._renderingResolver;
}

Expand Down Expand Up @@ -308,6 +308,7 @@ export default class TableHandler {
return this.tableManager.upsertColumns({ columns: this.columns }).then(({ columns }) => {
this._lastOrderedColumn = column;
this._reinitColumnsAndRows(columns);
this.triggerEvent('apply-order', column, direction);
});
}

Expand Down
39 changes: 39 additions & 0 deletions tests/unit/core/handler-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ module('Unit | core/handler', function (hooks) {
assert.equal(handler.columns.length, 4);
});

test('Handler#fetchColumns triggers the columns-loaded event', async function (this: TestContext, assert: Assert) {
const handler = new TableHandler(getContext(), this.tableManager, this.rowsFetcher);
const handlerSpy = sinon.spy(handler, 'triggerEvent');

await handler.fetchColumns();

assert.ok(handlerSpy.calledOnceWithExactly('columns-loaded'));
});

module('Handler#fetchRows', () => {
test('it adds the correct number of rows', async function (this: TestContext, assert: Assert) {
const handler = new TableHandler(getContext(), this.tableManager, this.rowsFetcher);
Expand Down Expand Up @@ -211,6 +220,16 @@ module('Unit | core/handler', function (hooks) {
assert.equal(handler.columns[1].order, undefined);
});

test('it triggers the reset-columns event', async function (this: TestContext, assert: Assert) {
const handler = new TableHandler(getContext(), this.tableManager, this.rowsFetcher);
const handlerSpy = sinon.spy(handler, 'triggerEvent');

await handler.fetchColumns();
await handler.resetColumns(handler.columns);

assert.ok(handlerSpy.calledWithExactly('reset-columns', handler.columns));
});

test('if all items where globally selected, the selection is properly reset', async function (this: TestContext, assert: Assert) {
const handler = new TableHandler(getContext(), this.tableManager, this.rowsFetcher);
await handler.fetchColumns();
Expand Down Expand Up @@ -258,6 +277,16 @@ module('Unit | core/handler', function (hooks) {
assert.equal(handler.rows.length, 3);
});

test('Handler#resetRows triggers the reset-rows event', async function (this: TestContext, assert: Assert) {
const handler = new TableHandler(getContext(), this.tableManager, this.rowsFetcher);
const handlerSpy = sinon.spy(handler, 'triggerEvent');

await handler.fetchRows();
await handler.resetRows();

assert.ok(handlerSpy.calledOnceWithExactly('reset-rows'));
});

test('Handler#removeRow', async function (this: TestContext, assert: Assert) {
const handler = new TableHandler(getContext(), this.tableManager, this.rowsFetcher);
const handlerTriggerEventSpy = sinon.spy(handler, 'triggerEvent');
Expand Down Expand Up @@ -307,6 +336,16 @@ module('Unit | core/handler', function (hooks) {
assert.equal(handler.currentPage, 1);
});

test('Handler#applyOrder triggers the apply-order event', async function (this: TestContext, assert: Assert) {
const handler = new TableHandler(getContext(), this.tableManager, this.rowsFetcher);
const handlerSpy = sinon.spy(handler, 'triggerEvent');

await handler.fetchColumns();
await handler.applyOrder(handler.columns[0], 'asc');

assert.ok(handlerSpy.calledWithExactly('apply-order', handler.columns[0], 'asc'));
});

module('Handler#toggleSelectAll', () => {
test('it selects all the loaded rows', async function (this: TestContext, assert: Assert) {
const handler = new TableHandler(getContext(), this.tableManager, this.rowsFetcher);
Expand Down