Skip to content

Commit 263d13a

Browse files
authored
Merge pull request #94 from arturbien/feature/table-enhancements-and-tests
Feature/table enhancements and tests
2 parents c48fccf + 9931425 commit 263d13a

File tree

17 files changed

+340
-111
lines changed

17 files changed

+340
-111
lines changed

src/components/Button/Button.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const Button = ({
120120
primary={primary}
121121
onClick={disabled ? undefined : onClick}
122122
style={style}
123+
disabled={disabled}
123124
isDisabled={disabled}
124125
fullWidth={fullWidth}
125126
size={size}

src/components/Button/Button.spec.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,21 @@ describe('<Button />', () => {
9898
expect(button.innerHTML).toBe('click me');
9999
});
100100

101-
it('should not fire click when disabled', () => {
102-
const onButtonClick = jest.fn();
103-
const { getByRole } = render(<Button {...defaultProps} disabled />);
104-
const button = getByRole('button');
105-
106-
fireEvent.click(button);
107-
108-
expect(onButtonClick).not.toHaveBeenCalled();
101+
describe('prop: disabled', () => {
102+
it('should render disabled', () => {
103+
const { getByRole } = render(<Button {...defaultProps} disabled />);
104+
const button = getByRole('button');
105+
106+
expect(button).toHaveAttribute('disabled');
107+
});
108+
it('should not fire click when disabled', () => {
109+
const onButtonClick = jest.fn();
110+
const { getByRole } = render(<Button {...defaultProps} disabled />);
111+
const button = getByRole('button');
112+
113+
fireEvent.click(button);
114+
115+
expect(onButtonClick).not.toHaveBeenCalled();
116+
});
109117
});
110118
});

src/components/Fieldset/Fieldset.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ const StyledLegend = styled.legend`
3636
`;
3737

3838
const Fieldset = ({ label, disabled, variant, children, ...otherProps }) => (
39-
<StyledFieldset isDisabled={disabled} variant={variant} {...otherProps}>
39+
<StyledFieldset
40+
aria-disabled={disabled}
41+
isDisabled={disabled}
42+
variant={variant}
43+
{...otherProps}
44+
>
4045
{label && <StyledLegend variant={variant}>{label}</StyledLegend>}
4146
{children}
4247
</StyledFieldset>

src/components/Fieldset/Fieldset.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ describe('<Fieldset />', () => {
4141
const { container } = renderWithTheme(<Fieldset disabled />);
4242
const fieldset = container.firstChild;
4343

44+
expect(fieldset).toHaveAttribute('aria-disabled', 'true');
45+
4446
expect(fieldset).toHaveStyleRule('color', theme.textDisabled);
4547
expect(fieldset).toHaveStyleRule(
4648
'text-shadow',

src/components/Table/Table.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ const StyledCutout = styled(Cutout)`
1717
}
1818
`;
1919

20-
const Table = ({ className, children, style, ...otherProps }) => (
21-
<StyledCutout>
22-
<StyledTable className={className} style={style} {...otherProps}>
23-
{children}
24-
</StyledTable>
25-
</StyledCutout>
26-
);
20+
const Table = React.forwardRef(function Table(props, ref) {
21+
const { children, ...otherProps } = props;
22+
23+
return (
24+
<StyledCutout>
25+
<StyledTable ref={ref} {...otherProps}>
26+
{children}
27+
</StyledTable>
28+
</StyledCutout>
29+
);
30+
});
2731

2832
Table.defaultProps = {
29-
children: null,
30-
className: '',
31-
style: {}
33+
children: null
3234
};
3335

3436
Table.propTypes = {
35-
children: propTypes.node,
36-
className: propTypes.string,
37-
style: propTypes.shape([propTypes.string, propTypes.number])
37+
children: propTypes.node
3838
};
3939

4040
export default Table;

src/components/Table/Table.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
3+
import { renderWithTheme } from '../../../test/utils';
4+
5+
import Table from './Table';
6+
7+
describe('<Table />', () => {
8+
it('renders Table', () => {
9+
const { container } = renderWithTheme(<Table />);
10+
const list = container.firstChild;
11+
12+
expect(list).toBeInTheDocument();
13+
});
14+
it('renders table element', () => {
15+
const { getByRole } = renderWithTheme(<Table />);
16+
17+
expect(getByRole('table')).toBeInTheDocument();
18+
});
19+
it('renders children', () => {
20+
const textContent = 'Hi there!';
21+
const { getByText } = renderWithTheme(
22+
<Table>
23+
<span>{textContent}</span>
24+
</Table>
25+
);
26+
expect(getByText(textContent)).toBeInTheDocument();
27+
});
28+
});

src/components/Table/Table.stories.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import WindowHeader from '../WindowHeader/WindowHeader';
1313
import WindowContent from '../WindowContent/WindowContent';
1414

1515
const SimpleTable = () => (
16-
<Window>
16+
<Window style={{ width: 320 }}>
1717
<WindowHeader>Pokedex.exe</WindowHeader>
1818
<WindowContent>
1919
<Table>
2020
<TableHead>
2121
<TableRow head>
2222
<TableHeadCell>Type</TableHeadCell>
2323
<TableHeadCell>Name</TableHeadCell>
24-
<TableHeadCell>Lvl.</TableHeadCell>
24+
<TableHeadCell disabled>Level</TableHeadCell>
2525
</TableRow>
2626
</TableHead>
2727
<TableBody>

src/components/TableBody/TableBody.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ const StyledTableBody = styled.tbody`
1010
box-shadow: ${insetShadow};
1111
`;
1212

13-
const TableBody = ({ className, children, style, ...otherProps }) => (
14-
<StyledTableBody className={className} style={style} {...otherProps}>
15-
{children}
16-
</StyledTableBody>
17-
);
13+
const TableBody = React.forwardRef(function TableBody(props, ref) {
14+
const { children, ...otherProps } = props;
15+
16+
return (
17+
<StyledTableBody ref={ref} {...otherProps}>
18+
{children}
19+
</StyledTableBody>
20+
);
21+
});
1822

1923
TableBody.defaultProps = {
20-
children: null,
21-
className: '',
22-
style: {}
24+
children: null
2325
};
2426

2527
TableBody.propTypes = {
26-
children: propTypes.node,
27-
className: propTypes.string,
28-
style: propTypes.shape([propTypes.string, propTypes.number])
28+
children: propTypes.node
2929
};
3030

3131
export default TableBody;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
3+
import { renderWithTheme } from '../../../test/utils';
4+
5+
import TableBody from './TableBody';
6+
7+
describe('<TableBody />', () => {
8+
it('renders TableBody', () => {
9+
const { container } = renderWithTheme(<TableBody />);
10+
const list = container.firstChild;
11+
12+
expect(list).toBeInTheDocument();
13+
});
14+
it('renders tbody element', () => {
15+
const { container } = renderWithTheme(<TableBody />);
16+
17+
expect(container.querySelector('tbody')).toBeInTheDocument();
18+
});
19+
it('renders children', () => {
20+
const textContent = 'Hi there!';
21+
const { getByText } = renderWithTheme(
22+
<TableBody>
23+
<span>{textContent}</span>
24+
</TableBody>
25+
);
26+
expect(getByText(textContent)).toBeInTheDocument();
27+
});
28+
});

src/components/TableDataCell/TableDataCell.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,21 @@ import { padding } from '../common/system';
77
const StyledTd = styled.td`
88
padding: 0 ${padding.sm};
99
`;
10-
const TableDataCell = ({ className, children, style, ...otherProps }) => (
11-
<StyledTd className={className} style={style} {...otherProps}>
12-
{children}
13-
</StyledTd>
14-
);
10+
const TableDataCell = React.forwardRef(function TableDataCell(props, ref) {
11+
const { children, ...otherProps } = props;
12+
return (
13+
<StyledTd ref={ref} {...otherProps}>
14+
{children}
15+
</StyledTd>
16+
);
17+
});
1518

1619
TableDataCell.defaultProps = {
17-
children: null,
18-
className: '',
19-
style: {}
20+
children: null
2021
};
2122

2223
TableDataCell.propTypes = {
23-
children: propTypes.node,
24-
className: propTypes.string,
25-
style: propTypes.shape([propTypes.string, propTypes.number])
24+
children: propTypes.node
2625
};
2726

2827
export default TableDataCell;

0 commit comments

Comments
 (0)