From 24bb81e5dd152808d5103a6757aff89c92064314 Mon Sep 17 00:00:00 2001 From: Olympe Lespagnon Date: Mon, 27 Oct 2025 10:40:01 +0100 Subject: [PATCH 1/3] Trigger an 'apply-order' event --- addon/core/handler.ts | 3 ++- tests/unit/core/handler-test.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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..95408c21 100644 --- a/tests/unit/core/handler-test.ts +++ b/tests/unit/core/handler-test.ts @@ -307,6 +307,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.calledWith('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); From f331bade11d97a1225896904b6f0f56829e76e74 Mon Sep 17 00:00:00 2001 From: Olympe Lespagnon Date: Mon, 27 Oct 2025 10:40:18 +0100 Subject: [PATCH 2/3] Add missing events tests --- tests/unit/core/handler-test.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/unit/core/handler-test.ts b/tests/unit/core/handler-test.ts index 95408c21..56f34f18 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.calledWith('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.calledWith('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.calledWith('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'); From 391ac4b99d5eab594cdd5aae60de538eb80f1941 Mon Sep 17 00:00:00 2001 From: Olympe Lespagnon Date: Mon, 27 Oct 2025 11:24:20 +0100 Subject: [PATCH 3/3] Make tests more precise with 'called (once) with exactly' --- tests/unit/core/handler-test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/core/handler-test.ts b/tests/unit/core/handler-test.ts index 56f34f18..3aed278f 100644 --- a/tests/unit/core/handler-test.ts +++ b/tests/unit/core/handler-test.ts @@ -39,7 +39,7 @@ module('Unit | core/handler', function (hooks) { await handler.fetchColumns(); - assert.ok(handlerSpy.calledWith('columns-loaded')); + assert.ok(handlerSpy.calledOnceWithExactly('columns-loaded')); }); module('Handler#fetchRows', () => { @@ -227,7 +227,7 @@ module('Unit | core/handler', function (hooks) { await handler.fetchColumns(); await handler.resetColumns(handler.columns); - assert.ok(handlerSpy.calledWith('reset-columns', 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) { @@ -284,7 +284,7 @@ module('Unit | core/handler', function (hooks) { await handler.fetchRows(); await handler.resetRows(); - assert.ok(handlerSpy.calledWith('reset-rows')); + assert.ok(handlerSpy.calledOnceWithExactly('reset-rows')); }); test('Handler#removeRow', async function (this: TestContext, assert: Assert) { @@ -343,7 +343,7 @@ module('Unit | core/handler', function (hooks) { await handler.fetchColumns(); await handler.applyOrder(handler.columns[0], 'asc'); - assert.ok(handlerSpy.calledWith('apply-order', handler.columns[0], 'asc')); + assert.ok(handlerSpy.calledWithExactly('apply-order', handler.columns[0], 'asc')); }); module('Handler#toggleSelectAll', () => {