forked from FortAwesome/angular-fontawesome
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduotone-icon.component.spec.ts
More file actions
140 lines (122 loc) · 4.43 KB
/
duotone-icon.component.spec.ts
File metadata and controls
140 lines (122 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { Component, signal, viewChild, ViewContainerRef } from '@angular/core';
import { faUser } from '@fortawesome/free-solid-svg-icons';
import { faDummy, initTest, queryByCss } from '../../testing/helpers';
import { FaDuotoneIconComponent } from './duotone-icon.component';
describe('FaDuotoneIconComponent', () => {
it('should render the duotone icon', () => {
@Component({
selector: 'fa-host',
standalone: false,
template: '<fa-duotone-icon [icon]="faDummy()"></fa-duotone-icon>',
})
class HostComponent {
faDummy = signal(faDummy);
}
const fixture = initTest(HostComponent);
fixture.detectChanges();
expect(queryByCss(fixture, 'svg')).toBeTruthy();
});
it('should allow to swap opacity of the layers', () => {
@Component({
selector: 'fa-host',
standalone: false,
template: '<fa-duotone-icon [icon]="faDummy()" [swapOpacity]="true"></fa-duotone-icon>',
})
class HostComponent {
faDummy = signal(faDummy);
}
const fixture = initTest(HostComponent);
fixture.detectChanges();
expect(queryByCss(fixture, 'svg').classList.contains('fa-swap-opacity')).toBeTruthy();
});
it('should allow to customize opacity of the primary layer', () => {
@Component({
selector: 'fa-host',
standalone: false,
template: '<fa-duotone-icon [icon]="faDummy()" [primaryOpacity]="0.1"></fa-duotone-icon>',
})
class HostComponent {
faDummy = signal(faDummy);
}
const fixture = initTest(HostComponent);
fixture.detectChanges();
expect(queryByCss(fixture, 'svg').style.getPropertyValue('--fa-primary-opacity')).toBe('0.1');
});
it('should allow to customize opacity of the secondary layer', () => {
@Component({
selector: 'fa-host',
standalone: false,
template: '<fa-duotone-icon [icon]="faDummy()" [secondaryOpacity]="0.9"></fa-duotone-icon>',
})
class HostComponent {
faDummy = signal(faDummy);
}
const fixture = initTest(HostComponent);
fixture.detectChanges();
expect(queryByCss(fixture, 'svg').style.getPropertyValue('--fa-secondary-opacity')).toBe('0.9');
});
it('should allow to customize color of the primary layer', () => {
@Component({
selector: 'fa-host',
standalone: false,
template: '<fa-duotone-icon [icon]="faDummy()" primaryColor="red"></fa-duotone-icon>',
})
class HostComponent {
faDummy = signal(faDummy);
}
const fixture = initTest(HostComponent);
fixture.detectChanges();
expect(queryByCss(fixture, 'svg').style.getPropertyValue('--fa-primary-color')).toBe('red');
});
it('should allow to customize color of the secondary layer', () => {
@Component({
selector: 'fa-host',
standalone: false,
template: '<fa-duotone-icon [icon]="faDummy()" secondaryColor="red"></fa-duotone-icon>',
})
class HostComponent {
faDummy = signal(faDummy);
}
const fixture = initTest(HostComponent);
fixture.detectChanges();
expect(queryByCss(fixture, 'svg').style.getPropertyValue('--fa-secondary-color')).toBe('red');
});
it('should throw if specified icon is not a Duotone icon', () => {
@Component({
selector: 'fa-host',
standalone: false,
template: '<fa-duotone-icon [icon]="faUser()"></fa-duotone-icon>',
})
class HostComponent {
faUser = signal(faUser);
}
const fixture = initTest(HostComponent);
expect(() => fixture.detectChanges()).toThrow(
new Error(
'The specified icon does not appear to be a Duotone icon. ' +
"Check that you specified the correct style: <fa-duotone-icon [icon]=\"['fad', 'user']\"></fa-duotone-icon> " +
'or use: <fa-icon icon="user"></fa-icon> instead.',
),
);
});
it('should be able to create component dynamically', () => {
@Component({
selector: 'fa-host',
standalone: false,
template: '<ng-container #host></ng-container>',
})
class HostComponent {
container = viewChild('host', { read: ViewContainerRef });
createIcon() {
const componentRef = this.container()!.createComponent(FaDuotoneIconComponent);
componentRef.setInput('icon', faDummy);
}
}
const fixture = initTest(HostComponent);
fixture.detectChanges();
expect(queryByCss(fixture, 'svg')).toBeFalsy();
fixture.componentInstance.createIcon();
fixture.detectChanges();
expect(queryByCss(fixture, 'svg')).toBeTruthy();
});
});