-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: styles per event and disableDrag/Press per event (#254)
* Add styles per event * Add tests for WV visual-customizations * Add disable drag, press, longpress per event * Rename test file * Add fields to EventPropType
- Loading branch information
Showing
6 changed files
with
281 additions
and
143 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
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 |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react-native'; | ||
import WeekView from '../../WeekView/WeekView'; | ||
|
||
/** | ||
* NOTE: In most cases, when providing events to <WeekView />, select | ||
* carefully some props so the events _are visible in the screen_. | ||
* For example: | ||
* - numberOfDays | ||
* - selectedDate (usually, at least the same day the target event's startDate) | ||
* - hoursInDisplay | ||
* - startHour (usually, some hours before the target event) | ||
*/ | ||
describe('Basic render functionality', () => { | ||
describe('with no events', () => { | ||
it('renders an empty grid', () => { | ||
const { getByHintText, queryAllByHintText } = render( | ||
<WeekView | ||
events={[]} | ||
numberOfDays={3} | ||
selectedDate={new Date(2020, 3, 24)} | ||
/>, | ||
); | ||
expect(getByHintText('Grid with horizontal scroll')).toBeDefined(); | ||
expect(queryAllByHintText(/Show event \d+/)).toBeArrayOfSize(0); | ||
}); | ||
}); | ||
|
||
const eventsWithoutOverlap = [ | ||
{ | ||
id: 1, | ||
startDate: new Date(2021, 4, 2, 12, 0), | ||
endDate: new Date(2021, 4, 2, 13, 0), | ||
color: 'blue', | ||
}, | ||
{ | ||
id: 2, | ||
startDate: new Date(2021, 4, 2, 13, 0), | ||
endDate: new Date(2021, 4, 2, 13, 45), | ||
color: 'lightblue', | ||
}, | ||
{ | ||
id: 7, | ||
startDate: new Date(2021, 4, 3, 11, 14, 56), | ||
endDate: new Date(2021, 4, 3, 11, 30, 21), | ||
color: 'purple', | ||
}, | ||
{ | ||
id: 19, | ||
startDate: new Date(2021, 4, 4, 13, 32), | ||
endDate: new Date(2021, 4, 4, 14, 35), | ||
color: 'yellow', | ||
}, | ||
{ | ||
id: 52, | ||
startDate: new Date(2021, 4, 5, 18, 23), | ||
endDate: new Date(2021, 4, 5, 19, 57), | ||
color: 'pink', | ||
}, | ||
].map((evt) => ({ ...evt, description: `event ${evt.id}` })); | ||
|
||
const propsForNoOverlap = { | ||
numberOfDays: 5, | ||
selectedDate: new Date(2021, 4, 1), | ||
hoursInDisplay: 10, | ||
startHour: 11, | ||
}; | ||
|
||
const eventsWithOverlap = [ | ||
{ | ||
id: 9, | ||
startDate: new Date(2020, 7, 24, 17), | ||
endDate: new Date(2020, 7, 24, 18), | ||
color: 'purple', | ||
}, | ||
{ | ||
id: 43, | ||
startDate: new Date(2020, 7, 24, 17), | ||
endDate: new Date(2020, 7, 24, 18), | ||
color: 'red', | ||
}, | ||
{ | ||
id: 11, | ||
startDate: new Date(2020, 7, 25, 12, 15), | ||
endDate: new Date(2020, 7, 25, 14, 30), | ||
color: 'pink', | ||
}, | ||
{ | ||
id: 2, | ||
startDate: new Date(2020, 7, 25, 13, 0), | ||
endDate: new Date(2020, 7, 25, 13, 45), | ||
color: 'yellow', | ||
}, | ||
{ | ||
id: 3, | ||
startDate: new Date(2020, 7, 24, 17), | ||
endDate: new Date(2020, 7, 24, 18), | ||
color: 'lightblue', | ||
}, | ||
{ | ||
id: 1, | ||
startDate: new Date(2020, 7, 26, 13), | ||
endDate: new Date(2020, 7, 26, 20), | ||
color: 'lightblue', | ||
}, | ||
].map((evt) => ({ ...evt, description: `event ${evt.id}` })); | ||
|
||
const propsForOverlap = { | ||
numberOfDays: 3, | ||
selectedDate: new Date(2020, 7, 24), | ||
hoursInDisplay: 12, | ||
startHour: 12, | ||
}; | ||
|
||
describe.each([ | ||
['non-overlapping', eventsWithoutOverlap, propsForNoOverlap], | ||
['overlapped', eventsWithOverlap, propsForOverlap], | ||
])('with %s events', (_, events, props) => { | ||
it('shows all events', () => { | ||
const { queryAllByText } = render( | ||
/* eslint-disable-next-line react/jsx-props-no-spreading */ | ||
<WeekView events={events} {...props} />, | ||
); | ||
expect(queryAllByText(/event \d+/)).toBeArrayOfSize(events.length); | ||
}); | ||
|
||
it('shows each event with its color', () => { | ||
const { getByHintText } = render( | ||
/* eslint-disable-next-line react/jsx-props-no-spreading */ | ||
<WeekView events={events} {...props} />, | ||
); | ||
events.forEach((evt) => { | ||
const renderedEvent = getByHintText(`Show event ${evt.id}`); | ||
const expectedColor = evt.color; | ||
expect(renderedEvent).toHaveStyle({ backgroundColor: expectedColor }); | ||
}); | ||
}); | ||
}); | ||
}); |
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,104 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react-native'; | ||
import { Text } from 'react-native'; | ||
import WeekView from '../../WeekView/WeekView'; | ||
|
||
describe('Visual customizations', () => { | ||
describe('custom EventComponent', () => { | ||
const exampleEvents = [ | ||
{ | ||
id: 1, | ||
startDate: new Date(2021, 4, 2, 12, 0), | ||
endDate: new Date(2021, 4, 2, 13, 0), | ||
}, | ||
{ | ||
id: 2, | ||
startDate: new Date(2021, 4, 2, 13, 0), | ||
endDate: new Date(2021, 4, 2, 13, 45), | ||
}, | ||
{ | ||
id: 7, | ||
startDate: new Date(2021, 4, 3, 11, 14, 56), | ||
endDate: new Date(2021, 4, 3, 11, 30, 21), | ||
}, | ||
{ | ||
id: 19, | ||
startDate: new Date(2021, 4, 4, 13, 32), | ||
endDate: new Date(2021, 4, 4, 14, 35), | ||
}, | ||
{ | ||
id: 52, | ||
startDate: new Date(2021, 4, 5, 18, 23), | ||
endDate: new Date(2021, 4, 5, 19, 57), | ||
}, | ||
].map((evt) => ({ | ||
...evt, | ||
description: 'event by default', | ||
color: 'green', | ||
})); | ||
|
||
it('renders the custom component instead of the default', () => { | ||
const MyEventComponent = ({ event }) => ( | ||
<Text>{`custom ${event.id}`}</Text> | ||
); | ||
|
||
const { queryAllByText } = render( | ||
<WeekView | ||
events={exampleEvents} | ||
numberOfDays={5} | ||
selectedDate={new Date(2021, 4, 1)} | ||
hoursInDisplay={10} | ||
startHour={11} | ||
EventComponent={MyEventComponent} | ||
/>, | ||
); | ||
expect(queryAllByText('event by default')).toBeArrayOfSize(0); | ||
expect(queryAllByText(/custom \d+/)).toBeArrayOfSize( | ||
exampleEvents.length, | ||
); | ||
}); | ||
}); | ||
|
||
describe('using event.style', () => { | ||
const exampleEvents = [ | ||
{ | ||
id: 1, | ||
startDate: new Date(2021, 4, 2, 12, 0), | ||
endDate: new Date(2021, 4, 2, 13, 0), | ||
style: { borderRadius: 2, borderWidth: 1, borderColor: 'blue' }, | ||
}, | ||
{ | ||
id: 7, | ||
startDate: new Date(2021, 4, 3, 11, 14, 56), | ||
endDate: new Date(2021, 4, 3, 11, 30, 21), | ||
style: { backgroundColor: 'red' }, | ||
}, | ||
{ | ||
id: 19, | ||
startDate: new Date(2021, 4, 4, 13, 32), | ||
endDate: new Date(2021, 4, 4, 14, 35), | ||
style: { backgroundColor: 'green' }, | ||
}, | ||
].map((evt) => ({ | ||
...evt, | ||
description: `event ${evt.id}`, | ||
color: 'green', | ||
})); | ||
|
||
it('renders the event with extra style', () => { | ||
const { getByHintText } = render( | ||
<WeekView | ||
events={exampleEvents} | ||
numberOfDays={5} | ||
selectedDate={new Date(2021, 4, 1)} | ||
hoursInDisplay={10} | ||
startHour={11} | ||
/>, | ||
); | ||
exampleEvents.forEach((evt) => { | ||
const renderedEvent = getByHintText(`Show event ${evt.id}`); | ||
expect(renderedEvent).toHaveStyle(evt.style); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.