Skip to content

Commit e78edcd

Browse files
committed
Support custom path for icons file
1 parent 8ff4f88 commit e78edcd

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { CpsIconComponent, ICONS_PATH } from './cps-icon.component';
3+
import { CommonModule } from '@angular/common';
4+
5+
describe('CpsIconComponent', () => {
6+
const createComponent = () => {
7+
fixture = TestBed.createComponent(CpsIconComponent);
8+
component = fixture.componentInstance;
9+
fixture.detectChanges();
10+
};
11+
12+
let component: CpsIconComponent;
13+
let fixture: ComponentFixture<CpsIconComponent>;
14+
15+
beforeEach(async () => {
16+
await TestBed.configureTestingModule({
17+
imports: [CommonModule, CpsIconComponent],
18+
providers: [{ provide: ICONS_PATH, useValue: 'test-assets' }]
19+
}).compileComponents();
20+
});
21+
22+
it('should create', () => {
23+
createComponent();
24+
expect(component).toBeTruthy();
25+
});
26+
27+
describe('Test assets path injection', () => {
28+
it('should use injected ICONS_PATH value', () => {
29+
createComponent();
30+
expect(component.url).toBe('test-assets');
31+
});
32+
33+
it('should default to "assets/" if no ICONS_PATH is provided', () => {
34+
TestBed.overrideProvider(ICONS_PATH, {
35+
useValue: null
36+
});
37+
createComponent();
38+
expect(component.url).toBe('assets/');
39+
});
40+
});
41+
});

projects/cps-ui-kit/src/lib/components/cps-icon/cps-icon.component.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
import { CommonModule, DOCUMENT } from '@angular/common';
2-
import { Component, Inject, Input, OnChanges } from '@angular/core';
2+
import {
3+
Component,
4+
inject,
5+
Inject,
6+
InjectionToken,
7+
Input,
8+
OnChanges
9+
} from '@angular/core';
310
import { convertSize } from '../../utils/internal/size-utils';
411
import { getCSSColor } from '../../utils/colors-utils';
512

13+
/**
14+
* Injection token that is used to provide the path to the icons.
15+
*/
16+
export const ICONS_PATH = new InjectionToken<string>(
17+
'Icons path for CpsIconComponent'
18+
);
19+
620
export const iconNames = [
721
'access',
822
'access-denied',
@@ -176,7 +190,7 @@ export class CpsIconComponent implements OnChanges {
176190
@Input() color = 'currentColor';
177191

178192
iconColor = 'currentColor';
179-
url = 'assets/';
193+
url = inject(ICONS_PATH, { optional: true }) ?? 'assets/';
180194
cvtSize = '';
181195

182196
classesList: string[] = ['cps-icon'];

0 commit comments

Comments
 (0)