Skip to content

Commit c733c39

Browse files
committed
Add unit testing
1 parent c63943c commit c733c39

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Copyright Zendesk, Inc.
3+
*
4+
* Use of this source code is governed under the Apache License, Version 2.0
5+
* found at http://www.apache.org/licenses/LICENSE-2.0.
6+
*/
7+
8+
import { getCheckeredBackground } from './getCheckeredBackground';
9+
import DEFAULT_THEME from '../elements/theme';
10+
import PALETTE from '../elements/palette';
11+
12+
describe('getCheckeredBackground', () => {
13+
it('returns a valid background', () => {
14+
const size = 10;
15+
const result = getCheckeredBackground({ theme: DEFAULT_THEME, size });
16+
const expected1 = `0 0px / ${size}px ${size}px repeat`;
17+
const expected2 = `${size / 2}px ${size / 2}px / ${size}px ${size}px repeat`;
18+
19+
expect(result).toContain(expected1);
20+
expect(result).toContain(expected2);
21+
});
22+
23+
it('handles color overlay as expected', () => {
24+
const expected = `${PALETTE.blue[700]}80`;
25+
const result = getCheckeredBackground({ theme: DEFAULT_THEME, size: 10, overlay: expected });
26+
27+
expect(result).toContain(`linear-gradient(${expected}, ${expected})`);
28+
});
29+
30+
it('handles linear-gradient overlay as expected', () => {
31+
const expected = `linear-gradient(to right, ${PALETTE.white}, ${PALETTE.black})`;
32+
const result = getCheckeredBackground({ theme: DEFAULT_THEME, size: 10, overlay: expected });
33+
34+
expect(result).toContain(`${expected},`);
35+
});
36+
37+
it('handles vertical position as expected', () => {
38+
const size = 10;
39+
const positionY = DEFAULT_THEME.space.base;
40+
const result = getCheckeredBackground({ theme: DEFAULT_THEME, size, positionY });
41+
const expected1 = `0 ${positionY}px`;
42+
const expected2 = `${size / 2}px ${size / 2 + positionY}px`;
43+
44+
expect(result).toContain(expected1);
45+
expect(result).toContain(expected2);
46+
});
47+
48+
it('handles repeat as expected', () => {
49+
const repeat = 'repeat-x';
50+
const result = getCheckeredBackground({ theme: DEFAULT_THEME, size: 10, repeat });
51+
52+
expect(result).toContain(repeat);
53+
});
54+
55+
it('handles RTL as expected', () => {
56+
const theme = { ...DEFAULT_THEME, rtl: true };
57+
const size = 10;
58+
const result = getCheckeredBackground({ theme, size });
59+
const expected1 = `100% 0px / ${size}px ${size}px repeat`;
60+
const expected2 = `calc(100% - ${size / 2}px) ${size / 2}px / ${size}px ${size}px repeat`;
61+
62+
expect(result).toContain(expected1);
63+
expect(result).toContain(expected2);
64+
});
65+
});

0 commit comments

Comments
 (0)