Skip to content
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
1 change: 1 addition & 0 deletions packages/eui/changelogs/upcoming/9540.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added a warning when non-recommended units are used in `width`, `minWidth` or `maxWidth` props on `<EuiTableFooterCell>`, `<EuiTableHeaderCell>`, `<EuiTableHeaderCellCheckbox>` as well as the `columns` configuration on `<EuiBasicTable>` and `<EuiInMemoryTable>`
30 changes: 23 additions & 7 deletions packages/eui/src/components/table/table_footer_cell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
WARNING_MESSAGE_MAX_WIDTH,
WARNING_MESSAGE_MIN_WIDTH,
WARNING_MESSAGE_WIDTH,
WARNING_MESSAGE_NOT_RECOMMENDED_UNIT,
} from './utils';
import type { EuiTableSharedWidthProps } from './types';

Expand Down Expand Up @@ -76,14 +77,14 @@ describe('EuiTableFooterCell', () => {
it('accepts `style` prop', () => {
const { getByRole } = renderInTableFooter(
<EuiTableFooterCell
style={{ width: '20%', minWidth: '123px', maxWidth: '456px' }}
style={{ width: '200px', minWidth: '123px', maxWidth: '456px' }}
>
Test
</EuiTableFooterCell>
);

expect(getByRole('cell')).toHaveStyle({
width: '20%',
width: '200px',
minWidth: '123px',
maxWidth: '456px',
});
Expand All @@ -99,14 +100,14 @@ describe('EuiTableFooterCell', () => {

it(`accepts \`${name}\` prop`, () => {
const { getByRole } = renderInTableFooter(
<EuiTableFooterCell style={{ [name]: '10%' }}>
<EuiTableFooterCell style={{ [name]: '100px' }}>
Test
</EuiTableFooterCell>
);

expect(getByRole('cell')).toHaveStyle({
...defaultStyles,
[name]: '10%',
[name]: '100px',
});
});

Expand All @@ -130,9 +131,9 @@ describe('EuiTableFooterCell', () => {
console.warn = jest.fn();

const props = {
[name]: '10%',
[name]: '100px',
style: {
[name]: '20%',
[name]: '200px',
},
};

Expand All @@ -142,13 +143,28 @@ describe('EuiTableFooterCell', () => {

expect(getByRole('cell')).toHaveStyle({
...defaultStyles,
[name]: '10%',
[name]: '100px',
});

expect(console.warn).toHaveBeenCalledWith(warningMessage);

console.warn = originalConsoleWarn;
});

it('warns when a not recommended unit is used', () => {
const originalConsoleWarn = console.warn;
console.warn = jest.fn();

renderInTableFooter(
<EuiTableFooterCell {...{ [name]: '20%' }}>Test</EuiTableFooterCell>
);

expect(console.warn).toHaveBeenCalledWith(
WARNING_MESSAGE_NOT_RECOMMENDED_UNIT
);

console.warn = originalConsoleWarn;
});
};

describe('width', testProp('width', WARNING_MESSAGE_WIDTH));
Expand Down
30 changes: 23 additions & 7 deletions packages/eui/src/components/table/table_header_cell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
WARNING_MESSAGE_MAX_WIDTH,
WARNING_MESSAGE_MIN_WIDTH,
WARNING_MESSAGE_WIDTH,
WARNING_MESSAGE_NOT_RECOMMENDED_UNIT,
} from './utils';
import { EuiTableIsResponsiveContext } from './mobile/responsive_context';

Expand Down Expand Up @@ -158,14 +159,14 @@ describe('EuiTableHeaderCell', () => {
it('accepts `style` prop', () => {
const { getByRole } = renderInTableHeader(
<EuiTableHeaderCell
style={{ width: '20%', minWidth: '123px', maxWidth: '456px' }}
style={{ width: '200px', minWidth: '123px', maxWidth: '456px' }}
>
Test
</EuiTableHeaderCell>
);

expect(getByRole('columnheader')).toHaveStyle({
width: '20%',
width: '200px',
minWidth: '123px',
maxWidth: '456px',
});
Expand All @@ -181,14 +182,14 @@ describe('EuiTableHeaderCell', () => {

it(`accepts \`${name}\` prop`, () => {
const { getByRole } = renderInTableHeader(
<EuiTableHeaderCell style={{ [name]: '10%' }}>
<EuiTableHeaderCell style={{ [name]: '100px' }}>
Test
</EuiTableHeaderCell>
);

expect(getByRole('columnheader')).toHaveStyle({
...defaultStyles,
[name]: '10%',
[name]: '100px',
});
});

Expand All @@ -212,9 +213,9 @@ describe('EuiTableHeaderCell', () => {
console.warn = jest.fn();

const props = {
[name]: '10%',
[name]: '100px',
style: {
[name]: '20%',
[name]: '200px',
},
};

Expand All @@ -224,13 +225,28 @@ describe('EuiTableHeaderCell', () => {

expect(getByRole('columnheader')).toHaveStyle({
...defaultStyles,
[name]: '10%',
[name]: '100px',
});

expect(console.warn).toHaveBeenCalledWith(warningMessage);

console.warn = originalConsoleWarn;
});

it('warns when a not recommended unit is used', () => {
const originalConsoleWarn = console.warn;
console.warn = jest.fn();

renderInTableHeader(
<EuiTableHeaderCell {...{ [name]: '20%' }}>Test</EuiTableHeaderCell>
);

expect(console.warn).toHaveBeenCalledWith(
WARNING_MESSAGE_NOT_RECOMMENDED_UNIT
);

console.warn = originalConsoleWarn;
});
};

describe('width', testProp('width', WARNING_MESSAGE_WIDTH));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
WARNING_MESSAGE_MAX_WIDTH,
WARNING_MESSAGE_MIN_WIDTH,
WARNING_MESSAGE_WIDTH,
WARNING_MESSAGE_NOT_RECOMMENDED_UNIT,
} from './utils';
import type { EuiTableSharedWidthProps } from './types';

Expand All @@ -40,14 +41,14 @@ describe('EuiTableHeaderCellCheckbox', () => {
it('accepts `style` prop', () => {
const { getByRole } = renderInTableHeader(
<EuiTableHeaderCellCheckbox
style={{ width: '20%', minWidth: '123px', maxWidth: '456px' }}
style={{ width: '200px', minWidth: '123px', maxWidth: '456px' }}
>
Test
</EuiTableHeaderCellCheckbox>
);

expect(getByRole('columnheader')).toHaveStyle({
width: '20%',
width: '200px',
minWidth: '123px',
maxWidth: '456px',
});
Expand All @@ -63,14 +64,14 @@ describe('EuiTableHeaderCellCheckbox', () => {

it(`accepts \`${name}\` prop`, () => {
const { getByRole } = renderInTableHeader(
<EuiTableHeaderCellCheckbox style={{ [name]: '10%' }}>
<EuiTableHeaderCellCheckbox style={{ [name]: '100px' }}>
Test
</EuiTableHeaderCellCheckbox>
);

expect(getByRole('columnheader')).toHaveStyle({
...defaultStyles,
[name]: '10%',
[name]: '100px',
});
});

Expand All @@ -96,9 +97,9 @@ describe('EuiTableHeaderCellCheckbox', () => {
console.warn = jest.fn();

const props = {
[name]: '10%',
[name]: '100px',
style: {
[name]: '20%',
[name]: '200px',
},
};

Expand All @@ -110,13 +111,30 @@ describe('EuiTableHeaderCellCheckbox', () => {

expect(getByRole('columnheader')).toHaveStyle({
...defaultStyles,
[name]: '10%',
[name]: '100px',
});

expect(console.warn).toHaveBeenCalledWith(warningMessage);

console.warn = originalConsoleWarn;
});

it('warns when a not recommended unit is used', () => {
const originalConsoleWarn = console.warn;
console.warn = jest.fn();

renderInTableHeader(
<EuiTableHeaderCellCheckbox {...{ [name]: '20%' }}>
Test
</EuiTableHeaderCellCheckbox>
);

expect(console.warn).toHaveBeenCalledWith(
WARNING_MESSAGE_NOT_RECOMMENDED_UNIT
);

console.warn = originalConsoleWarn;
});
};

describe('width', testProp('width', WARNING_MESSAGE_WIDTH));
Expand Down
30 changes: 23 additions & 7 deletions packages/eui/src/components/table/table_row_cell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
WARNING_MESSAGE_MAX_WIDTH,
WARNING_MESSAGE_MIN_WIDTH,
WARNING_MESSAGE_WIDTH,
WARNING_MESSAGE_NOT_RECOMMENDED_UNIT,
} from './utils';
import { EuiTableIsResponsiveContext } from './mobile/responsive_context';

Expand Down Expand Up @@ -202,14 +203,14 @@ describe('EuiTableRowCell', () => {
it('accepts `style` prop', () => {
const { getByRole } = renderInTableRow(
<EuiTableRowCell
style={{ width: '20%', minWidth: '123px', maxWidth: '456px' }}
style={{ width: '200px', minWidth: '123px', maxWidth: '456px' }}
>
Test
</EuiTableRowCell>
);

expect(getByRole('cell')).toHaveStyle({
width: '20%',
width: '200px',
minWidth: '123px',
maxWidth: '456px',
});
Expand All @@ -225,12 +226,12 @@ describe('EuiTableRowCell', () => {

it(`accepts \`${name}\` prop`, () => {
const { getByRole } = renderInTableRow(
<EuiTableRowCell style={{ [name]: '10%' }}>Test</EuiTableRowCell>
<EuiTableRowCell style={{ [name]: '100px' }}>Test</EuiTableRowCell>
);

expect(getByRole('cell')).toHaveStyle({
...defaultStyles,
[name]: '10%',
[name]: '100px',
});
});

Expand All @@ -254,9 +255,9 @@ describe('EuiTableRowCell', () => {
console.warn = jest.fn();

const props = {
[name]: '10%',
[name]: '100px',
style: {
[name]: '20%',
[name]: '200px',
},
};

Expand All @@ -266,13 +267,28 @@ describe('EuiTableRowCell', () => {

expect(getByRole('cell')).toHaveStyle({
...defaultStyles,
[name]: '10%',
[name]: '100px',
});

expect(console.warn).toHaveBeenCalledWith(warningMessage);

console.warn = originalConsoleWarn;
});

it('warns when a not recommended unit is used', () => {
const originalConsoleWarn = console.warn;
console.warn = jest.fn();

renderInTableRow(
<EuiTableRowCell {...{ [name]: '20%' }}>Test</EuiTableRowCell>
);

expect(console.warn).toHaveBeenCalledWith(
WARNING_MESSAGE_NOT_RECOMMENDED_UNIT
);

console.warn = originalConsoleWarn;
});
};

describe('width', testProp('width', WARNING_MESSAGE_WIDTH));
Expand Down
30 changes: 19 additions & 11 deletions packages/eui/src/components/table/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,34 @@ import {
WARNING_MESSAGE_MAX_WIDTH,
WARNING_MESSAGE_MIN_WIDTH,
WARNING_MESSAGE_WIDTH,
WARNING_MESSAGE_NOT_RECOMMENDED_UNIT,
} from './utils';

describe('resolveWidthPropsAsStyle', () => {
let originalConsoleWarn: typeof console.warn;

beforeAll(() => {
originalConsoleWarn = console.warn;
console.warn = jest.fn();
});

afterAll(() => {
console.warn = originalConsoleWarn;
});

it('returns an empty style object when no style or width props are provided', () => {
expect(resolveWidthPropsAsStyle(undefined, {})).toEqual({});
expect(resolveWidthPropsAsStyle({}, {})).toEqual({});
});

const testPropAndStyle = (name: string, warningMessage: string) => () => {
let originalConsoleWarn: typeof console.warn;

beforeAll(() => {
originalConsoleWarn = console.warn;
console.warn = jest.fn();
});

afterAll(() => {
console.warn = originalConsoleWarn;
});
it('warns when a not recommended unit is used', () => {
expect(resolveWidthPropsAsStyle({}, { width: '10%' }));
expect(console.warn).toHaveBeenCalledWith(
WARNING_MESSAGE_NOT_RECOMMENDED_UNIT
);
});

const testPropAndStyle = (name: string, warningMessage: string) => () => {
it(`supports setting ${name} via the prop`, () => {
expect(resolveWidthPropsAsStyle({}, { [name]: '123px' })).toEqual({
[name]: '123px',
Expand Down
Loading