diff --git a/addon/core/handler.ts b/addon/core/handler.ts index 887d75c5..5c381ec0 100644 --- a/addon/core/handler.ts +++ b/addon/core/handler.ts @@ -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; } @@ -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); }); } diff --git a/tests/unit/core/handler-test.ts b/tests/unit/core/handler-test.ts index dd7d8e64..3aed278f 100644 --- a/tests/unit/core/handler-test.ts +++ b/tests/unit/core/handler-test.ts @@ -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); @@ -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(); @@ -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'); @@ -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);