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

fix(react-grid): remove header cell title offset if grouping by click isn't allowed #434

Merged
merged 1 commit into from
Oct 23, 2017
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class TableHeaderCell extends React.PureComponent {
)}
<div
style={{
[`margin${column.align === 'right' ? 'Left' : 'Right'}`]: '14px',
...(allowGroupingByClick ? { [`margin${column.align === 'right' ? 'Left' : 'Right'}`]: '14px' } : null),
textAlign: align,
whiteSpace: 'nowrap',
overflow: 'hidden',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { setupConsole } from '@devexpress/dx-testing';

import { TableHeaderCell } from './table-header-cell';
import { ResizingControl } from './table-header-cell/resizing-control';
import { GroupingControl } from './table-header-cell/grouping-control';

jest.mock('./table-header-cell/grouping-control', () => ({
GroupingControl: jest.fn(),
}));

describe('TableHeaderCell', () => {
let resetConsole;
Expand All @@ -15,6 +20,13 @@ describe('TableHeaderCell', () => {
resetConsole();
});

beforeEach(() => {
GroupingControl.mockImplementation(() => null);
});
afterEach(() => {
jest.resetAllMocks();
});

it('should use column name if title is not specified', () => {
const tree = mount((
<TableHeaderCell
Expand Down Expand Up @@ -154,4 +166,70 @@ describe('TableHeaderCell', () => {
expect(tree.find(ResizingControl).prop('changeColumnWidth'))
.toBe(changeColumnWidth);
});

it('should have correct styles when grouping by click is not allowed and column align is left', () => {
const tree = mount((
<TableHeaderCell
column={{}}
allowGroupingByClick={false}
/>
));
expect(tree.find('th > div').prop('style'))
.toMatchObject({
textAlign: 'left',
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
});
});

it('should have correct styles when grouping by click is allowed and column align is left', () => {
const tree = mount((
<TableHeaderCell
column={{}}
allowGroupingByClick
/>
));
expect(tree.find('th > div').prop('style'))
.toMatchObject({
textAlign: 'left',
marginRight: '14px',
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
});
});

it('should have correct styles when grouping by click is not allowed and column align is right', () => {
const tree = mount((
<TableHeaderCell
column={{ align: 'right' }}
allowGroupingByClick={false}
/>
));
expect(tree.find('th > div').prop('style'))
.toMatchObject({
textAlign: 'right',
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
});
});

it('should have correct styles when grouping by click is allowed and column align is right', () => {
const tree = mount((
<TableHeaderCell
column={{ align: 'right' }}
allowGroupingByClick
/>
));
expect(tree.find('th > div').prop('style'))
.toMatchObject({
textAlign: 'right',
marginLeft: '14px',
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ const styles = theme => ({
},
titleRight: {
textAlign: 'right',
marginLeft: (theme.spacing.unit * 2) - 2,
},
titleLeft: {
textAlign: 'left',
},
titleRightOffset: {
marginLeft: (theme.spacing.unit * 2) - 2,
},
titleLeftOffset: {
marginRight: (theme.spacing.unit * 2) - 2,
},
});
Expand Down Expand Up @@ -108,6 +112,8 @@ class TableHeaderCellBase extends React.PureComponent {
[classes.title]: true,
[classes.titleRight]: align === 'right',
[classes.titleLeft]: align === 'left',
[classes.titleRightOffset]: align === 'right' && allowGroupingByClick,
[classes.titleLeftOffset]: align === 'left' && allowGroupingByClick,
});

const cellLayout = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { setupConsole } from '@devexpress/dx-testing';
import { DragDropContext, DragSource } from '@devexpress/dx-react-core';
import { TableHeaderCell } from './table-header-cell';
import { ResizingControl } from './table-header-cell/resizing-control';
import { GroupingControl } from './table-header-cell/grouping-control';

jest.mock('./table-header-cell/grouping-control', () => ({
GroupingControl: jest.fn(),
}));

describe('TableHeaderCell', () => {
let resetConsole;
Expand All @@ -20,6 +25,13 @@ describe('TableHeaderCell', () => {
mount.cleanUp();
});

beforeEach(() => {
GroupingControl.mockImplementation(() => null);
});
afterEach(() => {
jest.resetAllMocks();
});

it('should use column name if title is not specified', () => {
const tree = mount((
<TableHeaderCell
Expand Down Expand Up @@ -126,4 +138,60 @@ describe('TableHeaderCell', () => {
expect(tree.find(ResizingControl).prop('changeColumnWidth'))
.toBe(changeColumnWidth);
});

it('should have correct offset when grouping by click is not allowed and column align is left', () => {
const tree = mount((
<TableHeaderCell
column={{}}
allowGroupingByClick={false}
/>
));

expect(tree.find(`.${classes.titleLeftOffset}`)).toHaveLength(0);
expect(tree.find(`.${classes.titleRightOffset}`)).toHaveLength(0);
expect(tree.find(`.${classes.titleLeft}`)).toHaveLength(1);
expect(tree.find(`.${classes.titleRight}`)).toHaveLength(0);
});

it('should have correct offset when grouping by click is allowed column align is left', () => {
const tree = mount((
<TableHeaderCell
column={{}}
allowGroupingByClick
/>
));

expect(tree.find(`.${classes.titleLeftOffset}`)).toHaveLength(1);
expect(tree.find(`.${classes.titleRightOffset}`)).toHaveLength(0);
expect(tree.find(`.${classes.titleLeft}`)).toHaveLength(1);
expect(tree.find(`.${classes.titleRight}`)).toHaveLength(0);
});

it('should have correct offset when grouping by click is not allowed and column align is right', () => {
const tree = mount((
<TableHeaderCell
column={{ align: 'right' }}
allowGroupingByClick={false}
/>
));

expect(tree.find(`.${classes.titleLeftOffset}`)).toHaveLength(0);
expect(tree.find(`.${classes.titleRightOffset}`)).toHaveLength(0);
expect(tree.find(`.${classes.titleLeft}`)).toHaveLength(0);
expect(tree.find(`.${classes.titleRight}`)).toHaveLength(1);
});

it('should have correct offset when grouping by click is allowed column align is right', () => {
const tree = mount((
<TableHeaderCell
column={{ align: 'right' }}
allowGroupingByClick
/>
));

expect(tree.find(`.${classes.titleLeftOffset}`)).toHaveLength(0);
expect(tree.find(`.${classes.titleRightOffset}`)).toHaveLength(1);
expect(tree.find(`.${classes.titleLeft}`)).toHaveLength(0);
expect(tree.find(`.${classes.titleRight}`)).toHaveLength(1);
});
});