Skip to content

Commit

Permalink
Merge pull request #226 from upfluence/mb/DRA-2119
Browse files Browse the repository at this point in the history
Updated: set 23:59:59 to all date filtering toDate
  • Loading branch information
Miexil authored Jan 22, 2025
2 parents a3157fd + e549009 commit 232f3cb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
5 changes: 5 additions & 0 deletions addon/components/hyper-table-v2/filtering-renderers/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default class HyperTableV2FilteringRenderersDate extends Component<HyperT
let [fromDate, toDate] = value;

if (fromDate && toDate) {
this.sendEndOfTheDayOnDate(toDate);
this.args.handler.applyFilters(this.args.column, [
{ key: this.movingOptionKey, value: '' },
{ key: 'lower_bound', value: (+fromDate / 1000).toString() },
Expand All @@ -118,6 +119,10 @@ export default class HyperTableV2FilteringRenderersDate extends Component<HyperT
this.args.handler.removeColumn(this.args.column.definition);
}

private sendEndOfTheDayOnDate(date: Date): void {
date.setHours(23, 59, 59);
}

private _resetStates(): void {
this._currentDateValue = [];
this._currentMovingDateOption = [];
Expand Down
5 changes: 5 additions & 0 deletions addon/components/hyper-table/filters-renderers/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default class DateFiltersRenderer extends FiltersRenderer {
let [fromDate, toDate] = value;

if (fromDate && toDate) {
this._sendEndOfTheDayOnDate(toDate);
this.args.column.set('filters', [
{ key: 'lower_bound', value: (+fromDate / 1000).toString() },
{ key: 'upper_bound', value: (+toDate / 1000).toString() }
Expand All @@ -102,4 +103,8 @@ export default class DateFiltersRenderer extends FiltersRenderer {
this._currentDateValue = [];
this._currentMovingDateOption = [];
}

_sendEndOfTheDayOnDate(date: Date): void {
date.setHours(23, 59, 59);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module('Integration | Component | hyper-table-v2/filtering-renderers/date', func
this.tableManager = new TableManager();
this.rowsFetcher = new RowsFetcher();
this.handler = new TableHandler(this, this.tableManager, this.rowsFetcher);
this.handlerSpy = sinon.spy(this.handler);

sinon.stub(this.tableManager, 'fetchColumns').callsFake(() => {
return Promise.resolve({
Expand Down Expand Up @@ -49,7 +50,6 @@ module('Integration | Component | hyper-table-v2/filtering-renderers/date', func
});

test('it calls the Handler#applyOrder method correctly via the radio buttons', async function (this: TestContext, assert: Assert) {
const handlerSpy = sinon.spy(this.handler);
await render(
hbs`<HyperTableV2::FilteringRenderers::Numeric @handler={{this.handler}} @column={{this.column}} />`
);
Expand All @@ -59,8 +59,7 @@ module('Integration | Component | hyper-table-v2/filtering-renderers/date', func
'[data-control-name="hypertable__column_filtering_for_date_ordering"] .oss-toggle-buttons-btn:nth-child(1)'
);

//@ts-ignore
assert.ok(handlerSpy.applyOrder.calledWith(this.column, 'asc'));
assert.ok(this.handlerSpy.applyOrder.calledWith(this.column, 'asc'));
assert.deepEqual(this.column.order, {
direction: 'asc',
key: 'date'
Expand All @@ -70,8 +69,7 @@ module('Integration | Component | hyper-table-v2/filtering-renderers/date', func
'div[data-control-name="hypertable__column_filtering_for_date_ordering"] .oss-toggle-buttons-btn:nth-child(2)'
);

//@ts-ignore
assert.ok(handlerSpy.applyOrder.calledWith(this.column, 'desc'));
assert.ok(this.handlerSpy.applyOrder.calledWith(this.column, 'desc'));
assert.deepEqual(this.column.order, {
direction: 'desc',
key: 'date'
Expand Down Expand Up @@ -113,16 +111,14 @@ module('Integration | Component | hyper-table-v2/filtering-renderers/date', func
});

test('when the filter is set to Moving, when clicking on a filter option, applyFilter is triggered', async function (this: TestContext, assert: Assert) {
const handlerSpy = sinon.spy(this.handler);
await render(hbs`<HyperTableV2::FilteringRenderers::Date @handler={{this.handler}} @column={{this.column}} />`);

await click(
'div[data-control-name="hypertable__column_filtering_for_date_filter_by_radiogroup"] .oss-toggle-buttons-btn:nth-child(1)'
);
await click('.filters__option');
assert.ok(
//@ts-ignore
handlerSpy.applyFilters.calledWith(this.column, [
this.handlerSpy.applyFilters.calledWith(this.column, [
{ key: 'lower_bound', value: '' },
{ key: 'upper_bound', value: '' },
{ key: 'moving', value: 'today' }
Expand All @@ -139,6 +135,24 @@ module('Integration | Component | hyper-table-v2/filtering-renderers/date', func
assert.dom('div[data-control-name="hypertable__column_filtering_for_date_date_range_inputs"]').exists();
});

test('when the date is selected in Fixed mode, the end date should be set at the end of the day 23:59:59', async function (this: TestContext, assert: Assert) {
await render(hbs`<HyperTableV2::FilteringRenderers::Date @handler={{this.handler}} @column={{this.column}} />`);

await click(
'div[data-control-name="hypertable__column_filtering_for_date_filter_by_radiogroup"] .oss-toggle-buttons-btn:nth-child(2)'
);
await click('.upf-input');
(document.querySelector('.today') as HTMLElement)?.click();
(document.querySelector('.today') as HTMLElement)?.click();
const timestampSetInFilters = this.handlerSpy.applyFilters.args[0][1].find(
(filter: any) => filter.key === 'upper_bound'
)?.value;
const dateSetInFilters = new Date(timestampSetInFilters * 1000);
assert.true(dateSetInFilters.getHours() === 23);
assert.true(dateSetInFilters.getMinutes() === 59);
assert.true(dateSetInFilters.getSeconds() === 59);
});

test('clicking in the flatpickr input should open flatpickr', async function (assert: Assert) {
await render(hbs`<HyperTableV2::FilteringRenderers::Date @handler={{this.handler}} @column={{this.column}} />`);

Expand All @@ -153,29 +167,24 @@ module('Integration | Component | hyper-table-v2/filtering-renderers/date', func

module('clear column', async function () {
test('it calls the Handler#resetColumns with the column when the dedicated button is clicked', async function (this: TestContext, assert: Assert) {
const handlerSpy = sinon.spy(this.handler);
this.handler.applyFilters(this.column, [{ key: 'moving', value: 'today' }]);
this.handler.applyOrder(this.column, 'asc');

await render(hbs`<HyperTableV2::FilteringRenderers::Date @handler={{this.handler}} @column={{this.column}} />`);
await click('[data-control-name="hypertable__column_filtering_for_date_clear_filters"]');

//@ts-ignore
assert.ok(handlerSpy.resetColumns.calledWith([this.column]));
assert.ok(this.handlerSpy.resetColumns.calledWith([this.column]));
assert.equal(this.column.order, undefined);
assert.deepEqual(this.column.filters, []);
});
});

module('remove column', function () {
test('it calls the Handler#removeColumn with the column when the dedicated button is clicked', async function (this: TestContext, assert: Assert) {
const handlerSpy = sinon.spy(this.handler);

await render(hbs`<HyperTableV2::FilteringRenderers::Date @handler={{this.handler}} @column={{this.column}} />`);
await click('[data-control-name="hypertable__column_filtering_for_date_remove_column"]');

//@ts-ignore
assert.ok(handlerSpy.removeColumn.calledWith(this.column.definition));
assert.ok(this.handlerSpy.removeColumn.calledWith(this.column.definition));
});
});
});

0 comments on commit 232f3cb

Please sign in to comment.