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 src/components/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const Button = ({
primary={primary}
onClick={disabled ? undefined : onClick}
style={style}
disabled={disabled}
isDisabled={disabled}
fullWidth={fullWidth}
size={size}
Expand Down
24 changes: 16 additions & 8 deletions src/components/Button/Button.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,21 @@ describe('<Button />', () => {
expect(button.innerHTML).toBe('click me');
});

it('should not fire click when disabled', () => {
const onButtonClick = jest.fn();
const { getByRole } = render(<Button {...defaultProps} disabled />);
const button = getByRole('button');

fireEvent.click(button);

expect(onButtonClick).not.toHaveBeenCalled();
describe('prop: disabled', () => {
it('should render disabled', () => {
const { getByRole } = render(<Button {...defaultProps} disabled />);
const button = getByRole('button');

expect(button).toHaveAttribute('disabled');
});
it('should not fire click when disabled', () => {
const onButtonClick = jest.fn();
const { getByRole } = render(<Button {...defaultProps} disabled />);
const button = getByRole('button');

fireEvent.click(button);

expect(onButtonClick).not.toHaveBeenCalled();
});
});
});
7 changes: 6 additions & 1 deletion src/components/Fieldset/Fieldset.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ const StyledLegend = styled.legend`
`;

const Fieldset = ({ label, disabled, variant, children, ...otherProps }) => (
<StyledFieldset isDisabled={disabled} variant={variant} {...otherProps}>
<StyledFieldset
aria-disabled={disabled}
isDisabled={disabled}
variant={variant}
{...otherProps}
>
{label && <StyledLegend variant={variant}>{label}</StyledLegend>}
{children}
</StyledFieldset>
Expand Down
2 changes: 2 additions & 0 deletions src/components/Fieldset/Fieldset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ describe('<Fieldset />', () => {
const { container } = renderWithTheme(<Fieldset disabled />);
const fieldset = container.firstChild;

expect(fieldset).toHaveAttribute('aria-disabled', 'true');

expect(fieldset).toHaveStyleRule('color', theme.textDisabled);
expect(fieldset).toHaveStyleRule(
'text-shadow',
Expand Down
26 changes: 13 additions & 13 deletions src/components/Table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ const StyledCutout = styled(Cutout)`
}
`;

const Table = ({ className, children, style, ...otherProps }) => (
<StyledCutout>
<StyledTable className={className} style={style} {...otherProps}>
{children}
</StyledTable>
</StyledCutout>
);
const Table = React.forwardRef(function Table(props, ref) {
const { children, ...otherProps } = props;

return (
<StyledCutout>
<StyledTable ref={ref} {...otherProps}>
{children}
</StyledTable>
</StyledCutout>
);
});

Table.defaultProps = {
children: null,
className: '',
style: {}
children: null
};

Table.propTypes = {
children: propTypes.node,
className: propTypes.string,
style: propTypes.shape([propTypes.string, propTypes.number])
children: propTypes.node
};

export default Table;
28 changes: 28 additions & 0 deletions src/components/Table/Table.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';

import { renderWithTheme } from '../../../test/utils';

import Table from './Table';

describe('<Table />', () => {
it('renders Table', () => {
const { container } = renderWithTheme(<Table />);
const list = container.firstChild;

expect(list).toBeInTheDocument();
});
it('renders table element', () => {
const { getByRole } = renderWithTheme(<Table />);

expect(getByRole('table')).toBeInTheDocument();
});
it('renders children', () => {
const textContent = 'Hi there!';
const { getByText } = renderWithTheme(
<Table>
<span>{textContent}</span>
</Table>
);
expect(getByText(textContent)).toBeInTheDocument();
});
});
4 changes: 2 additions & 2 deletions src/components/Table/Table.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import WindowHeader from '../WindowHeader/WindowHeader';
import WindowContent from '../WindowContent/WindowContent';

const SimpleTable = () => (
<Window>
<Window style={{ width: 320 }}>
<WindowHeader>Pokedex.exe</WindowHeader>
<WindowContent>
<Table>
<TableHead>
<TableRow head>
<TableHeadCell>Type</TableHeadCell>
<TableHeadCell>Name</TableHeadCell>
<TableHeadCell>Lvl.</TableHeadCell>
<TableHeadCell disabled>Level</TableHeadCell>
</TableRow>
</TableHead>
<TableBody>
Expand Down
22 changes: 11 additions & 11 deletions src/components/TableBody/TableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ const StyledTableBody = styled.tbody`
box-shadow: ${insetShadow};
`;

const TableBody = ({ className, children, style, ...otherProps }) => (
<StyledTableBody className={className} style={style} {...otherProps}>
{children}
</StyledTableBody>
);
const TableBody = React.forwardRef(function TableBody(props, ref) {
const { children, ...otherProps } = props;

return (
<StyledTableBody ref={ref} {...otherProps}>
{children}
</StyledTableBody>
);
});

TableBody.defaultProps = {
children: null,
className: '',
style: {}
children: null
};

TableBody.propTypes = {
children: propTypes.node,
className: propTypes.string,
style: propTypes.shape([propTypes.string, propTypes.number])
children: propTypes.node
};

export default TableBody;
28 changes: 28 additions & 0 deletions src/components/TableBody/TableBody.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';

import { renderWithTheme } from '../../../test/utils';

import TableBody from './TableBody';

describe('<TableBody />', () => {
it('renders TableBody', () => {
const { container } = renderWithTheme(<TableBody />);
const list = container.firstChild;

expect(list).toBeInTheDocument();
});
it('renders tbody element', () => {
const { container } = renderWithTheme(<TableBody />);

expect(container.querySelector('tbody')).toBeInTheDocument();
});
it('renders children', () => {
const textContent = 'Hi there!';
const { getByText } = renderWithTheme(
<TableBody>
<span>{textContent}</span>
</TableBody>
);
expect(getByText(textContent)).toBeInTheDocument();
});
});
21 changes: 10 additions & 11 deletions src/components/TableDataCell/TableDataCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@ import { padding } from '../common/system';
const StyledTd = styled.td`
padding: 0 ${padding.sm};
`;
const TableDataCell = ({ className, children, style, ...otherProps }) => (
<StyledTd className={className} style={style} {...otherProps}>
{children}
</StyledTd>
);
const TableDataCell = React.forwardRef(function TableDataCell(props, ref) {
const { children, ...otherProps } = props;
return (
<StyledTd ref={ref} {...otherProps}>
{children}
</StyledTd>
);
});

TableDataCell.defaultProps = {
children: null,
className: '',
style: {}
children: null
};

TableDataCell.propTypes = {
children: propTypes.node,
className: propTypes.string,
style: propTypes.shape([propTypes.string, propTypes.number])
children: propTypes.node
};

export default TableDataCell;
28 changes: 28 additions & 0 deletions src/components/TableDataCell/TableDataCell.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';

import { renderWithTheme } from '../../../test/utils';

import TableDataCell from './TableDataCell';

describe('<TableDataCell />', () => {
it('renders TableDataCell', () => {
const { container } = renderWithTheme(<TableDataCell />);
const list = container.firstChild;

expect(list).toBeInTheDocument();
});
it('renders td element', () => {
const { container } = renderWithTheme(<TableDataCell />);

expect(container.querySelector('td')).toBeInTheDocument();
});
it('renders children', () => {
const textContent = 'Hi there!';
const { getByText } = renderWithTheme(
<TableDataCell>
<span>{textContent}</span>
</TableDataCell>
);
expect(getByText(textContent)).toBeInTheDocument();
});
});
21 changes: 10 additions & 11 deletions src/components/TableHead/TableHead.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ import styled from 'styled-components';
const StyledTableHead = styled.thead`
display: table-header-group;
`;
const TableHead = ({ className, children, style, ...otherProps }) => (
<StyledTableHead className={className} style={style} {...otherProps}>
{children}
</StyledTableHead>
);
const TableHead = React.forwardRef(function TableHead(props, ref) {
const { children, ...otherProps } = props;
return (
<StyledTableHead ref={ref} {...otherProps}>
{children}
</StyledTableHead>
);
});

TableHead.defaultProps = {
children: null,
className: '',
style: {}
children: null
};

TableHead.propTypes = {
children: propTypes.node,
className: propTypes.string,
style: propTypes.shape([propTypes.string, propTypes.number])
children: propTypes.node
};

export default TableHead;
28 changes: 28 additions & 0 deletions src/components/TableHead/TableHead.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';

import { renderWithTheme } from '../../../test/utils';

import TableHead from './TableHead';

describe('<TableHead />', () => {
it('renders TableHead', () => {
const { container } = renderWithTheme(<TableHead />);
const list = container.firstChild;

expect(list).toBeInTheDocument();
});
it('renders thead element', () => {
const { container } = renderWithTheme(<TableHead />);

expect(container.querySelector('thead')).toBeInTheDocument();
});
it('renders children', () => {
const textContent = 'Hi there!';
const { getByText } = renderWithTheme(
<TableHead>
<span>{textContent}</span>
</TableHead>
);
expect(getByText(textContent)).toBeInTheDocument();
});
});
Loading