Skip to content
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
a803455
add tests
Oct 14, 2018
048aff2
fix TimelineHeader tests + add error to getNextUnit helper
Oct 18, 2018
15a7a53
add error snapshot
Ilaiwi Oct 19, 2018
e4381a7
add tests senarios
Ilaiwi Oct 20, 2018
b9f28af
Merge branch 'custom-headers' of https://github.com/FoothillSolutions…
Ilaiwi Jan 2, 2019
31b90a6
merge custom headers
Ilaiwi Jan 2, 2019
1502e4e
merge remote
Ilaiwi Jan 2, 2019
d6d9cee
adding test cases for the timeline wrapper's child components api
sh-alawneh Jan 5, 2019
815f7d8
fix typos in the test cases of timeline wrapper's components api
sh-alawneh Jan 6, 2019
908b861
adding a new Test Case to The SidebarHeader test collection
sh-alawneh Jan 6, 2019
f7f385d
Merge branch 'custom-headers' of https://github.com/FoothillSolutions…
sh-alawneh Jan 6, 2019
b9ab291
implement tests and extract test cases to separate files
sh-alawneh Jan 6, 2019
496edb9
adding new test to the Timeline Component
sh-alawneh Jan 6, 2019
0e03bd3
implement timeline tests except the primary secondary test case
sh-alawneh Jan 6, 2019
db4af0f
implement the test for checking one secondary and one primary headers
sh-alawneh Jan 6, 2019
f09bbfb
update the test case one secondary and one primary
sh-alawneh Jan 7, 2019
572b1f4
implement the test cases in the sidebarHeader test file
sh-alawneh Jan 7, 2019
e0a560e
extend the test cases for the sidebarHeader component
sh-alawneh Jan 7, 2019
85483dc
remove unused imports
sh-alawneh Jan 7, 2019
47c80f7
do code refactoring
sh-alawneh Jan 7, 2019
08443aa
extend the test cases with some arrangments
sh-alawneh Jan 15, 2019
359449d
extend the test cases and make the descreption more descriptive
sh-alawneh Jan 16, 2019
a5c19a1
remove unused imports and variables, adding custom header test cases
sh-alawneh Jan 17, 2019
1647566
extend the custom header test cases
sh-alawneh Jan 22, 2019
b7b2cca
delete package lock
Ilaiwi Jan 22, 2019
40065f8
refactor how we calculate interval style
Ilaiwi Jan 22, 2019
c72f12d
Merge branch 'custom-headers-test' of https://github.com/FoothillSolu…
Ilaiwi Jan 22, 2019
0a8d21a
extends the test cases
sh-alawneh Jan 28, 2019
892fe56
Merge branch 'custom-headers-test' of https://github.com/FoothillSolu…
sh-alawneh Jan 28, 2019
1b47281
Merge branch 'custom-headers' of https://github.com/FoothillSolutions…
Ilaiwi Feb 21, 2019
a6486e8
Merge branch 'custom-headers' of https://github.com/FoothillSolutions…
Ilaiwi Mar 18, 2019
f8657e0
fix broken tests
Ilaiwi Mar 18, 2019
7703421
refactor to use context and not timeline
Ilaiwi Mar 19, 2019
aa566a0
check tests and add TODOs
Ilaiwi Mar 19, 2019
2069dca
finalize SidebarHeader and TimelineHeader tests
Ilaiwi Mar 20, 2019
44d367f
Custom headers tests
Ilaiwi Mar 24, 2019
db46dd4
DateHeader
Ilaiwi Mar 25, 2019
74ffee4
fix broken tests
Ilaiwi Mar 26, 2019
46e72f9
delete snapshots + fix travis moment errors
Ilaiwi Mar 26, 2019
1199d66
Merge branch 'custom-headers' of https://github.com/FoothillSolutions…
Ilaiwi Mar 26, 2019
9abdd45
Merge branch 'custom-headers' of https://github.com/FoothillSolutions…
Ilaiwi Mar 26, 2019
e98aacf
pass primary as unit and remove secondary
Ilaiwi Mar 27, 2019
4c02b20
Merge branch 'custom-headers' of https://github.com/FoothillSolutions…
Ilaiwi Mar 27, 2019
96e3e47
sidebarheader to accept component as a child
Ilaiwi Mar 27, 2019
f018881
convert DateHeader and CustomHeader to use headerData
Ilaiwi Mar 27, 2019
34f2c28
remove labelFormat object option
Ilaiwi Mar 28, 2019
766220e
remove inline styles and replace them with classnames
Ilaiwi Mar 28, 2019
d5cba6e
update readme
Ilaiwi Mar 28, 2019
9ab5d4e
add height prop
Ilaiwi Apr 1, 2019
ad92d55
fix failing height test
Ilaiwi Apr 3, 2019
9e0fe8c
Merge branch 'custom-headers' of https://github.com/FoothillSolutions…
Ilaiwi Apr 3, 2019
abaa893
add right and left sidebar headers if not provided
Ilaiwi Apr 4, 2019
2f4e974
pull changes from tests
Ilaiwi Apr 8, 2019
8784ea1
Merge branch 'custom-headers' of https://github.com/FoothillSolutions…
Ilaiwi Apr 8, 2019
1642a17
Merge branch 'custom-headers' of https://github.com/FoothillSolutions…
Ilaiwi Apr 8, 2019
294a8d4
pull changes
Ilaiwi Apr 8, 2019
d550eb9
Custom headers (#391)
Ilaiwi Apr 8, 2019
b8b03e8
remove console.log
Ilaiwi Apr 8, 2019
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
194 changes: 194 additions & 0 deletions __tests__/components/Headers/CustomHeader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
import React from 'react'
import { render, cleanup } from 'react-testing-library'
import Timeline from 'lib/Timeline'
import DateHeader from 'lib/headers/DateHeader'
import SidebarHeader from 'lib/headers/SidebarHeader'
import TimelineHeaders from 'lib/headers/TimelineHeaders'
import CustomHeader from 'lib/headers/CustomHeader'
import 'jest-dom/extend-expect'
import moment from 'moment'
import { items, groups } from '../../../__fixtures__/itemsAndGroups'
import { visibleTimeEnd, visibleTimeStart } from '../../../__fixtures__/stateAndProps'

const defaultProps = {
groups,
items,
defaultTimeStart: moment(visibleTimeStart, 'x'),
defaultTimeEnd: moment(visibleTimeEnd, 'x'),
}

describe('CustomHeader Component Test', () => {
afterEach(cleanup)
// Render The Example In The Docs
it('Given CustomHeader When render Then it should renderd Correctly in the timeline', () => {
const { getByTestId } = render(
<Timeline {...defaultProps}>
<TimelineHeaders>
<SidebarHeader>
{({ getRootProps }) => {
return <div {...getRootProps()}>Left</div>
}}
</SidebarHeader>
<DateHeader primaryHeader />
<DateHeader />
<CustomHeader unit="year">
{({
headerContext: { intervals },
getRootProps,
getIntervalProps,
showPeriod
}) => {
return (
<div data-testid="customHeader" {...getRootProps({ style: { height: 30 } })}>
{intervals.map(interval => {
const intervalStyle = {
// height: 30,
lineHeight: '30px',
textAlign: 'center',
borderLeft: '1px solid black',
cursor: 'pointer',
backgroundColor: 'Turquoise',
color: 'white'
}
return (
<div
onClick={() => {
showPeriod(interval.startTime, interval.endTime)
}}
{...getIntervalProps({
interval,
style: intervalStyle
})}
>
<div className="sticky">
{interval.startTime.format('YYYY')}
</div>
</div>
)
})}
</div>
)
}}
</CustomHeader>
</TimelineHeaders>
</Timeline>
)

expect(getByTestId('customHeader')).toBeInTheDocument()
})
it('Given CustomHeader When pass a unit to it Then it should take it', () => {
const { getByTestId, rerender } = render(getCustomHeadersInTimeline({ unit: "year" }));
expect(getByTestId('customHeader')).toHaveTextContent('01/01/2018')

rerender(getCustomHeadersInTimeline({ unit: "month" }));
expect(getByTestId('customHeader')).toHaveTextContent('10/01/2018')

rerender(getCustomHeadersInTimeline({ unit: "day" }));
expect(getByTestId('customHeader')).toHaveTextContent('10/25/2018')
expect(getByTestId('customHeader')).toHaveTextContent('10/26/2018')
expect(getByTestId('customHeader')).toHaveTextContent('10/27/2018')
})
it('Given CustomHeader When pass a style props with (width, position) Then it should not ovverride the default values', () => {
const { getByTestId } = render(getCustomHeadersInTimeline({ props: { style: { width: 0, position: 'fixed' } } }));
const { width, position } = getComputedStyle(getByTestId('customHeader'))
expect(width).not.toBe('0px')
expect(position).not.toBe('fixed')
})

it('Given CustomHeader When pass a style props other than (width, position) Then it should renderd Correctly', () => {
const { getByTestId } = render(getCustomHeadersInTimeline({ props: { style: { height: 150 } } }));
const { height } = getComputedStyle(getByTestId('customHeader'))
expect(height).toBe("150px")
})

it('Given CustomHeader When pass an interval style with (width, position, left) Then it should not ovverride the default values', () => {
const { getByTestId } = render(getCustomHeadersInTimeline({
intervalStyle: {
width: 0,
position: 'fixed',
left: 0

}
}));
const { width, position, left } = getComputedStyle(getByTestId('customHeaderInterval'))
expect(width).not.toBe('0px')
expect(position).not.toBe('fixed')
expect(left).not.toBe('0px')
})
it('Given CustomHeader When pass an interval style other than (width, position) Then it should rendered correctly', () => {
const { getByTestId } = render(getCustomHeadersInTimeline({
intervalStyle: {
lineHeight: '30px',
textAlign: 'center',
borderLeft: '1px solid black',
cursor: 'pointer',
color: 'white'
}
}));
const { lineHeight, textAlign, borderLeft, cursor, color } = getComputedStyle(getByTestId('customHeaderInterval'))
expect(lineHeight).toBe('30px')
expect(textAlign).toBe('center')
expect(borderLeft).toBe('1px solid black')
expect(cursor).toBe('pointer')
expect(color).toBe('white')
})
it('Given a DateHeader When pass a jsx as a children Then it Should be rendered Correctly', () => {
const {getByText} = render(getCustomHeadersInTimeline())
expect(getByText('Should Be Rendered')).toBeInTheDocument()
})
it('Given a DateHeader When not pass any unit prop Then it Should take the default timeline unit (year)', () => {
const {getByTestId} = render(getCustomHeadersInTimeline())
expect(getByTestId('customHeader')).toHaveTextContent('01/01/2018')
})
})

function getCustomHeadersInTimeline({ unit = "year", props, intervalStyle } = {}) {

return (
<Timeline {...defaultProps}>
<TimelineHeaders>
<SidebarHeader>
{({ getRootProps }) => {
return <div {...getRootProps()}>Left</div>
}}
</SidebarHeader>
<DateHeader primaryHeader />
<DateHeader />
<CustomHeader unit={unit} props={props}>
{({
headerContext: { intervals },
getRootProps,
getIntervalProps,
showPeriod
}) => {
return (
<div data-testid="customHeader" {...getRootProps(props)}>
{intervals.map(interval => {
return (
<div data-testid="customHeaderInterval"
onClick={() => {
showPeriod(interval.startTime, interval.endTime)
}}
{...getIntervalProps({
interval,
style: intervalStyle
})}
>
<div className="sticky">
{interval.startTime.format('MM/DD/YYYY')}
</div>
</div>
)
})}
<div>
Should Be Rendered
</div>
</div>

)
}}
</CustomHeader>
</TimelineHeaders>
</Timeline>
)
}
Loading