Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 7 additions & 3 deletions __fixtures__/stateAndProps.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { defaultKeys } from 'lib/default-config'
import {items} from './itemsAndGroups'

export const visibleTimeStart = 1540501200000
export const visibleTimeEnd = 1540587600000

export const props = {
keys: defaultKeys,
lineHeight: 30,
stackItems: true,
itemHeightRatio: 0.75
itemHeightRatio: 0.75,
visibleTimeEnd,
visibleTimeStart,
}

export const propsNoStack = {
...props,
stackItems: false,
}

export const visibleTimeStart = 1540501200000
export const visibleTimeEnd = 1540587600000

export const state = {
draggingItem: undefined,
Expand Down
371 changes: 371 additions & 0 deletions __tests__/components/Headers/CustomHeader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,371 @@
import React from 'react'
import { render, cleanup, prettyDOM } 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 { RenderHeadersWrapper } from '../../test-utility/header-renderer'
import { getCustomHeadersInTimeline } from '../../test-utility/headerRenderers'
import { parsePxToNumbers } from '../../test-utility/index'

import 'jest-dom/extend-expect'
import moment from 'moment'

describe('CustomHeader Component Test', () => {
afterEach(cleanup)

it('Given CustomHeader When pass a unit to it Then header should render that unit', () => {
const { getAllByTestId } = render(
getCustomHeadersInTimeline({
unit: 'month',
timelineState: {
timelineUnit: 'month',
canvasTimeStart: moment.utc('1/6/2018', 'DD/MM/YYYY').valueOf(),
canvasTimeEnd: moment.utc('1/6/2020', 'DD/MM/YYYY').valueOf(),
visibleTimeStart: moment.utc('1/1/2019', 'DD/MM/YYYY').valueOf(),
visibleTimeEnd: moment.utc('1/1/2020', 'DD/MM/YYYY').valueOf()
}
})
)
const intervals = getAllByTestId('customHeaderInterval')
const start = moment(intervals[0].textContent, 'DD/MM/YYYY')
const end = moment(intervals[1].textContent, 'DD/MM/YYYY')
expect(end.diff(start, 'M')).toBe(1)
})
it('Given CustomHeader When pass a style props with (width, position) Then it should not override 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 rendered Correctly', () => {
const { getByTestId } = render(
getCustomHeadersInTimeline({ props: { style: { color: 'white' } } })
)
const { color } = getComputedStyle(getByTestId('customHeader'))
expect(color).toBe('white')
})

it('Given CustomHeader When pass an interval style with (width, position and left) Then it should not override the default values', () => {
const { getByTestId } = render(
getCustomHeadersInTimeline({
intervalStyle: {
width: 0,
position: 'fixed',
left: 1222222
}
})
)
const { width, position, left } = getComputedStyle(
getByTestId('customHeaderInterval')
)
expect(width).not.toBe('0px')
expect(position).not.toBe('fixed')
expect(left).not.toBe('1222222px')
})
it('Given CustomHeader When pass an interval style other than (width, position and left) 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 CustomHeader When not pass any unit prop Then it Should take the default timeline unit', () => {
const { getAllByTestId } = render(
getCustomHeadersInTimeline({
timelineState: {
//default unit we are testing
timelineUnit: 'month',
canvasTimeStart: moment.utc('1/6/2018', 'DD/MM/YYYY').valueOf(),
canvasTimeEnd: moment.utc('1/6/2020', 'DD/MM/YYYY').valueOf(),
visibleTimeStart: moment.utc('1/1/2019', 'DD/MM/YYYY').valueOf(),
visibleTimeEnd: moment.utc('1/1/2020', 'DD/MM/YYYY').valueOf()
}
})
)
const intervals = getAllByTestId('customHeaderInterval')
const start = moment(intervals[0].textContent, 'DD/MM/YYYY')
const end = moment(intervals[1].textContent, 'DD/MM/YYYY')
expect(end.diff(start, 'M')).toBe(1)
})

it("Given CustomHeader When rendered Then intervals don't overlap in position", () => {
const { getAllByTestId } = render(getCustomHeadersInTimeline())
const intervals = getAllByTestId('customHeaderInterval')
const intervalsCoordinations = intervals.map(interval => {
const { left, width } = getComputedStyle(interval)
return {
left: parsePxToNumbers(left),
right: parsePxToNumbers(left) + parsePxToNumbers(width)
}
})
for (let index = 0; index < intervalsCoordinations.length - 1; index++) {
const a = intervalsCoordinations[index]
const b = intervalsCoordinations[index + 1]
expect(Math.abs(a.right - b.left)).toBeLessThan(0.1)
}
})

it('Given CustomHeader When passing child renderer Then showPeriod should be passed', () => {
const showPeriod = () => {}
const renderer = jest.fn(() => {
return <div>header</div>
})
render(
<RenderHeadersWrapper
timelineState={{
showPeriod: showPeriod
}}
>
<TimelineHeaders>
<CustomHeader>{renderer}</CustomHeader>
</TimelineHeaders>
</RenderHeadersWrapper>
)
expect(renderer.mock.calls[0][0].showPeriod).toBe(showPeriod)
})

it('Given CustomHeader When passing child renderer Then headerContext should be passed', () => {
const renderer = jest.fn(() => {
return <div>header</div>
})
render(
<RenderHeadersWrapper>
<TimelineHeaders>
<CustomHeader>{renderer}</CustomHeader>
</TimelineHeaders>
</RenderHeadersWrapper>
)
const headerContext = renderer.mock.calls[0][0].headerContext
expect(headerContext).toBeDefined()
})

it('Given CustomHeader When passing child renderer Then headerContext should be passed with intervals and unit', () => {
const renderer = jest.fn(() => {
return <div>header</div>
})
render(
<RenderHeadersWrapper>
<TimelineHeaders>
<CustomHeader>{renderer}</CustomHeader>
</TimelineHeaders>
</RenderHeadersWrapper>
)
const headerContext = renderer.mock.calls[0][0].headerContext
const intervals = headerContext.intervals
const unit = headerContext.unit
expect(intervals).toBeDefined()
expect(intervals).toEqual(
expect.arrayContaining([
expect.objectContaining({
startTime: expect.any(moment),
endTime: expect.any(moment),
labelWidth: expect.any(Number),
left: expect.any(Number)
})
])
)
expect(unit).toEqual(expect.any(String))
})

it('Given CustomHeader When passing child renderer Then timelineContext should be passed', () => {
const renderer = jest.fn(() => {
return <div>header</div>
})
render(
<RenderHeadersWrapper>
<TimelineHeaders>
<CustomHeader>{renderer}</CustomHeader>
</TimelineHeaders>
</RenderHeadersWrapper>
)
const timelineContext = renderer.mock.calls[0][0].timelineContext
expect(timelineContext).toBeDefined()
expect(timelineContext).toMatchObject({
timelineWidth: expect.any(Number),
visibleTimeStart: expect.any(Number),
visibleTimeEnd: expect.any(Number),
canvasTimeStart: expect.any(Number),
canvasTimeEnd: expect.any(Number)
})
})

describe('CustomHeader Intervals', () => {
it('Given intervals Then they should have the same width', () => {
const renderer = jest.fn(() => {
return <div>header</div>
})
render(
<RenderHeadersWrapper timelineState={{ timelineUnit: 'hour' }}>
<TimelineHeaders>
<CustomHeader>{renderer}</CustomHeader>
</TimelineHeaders>
</RenderHeadersWrapper>
)

const headerContext = renderer.mock.calls[0][0].headerContext
const intervals = headerContext.intervals
const widths = intervals.map(interval => interval.labelWidth)
for (let index = 0; index < widths.length - 1; index++) {
const a = widths[index]
const b = widths[index + 1]

expect(Math.abs(b - a)).toBeLessThan(0.1)
}
})

it('Given intervals Then left property should be different', () => {
const renderer = jest.fn(() => {
return <div>header</div>
})
render(
<RenderHeadersWrapper>
<TimelineHeaders>
<CustomHeader>{renderer}</CustomHeader>
</TimelineHeaders>
</RenderHeadersWrapper>
)
const headerContext = renderer.mock.calls[0][0].headerContext
const intervals = headerContext.intervals
const lefts = intervals.map(interval => interval.left)
for (let index = 0; index < lefts.length - 1; index++) {
const a = lefts[index]
const b = lefts[index + 1]
expect(a).toBeLessThan(b)
}
})
})

it('Given CustomHeader When passing extra props Then it will be passed to the renderProp', () => {
const renderer = jest.fn(() => {
return <div>header</div>
})
const props = {
data: 'some'
}
render(
<RenderHeadersWrapper>
<TimelineHeaders>
<CustomHeader headerData={props}>{renderer}</CustomHeader>
</TimelineHeaders>
</RenderHeadersWrapper>
)
expect(renderer.mock.calls[0][0].data).toBe(props)
})
// Render The Example In The Docs
it('Given CustomHeader When render Then it should render Correctly in the timeline', () => {
const { getByTestId } = render(
<RenderHeadersWrapper>
<TimelineHeaders>
<SidebarHeader>
{({ getRootProps }) => {
return <div {...getRootProps()}>Left</div>
}}
</SidebarHeader>
<DateHeader unit="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>
</RenderHeadersWrapper>
)

expect(getByTestId('customHeader')).toBeInTheDocument()
})
it('Given Custom Header When passing react stateless component to render prop Then it should render', () => {
const Renderer = props => {
return <div>header</div>
}

const { getByText } = render(
<RenderHeadersWrapper>
<TimelineHeaders>
<CustomHeader>{Renderer}</CustomHeader>
</TimelineHeaders>
</RenderHeadersWrapper>
)
expect(getByText('header')).toBeInTheDocument()
})

it('Given Custom Header When passing react component to render prop Then it should render', () => {
class Renderer extends React.Component {
render() {
return <div>header</div>
}
}

const { getByText } = render(
<RenderHeadersWrapper>
<TimelineHeaders>
<CustomHeader>{Renderer}</CustomHeader>
</TimelineHeaders>
</RenderHeadersWrapper>
)
expect(getByText('header')).toBeInTheDocument()
})
})
Loading