Skip to content

Commit 5bd3bfe

Browse files
Copilotdevoto13
andauthored
Fix undefined values appearing in CSS class names (#487)
* Initial plan * Fix undefined class names in DOM Co-authored-by: devoto13 <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: devoto13 <[email protected]>
1 parent 5e71eb5 commit 5bd3bfe

File tree

2 files changed

+86
-2
lines changed

2 files changed

+86
-2
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { faClassList } from './classlist.util';
2+
import { FaProps } from '../models/props.model';
3+
4+
describe('faClassList', () => {
5+
it('should not include undefined in class names when properties are undefined', () => {
6+
const props: FaProps = {
7+
flip: undefined,
8+
animation: undefined,
9+
border: undefined,
10+
inverse: undefined,
11+
size: undefined,
12+
pull: undefined,
13+
rotate: undefined,
14+
fixedWidth: false,
15+
stackItemSize: undefined,
16+
};
17+
18+
const classList = faClassList(props);
19+
20+
// Check that no class contains the string "undefined"
21+
const classesWithUndefined = classList.filter((className) => className.includes('undefined'));
22+
expect(classesWithUndefined.length).toBe(0);
23+
});
24+
25+
it('should not include undefined in class names when pull is undefined', () => {
26+
const props: FaProps = {
27+
flip: undefined,
28+
animation: undefined,
29+
border: undefined,
30+
inverse: undefined,
31+
size: undefined,
32+
pull: undefined,
33+
rotate: undefined,
34+
fixedWidth: false,
35+
stackItemSize: undefined,
36+
};
37+
38+
const classList = faClassList(props);
39+
40+
expect(classList).not.toContain('fa-pull-undefined');
41+
});
42+
43+
it('should not include undefined in class names when size is undefined', () => {
44+
const props: FaProps = {
45+
flip: undefined,
46+
animation: undefined,
47+
border: undefined,
48+
inverse: undefined,
49+
size: undefined,
50+
pull: undefined,
51+
rotate: undefined,
52+
fixedWidth: false,
53+
stackItemSize: undefined,
54+
};
55+
56+
const classList = faClassList(props);
57+
58+
expect(classList).not.toContain('fa-undefined');
59+
});
60+
61+
it('should include correct class names when properties are set', () => {
62+
const props: FaProps = {
63+
flip: 'horizontal',
64+
animation: 'bounce',
65+
border: true,
66+
inverse: false,
67+
size: 'lg',
68+
pull: 'left',
69+
rotate: 90,
70+
fixedWidth: true,
71+
stackItemSize: undefined,
72+
};
73+
74+
const classList = faClassList(props);
75+
76+
expect(classList).toContain('fa-bounce');
77+
expect(classList).toContain('fa-fw');
78+
expect(classList).toContain('fa-border');
79+
expect(classList).toContain('fa-flip-horizontal');
80+
expect(classList).toContain('fa-lg');
81+
expect(classList).toContain('fa-rotate-90');
82+
expect(classList).toContain('fa-pull-left');
83+
});
84+
});

src/lib/shared/utils/classlist.util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ export const faClassList = (props: FaProps): string[] => {
2727
'fa-layers-counter': props.counter,
2828
'fa-flip-horizontal': props.flip === 'horizontal' || props.flip === 'both',
2929
'fa-flip-vertical': props.flip === 'vertical' || props.flip === 'both',
30-
[`fa-${props.size}`]: props.size !== null,
30+
[`fa-${props.size}`]: props.size != null,
3131
[`fa-rotate-${props.rotate}`]: knownRotateValue,
3232
'fa-rotate-by': props.rotate != null && !knownRotateValue,
33-
[`fa-pull-${props.pull}`]: props.pull !== null,
33+
[`fa-pull-${props.pull}`]: props.pull != null,
3434
[`fa-stack-${props.stackItemSize}`]: props.stackItemSize != null,
3535
};
3636

0 commit comments

Comments
 (0)