Skip to content

Commit 9f68509

Browse files
committed
test(icons-angular): update
1 parent 82180e5 commit 9f68509

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

projects/coreui-icons-angular/src/lib/icon/icon.component.spec.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,29 @@ import { IconSetService } from '../icon-set';
88
import { By } from '@angular/platform-browser';
99

1010
@Component({
11-
template: `
12-
<div>
13-
<c-icon #icon name="cil-list" size="lg" class="test"></c-icon>
14-
</div>`
11+
template: '<c-icon #icon name="cil-list" size="lg" class="test" />',
12+
standalone: true,
13+
imports: [IconComponent],
14+
providers: [IconSetService]
1515
})
1616
class TestComponent {
17-
@ViewChild('icon', {read: IconComponent}) iconRef!: IconComponent;
17+
@ViewChild('icon', { read: IconComponent }) iconRef!: IconComponent;
1818

1919
constructor(
2020
public iconSet: IconSetService
2121
) {
22-
this.iconSet.icons = {cilList};
22+
this.iconSet.icons = { cilList };
2323
}
2424
}
2525

26-
2726
describe('IconComponent', () => {
2827
let inputEl: DebugElement;
2928
let component: TestComponent;
3029
let fixture: ComponentFixture<TestComponent>;
3130

3231
beforeEach(async () => {
3332
TestBed.configureTestingModule({
34-
declarations: [TestComponent],
35-
imports: [IconComponent, HtmlAttributesDirective],
33+
imports: [TestComponent, IconComponent, HtmlAttributesDirective],
3634
providers: [IconSetService]
3735
}).compileComponents();
3836

projects/coreui-icons-angular/src/lib/icon/icon.directive.spec.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, DebugElement, Renderer2, Type, ViewChild } from '@angular/core';
1+
import { Component, DebugElement, ElementRef, Renderer2, Type, ViewChild } from '@angular/core';
22
import { ComponentFixture, TestBed } from '@angular/core/testing';
33
import { By, DomSanitizer } from '@angular/platform-browser';
44

@@ -7,8 +7,10 @@ import { IconSetService } from '../icon-set';
77
import { cilList } from '@coreui/icons';
88

99
@Component({
10-
template: `
11-
<svg [cIcon]="this.iconSet.icons.cilList" size="lg" class="test" title="Test"></svg>`
10+
template: '<svg [cIcon]="this.iconSet.icons.cilList" size="lg" class="test" title="Test"></svg>',
11+
standalone: true,
12+
imports: [IconDirective],
13+
providers: [IconSetService]
1214
})
1315
class TestComponent {
1416
constructor(
@@ -17,10 +19,13 @@ class TestComponent {
1719
this.iconSet.icons = { cilList };
1820
}
1921

20-
@ViewChild(IconDirective, { read: IconDirective }) iconRef!: IconDirective;
22+
@ViewChild(IconDirective, { read: IconDirective }) public iconRef!: IconDirective;
2123
}
2224

25+
class MockElementRef extends ElementRef {}
26+
2327
describe('IconDirective', () => {
28+
let component: TestComponent;
2429
let fixture: ComponentFixture<TestComponent>;
2530
let svgEl: DebugElement;
2631
let renderer: Renderer2;
@@ -29,12 +34,12 @@ describe('IconDirective', () => {
2934

3035
beforeEach(() => {
3136
TestBed.configureTestingModule({
32-
declarations: [TestComponent],
33-
providers: [IconSetService],
34-
imports: [IconDirective]
37+
providers: [IconSetService, { provide: ElementRef, useClass: MockElementRef }],
38+
imports: [IconDirective, TestComponent]
3539
}).compileComponents();
3640

3741
fixture = TestBed.createComponent(TestComponent);
42+
component = fixture.componentInstance;
3843
fixture.detectChanges();
3944
svgEl = fixture.debugElement.query(By.css('svg'));
4045
renderer = fixture.componentRef.injector.get(Renderer2 as Type<Renderer2>);
@@ -43,16 +48,27 @@ describe('IconDirective', () => {
4348
});
4449
it('should create an instance', () => {
4550
TestBed.runInInjectionContext(() => {
46-
const directive = new IconDirective(renderer, svgEl, sanitizer, iconSetService);
51+
const directive = new IconDirective();
4752
expect(directive).toBeTruthy();
4853
});
4954
});
55+
56+
it('service should exist', () => {
57+
expect(component.iconSet).toBeTruthy();
58+
});
59+
60+
it('icon component should render', () => {
61+
expect(component.iconRef).toBeTruthy();
62+
expect(component.iconRef.code()).toBe(component.iconSet.icons['cilList']);
63+
});
64+
5065
it('icon classes should be applied', () => {
5166
expect(svgEl.nativeElement).toBeTruthy();
5267
expect(svgEl.nativeElement).toHaveClass('icon');
5368
expect(svgEl.nativeElement).toHaveClass('icon-lg');
5469
expect(svgEl.nativeElement).toHaveClass('test');
5570
});
71+
5672
it('icon attributes should be applied', () => {
5773
expect(svgEl.nativeElement.getAttribute('aria-hidden')).toBe('true');
5874
expect(svgEl.nativeElement.getAttribute('pointer-events')).toBe('none');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy