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

Implements rowRenderer prop #850

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
66 changes: 51 additions & 15 deletions __tests__/components/GroupRow/GroupRow.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react'
import { mount, render } from 'enzyme'
import { mount } from 'enzyme'
import { noop } from 'test-utility'
import GroupRow from 'lib/row/GroupRow'
import { RenderHeadersWrapper } from '../../test-utility/header-renderer'

const defaultProps = {
onClick: noop,
Expand All @@ -13,8 +14,7 @@ const defaultProps = {
group: {}
}

// using mount to be able to interact with element, render
// to assert dom level props (styles, className)
// using mount to be able to interact with element
describe('GroupRow', () => {
it('calls passed in onDoubleClick', () => {
const onDoubleClickMock = jest.fn()
Expand All @@ -23,9 +23,14 @@ describe('GroupRow', () => {
onDoubleClick: onDoubleClickMock
}

const wrapper = mount(<GroupRow {...props} />)
const wrapper = mount(
<RenderHeadersWrapper>
<GroupRow {...props} />
</RenderHeadersWrapper>
)

wrapper.simulate('doubleclick')
const component = wrapper.find('GroupRow')
component.simulate('doubleclick')

expect(onDoubleClickMock).toHaveBeenCalledTimes(1)
})
Expand All @@ -37,9 +42,14 @@ describe('GroupRow', () => {
onClick: onClickMock
}

const wrapper = mount(<GroupRow {...props} />)
const wrapper = mount(
<RenderHeadersWrapper>
<GroupRow {...props} />
</RenderHeadersWrapper>
)

wrapper.simulate('click')
const component = wrapper.find('GroupRow')
component.simulate('click')

expect(onClickMock).toHaveBeenCalledTimes(1)
})
Expand All @@ -51,40 +61,66 @@ describe('GroupRow', () => {
onContextMenu: onContextMenuMock
}

const wrapper = mount(<GroupRow {...props} />)
const wrapper = mount(
<RenderHeadersWrapper>
<GroupRow {...props} />
</RenderHeadersWrapper>
)

wrapper.simulate('contextmenu')
const component = wrapper.find('GroupRow')
component.simulate('contextmenu')

expect(onContextMenuMock).toHaveBeenCalledTimes(1)
})

it('assigns "rct-hl-even" class if isEvenRow is true', () => {
const props = {
...defaultProps,
isEvenRow: true
}

const wrapper = render(<GroupRow {...props} />)
const wrapper = mount(
<RenderHeadersWrapper>
<GroupRow {...props} />
</RenderHeadersWrapper>
)

const component = wrapper.find('GroupRow')

expect(wrapper.prop('class').trim()).toBe('rct-hl-even')
expect(component.hasClass('rct-hl-even'))
})

it('assigns "rct-hl-odd" if isEvenRow is false', () => {
const props = {
...defaultProps,
isEvenRow: false
}

const wrapper = render(<GroupRow {...props} />)
const wrapper = mount(
<RenderHeadersWrapper>
<GroupRow {...props} />
</RenderHeadersWrapper>
)

expect(wrapper.prop('class').trim()).toBe('rct-hl-odd')
const component = wrapper.find('GroupRow')

expect(component.hasClass('rct-hl-odd'))
})

it('passes style prop to style', () => {
const props = {
...defaultProps,
style: { border: '1px solid black' }
}

const wrapper = render(<GroupRow {...props} />)
const wrapper = mount(
<RenderHeadersWrapper>
<GroupRow {...props} />
</RenderHeadersWrapper>
)

const component = wrapper.find('GroupRow')

expect(wrapper.prop('style').border).toBe(props.style.border)
expect(component.prop('style').border).toBe(props.style.border)
})
})
7 changes: 6 additions & 1 deletion __tests__/components/GroupRow/GroupRows.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import { mount } from 'enzyme'
import { noop } from 'test-utility'
import GroupRows from 'lib/row/GroupRows'
import { RenderHeadersWrapper } from '../../test-utility/header-renderer'

const defaultProps = {
groups: [
Expand Down Expand Up @@ -31,7 +32,11 @@ const defaultProps = {

describe('GroupRows', () => {
it('passes props and get right height for first group', () => {
const wrapper = mount(<GroupRows {...defaultProps} />);
const wrapper = mount(
<RenderHeadersWrapper>
<GroupRows {...defaultProps} />
</RenderHeadersWrapper>
);

const component = wrapper.find('GroupRow').first();
expect(component.prop('style').height).toBe('30px');
Expand Down
Loading