Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Default export #233

Merged
merged 4 commits into from
Mar 20, 2018
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
8 changes: 7 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# CHANGELOG

### 1.1.0
### 1.1.x

**1.1.1:**

[#233](https://github.com/marmelab/EventDrops/pull/233): fix default export for users without module bundler

**1.1.0:**

[#232](https://github.com/marmelab/EventDrops/pull/232): minor README fixes
[#231](https://github.com/marmelab/EventDrops/pull/231): allow to display chart from end to start
Expand Down
10 changes: 2 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ import zoom from './zoom';
import { addMetaballsDefs } from './metaballs';

import './style.css';
import { withinRange } from './withinRange';

export const withinRange = (date, dateBounds) => {
const startingDate = Math.min(...dateBounds);
const endingDate = Math.max(...dateBounds);

// @TODO: remove the `new Date()` constructor in the next major version: we need to force it at configuration level.
return new Date(date) >= startingDate && new Date(date) <= endingDate;
};

// do not export anything else here to keep window.eventDrops as a function
export default ({ d3 = window.d3, ...customConfiguration }) => {
const chart = selection => {
const config = defaultsDeep(
Expand Down
28 changes: 1 addition & 27 deletions src/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventDrops, { withinRange } from './';
import EventDrops from './';
import zoom from './zoom';

jest.mock('./zoom');
Expand Down Expand Up @@ -157,29 +157,3 @@ describe('EventDrops', () => {
jest.restoreAllMocks();
});
});

describe('withinRange', () => {
it('should return true if date is in given date range', () => {
const dateRange = [new Date('2018-04-01'), new Date('2018-05-01')];
const test = (date, expectedResult) => {
expect(withinRange(date, dateRange)).toBe(expectedResult);
};

test('2018-04-19', true);
test('2018-04-01', true);
test('2018-05-01', true);
test('2018-05-19', false);
});

it('should return true if date is in given reverse date range (start date higher than end date', () => {
const dateRange = [new Date('2018-05-01'), new Date('2018-04-01')];
const test = (date, expectedResult) => {
expect(withinRange(date, dateRange)).toBe(expectedResult);
};

test('2018-04-19', true);
test('2018-04-01', true);
test('2018-05-01', true);
test('2018-05-19', false);
});
});
7 changes: 7 additions & 0 deletions src/withinRange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const withinRange = (date, dateBounds) => {
const startingDate = Math.min(...dateBounds);
const endingDate = Math.max(...dateBounds);

// @TODO: remove the `new Date()` constructor in the next major version: we need to force it at configuration level.
return new Date(date) >= startingDate && new Date(date) <= endingDate;
};
27 changes: 27 additions & 0 deletions src/withinRange.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { withinRange } from './withinRange';

describe('withinRange', () => {
it('should return true if date is in given date range', () => {
const dateRange = [new Date('2018-04-01'), new Date('2018-05-01')];
const test = (date, expectedResult) => {
expect(withinRange(date, dateRange)).toBe(expectedResult);
};

test('2018-04-19', true);
test('2018-04-01', true);
test('2018-05-01', true);
test('2018-05-19', false);
});

it('should return true if date is in given reverse date range (start date older than end date', () => {
const dateRange = [new Date('2018-05-01'), new Date('2018-04-01')];
const test = (date, expectedResult) => {
expect(withinRange(date, dateRange)).toBe(expectedResult);
};

test('2018-04-19', true);
test('2018-04-01', true);
test('2018-05-01', true);
test('2018-05-19', false);
});
});