mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) New date filter with a calendar view
Summary: Implements the new date filtering panel. Design results from long discussion between: Alex, Anais, Cyprien and Dmitry. Test environment: https://grist-new-date-range-filter.fly.dev/ Test Plan: Include various new tests. Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3720
This commit is contained in:
62
test/common/RelativeDates.ts
Normal file
62
test/common/RelativeDates.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import {DEPS, getMatchingDoubleRelativeDate} from 'app/client/ui/RelativeDatesOptions';
|
||||
import sinon from 'sinon';
|
||||
import {assert} from 'chai';
|
||||
import moment from 'moment-timezone';
|
||||
import {diffUnit} from 'app/common/RelativeDates';
|
||||
|
||||
const CURRENT_TIME = moment.tz('2022-09-26T12:13:32.018Z', 'utc');
|
||||
const now = () => moment(CURRENT_TIME);
|
||||
|
||||
describe('RelativeDates', function() {
|
||||
const sandbox = sinon.createSandbox();
|
||||
|
||||
before(() => {
|
||||
sinon.stub(DEPS, 'getCurrentTime').returns(now());
|
||||
});
|
||||
|
||||
after(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
describe('getMatchingDoubleRelativeDate', function() {
|
||||
it('should work correctly', function() {
|
||||
assert.deepEqual(
|
||||
getMatchingDoubleRelativeDate(getDateValue('10/1/2022'), {unit: 'month'}),
|
||||
[{unit: 'month', quantity: 1}]
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
getMatchingDoubleRelativeDate(getDateValue('9/19/2022'), {unit: 'week'}),
|
||||
[{unit: 'week', quantity: -1}, {quantity: 1, unit: 'day'}]
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
getMatchingDoubleRelativeDate(getDateValue('9/21/2022'), {unit: 'week'}),
|
||||
[{unit: 'week', quantity: -1}, {quantity: 3, unit: 'day'}]
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
getMatchingDoubleRelativeDate(getDateValue('9/30/2022'), {unit: 'month'}),
|
||||
[{unit: 'month', quantity: 0}, {quantity: 29, unit: 'day'}]
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
getMatchingDoubleRelativeDate(getDateValue('10/1/2022'), {unit: 'month'}),
|
||||
[{unit: 'month', quantity: 1}]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('diffUnit', function() {
|
||||
it('should work correctly', function() {
|
||||
assert.equal(diffUnit(moment('2022-09-30'), moment('2022-10-01'), 'month'), -1);
|
||||
assert.equal(diffUnit(moment('2022-10-01'), moment('2022-09-30'), 'month'), 1);
|
||||
assert.equal(diffUnit(moment('2022-09-30'), moment('2022-10-01'), 'week'), 0);
|
||||
assert.equal(diffUnit(moment('2022-09-30'), moment('2022-10-02'), 'week'), -1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function getDateValue(date: string): number {
|
||||
return moment.tz(date, "MM-DD-YYYY", 'utc').valueOf()/1000;
|
||||
}
|
||||
Reference in New Issue
Block a user