Skip to content

Commit e8abc07

Browse files
committed
test 'isActive' prop with data attribute
1 parent a9ce0ad commit e8abc07

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

src/components/WindowHeader/WindowHeader.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
import React from 'react';
22
import propTypes from 'prop-types';
33

4-
import styled, { css } from 'styled-components';
4+
import styled from 'styled-components';
55

66
const SlyledWindowHeader = styled.div`
77
height: 30px;
88
line-height: 30px;
99
padding-left: 0.25rem;
1010
font-weight: bold;
1111
12-
color: ${({ theme, isActive }) =>
13-
isActive ? theme.textInvert : theme.material};
14-
15-
${({ theme, isActive }) =>
16-
isActive
17-
? css`
18-
background: linear-gradient(
19-
to right,
20-
${theme.headerMaterialDark},
21-
${theme.headerMaterialLight}
22-
);
23-
`
24-
: css`
25-
background: ${theme.headerNotActive};
26-
`}
12+
&[data-active='false'] {
13+
background: ${({ theme }) => theme.headerNotActive};
14+
color: ${({ theme }) => theme.material};
15+
}
16+
&[data-active='true'] {
17+
background: linear-gradient(
18+
to right,
19+
${({ theme }) => theme.headerMaterialDark},
20+
${({ theme }) => theme.headerMaterialLight}
21+
);
22+
color: ${({ theme }) => theme.textInvert};
23+
}
2724
`;
2825
// TODO - should we add some aria label indicating if window is currently active?
2926
const WindowHeader = ({ isActive, children, ...otherProps }) => (
30-
<SlyledWindowHeader isActive={isActive} {...otherProps}>
27+
<SlyledWindowHeader data-active={isActive.toString()} {...otherProps}>
3128
{children}
3229
</SlyledWindowHeader>
3330
);

src/components/WindowHeader/WindowHeader.spec.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ describe('<WindowHeader />', () => {
2222
expect(getByText(textContent)).toBeInTheDocument();
2323
});
2424

25-
// describe('prop: isActive', () => {
26-
// it('displays active header by default', () => {
27-
// const { container } = renderWithTheme(<WindowHeader />);
28-
// const windowHeader = container.firstChild;
25+
describe('prop: isActive', () => {
26+
it('displays active header by default', () => {
27+
const { container } = renderWithTheme(<WindowHeader />);
28+
const windowHeader = container.firstChild;
2929

30-
// expect(windowHeader).toHaveAttribute('data-testid', 'activeHeader');
31-
// });
30+
expect(windowHeader).toHaveAttribute('data-active', 'true');
31+
});
3232

33-
// it('renders non-active header when set to false', () => {
34-
// const { container } = renderWithTheme(<WindowHeader isActive={false} />);
35-
// const windowHeader = container.firstChild;
33+
it('renders non-active header when set to false', () => {
34+
const { container } = renderWithTheme(<WindowHeader isActive={false} />);
35+
const windowHeader = container.firstChild;
3636

37-
// expect(windowHeader).toHaveAttribute('data-testid', 'notActiveHeader');
38-
// });
39-
// });
37+
expect(windowHeader).toHaveAttribute('data-active', 'false');
38+
});
39+
});
4040
});

0 commit comments

Comments
 (0)