-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from Adphorus/feature/support-for-customizabl…
…e-static-range-labels Support for customizable static range labels
- Loading branch information
Showing
8 changed files
with
1,562 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/node_modules/* | ||
/lib/* | ||
/dist/* | ||
**/*.snap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,8 @@ | |
], | ||
"contributors": [ | ||
"Burak Can <[email protected]> (https://github.com/burakcan)", | ||
"Mehmet Kamil Morcay <[email protected]> (https://github.com/mkg0)" | ||
"Mehmet Kamil Morcay <[email protected]> (https://github.com/mkg0)", | ||
"Engin Semih Basmacı <[email protected]> (https://github.com/mortargrind)" | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import React from 'react'; | ||
import { mount, shallow } from 'enzyme'; | ||
|
||
import DefinedRange from './DefinedRange'; | ||
import { isSameDay } from 'date-fns'; | ||
|
||
describe('DefinedRange tests', () => { | ||
test('Should call "renderStaticRangeLabel" callback correct amount of times according to the "hasCustomRendering" option', () => { | ||
const renderStaticRangeLabel = jest.fn(); | ||
|
||
mount( | ||
<DefinedRange | ||
staticRanges={[ | ||
{ | ||
label: 'Dynamic Label', | ||
range: {}, | ||
isSelected(range) { | ||
const definedRange = this.range(); | ||
return ( | ||
isSameDay(range.startDate, definedRange.startDate) && | ||
isSameDay(range.endDate, definedRange.endDate) | ||
); | ||
}, | ||
hasCustomRendering: true, | ||
}, | ||
{ | ||
label: 'Static Label', | ||
range: {}, | ||
isSelected(range) { | ||
const definedRange = this.range(); | ||
return ( | ||
isSameDay(range.startDate, definedRange.startDate) && | ||
isSameDay(range.endDate, definedRange.endDate) | ||
); | ||
}, | ||
}, | ||
{ | ||
label: 'Hede', | ||
range: {}, | ||
isSelected(range) { | ||
const definedRange = this.range(); | ||
return ( | ||
isSameDay(range.startDate, definedRange.startDate) && | ||
isSameDay(range.endDate, definedRange.endDate) | ||
); | ||
}, | ||
hasCustomRendering: true, | ||
}, | ||
]} | ||
renderStaticRangeLabel={renderStaticRangeLabel} | ||
/> | ||
); | ||
|
||
expect(renderStaticRangeLabel).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
test('Should render dynamic static label contents correctly', () => { | ||
const renderItalicLabelContent = () => ( | ||
<i className={'italic-label-content'}>{'Italic Content'}</i> | ||
); | ||
const renderBoldLabelContent = () => <b className={'bold-label-content'}>{'Bold Content'}</b>; | ||
const renderSomethingElse = () => <img className={'random-image'} />; | ||
|
||
const renderStaticRangeLabel = function(staticRange) { | ||
let result; | ||
|
||
if (staticRange.id === 'italic') { | ||
result = renderItalicLabelContent(); | ||
} else if (staticRange.id === 'bold') { | ||
result = renderBoldLabelContent(); | ||
} else { | ||
result = renderSomethingElse(); | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
const wrapper = shallow( | ||
<DefinedRange | ||
staticRanges={[ | ||
{ | ||
id: 'italic', | ||
range: {}, | ||
isSelected(range) { | ||
const definedRange = this.range(); | ||
return ( | ||
isSameDay(range.startDate, definedRange.startDate) && | ||
isSameDay(range.endDate, definedRange.endDate) | ||
); | ||
}, | ||
hasCustomRendering: true, | ||
}, | ||
{ | ||
label: 'Static Label', | ||
range: {}, | ||
isSelected(range) { | ||
const definedRange = this.range(); | ||
return ( | ||
isSameDay(range.startDate, definedRange.startDate) && | ||
isSameDay(range.endDate, definedRange.endDate) | ||
); | ||
}, | ||
}, | ||
{ | ||
id: 'whatever', | ||
range: {}, | ||
isSelected(range) { | ||
const definedRange = this.range(); | ||
return ( | ||
isSameDay(range.startDate, definedRange.startDate) && | ||
isSameDay(range.endDate, definedRange.endDate) | ||
); | ||
}, | ||
hasCustomRendering: true, | ||
}, | ||
{ | ||
id: 'bold', | ||
range: {}, | ||
isSelected(range) { | ||
const definedRange = this.range(); | ||
return ( | ||
isSameDay(range.startDate, definedRange.startDate) && | ||
isSameDay(range.endDate, definedRange.endDate) | ||
); | ||
}, | ||
hasCustomRendering: true, | ||
}, | ||
]} | ||
renderStaticRangeLabel={renderStaticRangeLabel} | ||
/> | ||
); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.