Skip to content

Commit e0c9aa6

Browse files
Scheduler - Resource's icon option does not support FontAwesome/SVG (T1321514) (DevExpress#32622)
1 parent 288e795 commit e0c9aa6

File tree

4 files changed

+76
-7
lines changed

4 files changed

+76
-7
lines changed

packages/devextreme/js/__internal/scheduler/__tests__/__mock__/model/popup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export class PopupModel {
4444
return queryRequiredElement(this.element, '.dx-scheduler-form-subject-group .dx-scheduler-form-icon .dx-icon');
4545
}
4646

47+
get resourceIcon(): HTMLElement {
48+
return queryRequiredElement(this.element, '.dx-scheduler-form-resources-group .dx-icon');
49+
}
50+
4751
get recurrenceWeekDayButtons(): HTMLElement {
4852
return queryRequiredElement(this.element, '.dx-scheduler-days-of-week-buttons');
4953
}

packages/devextreme/js/__internal/scheduler/appointment_popup/appointment_popup.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,32 @@ describe('Appointment Form', () => {
11861186
);
11871187
});
11881188

1189+
it('should render FontAwesome icon with correct CSS classes (T1322161)', async () => {
1190+
const { scheduler, POM } = await createScheduler({
1191+
...getDefaultConfig(),
1192+
dataSource: [{
1193+
text: 'Resource test app',
1194+
startDate: new Date(2017, 4, 9, 9, 30),
1195+
endDate: new Date(2017, 4, 9, 11),
1196+
roomId: 1,
1197+
}],
1198+
resources: [{
1199+
fieldExpr: 'roomId',
1200+
icon: 'fas fa-home',
1201+
dataSource: [{ text: 'Room 1', id: 1 }, { text: 'Room 2', id: 2 }],
1202+
}],
1203+
});
1204+
const dataSource = (scheduler as any).getDataSource();
1205+
const appointment = dataSource.items()[0];
1206+
1207+
scheduler.showAppointmentPopup(appointment);
1208+
1209+
const { resourceIcon } = POM.popup;
1210+
1211+
expect(resourceIcon.classList.contains('fas')).toBe(true);
1212+
expect(resourceIcon.classList.contains('fa-home')).toBe(true);
1213+
});
1214+
11891215
it('should create dxTagBox for resource with multiple selection', async () => {
11901216
const { scheduler, POM } = await createScheduler({
11911217
...getDefaultConfig(),
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { describe, expect, it } from '@jest/globals';
2+
3+
import { createFormIconTemplate } from './utils';
4+
5+
describe('createFormIconTemplate', () => {
6+
describe('FontAwesome icons support', () => {
7+
it('should create icon element with FontAwesome classes', () => {
8+
const template = createFormIconTemplate('fas fa-home');
9+
const $icon = template();
10+
11+
expect($icon.hasClass('dx-icon')).toBe(true);
12+
expect($icon.hasClass('fas')).toBe(true);
13+
expect($icon.hasClass('fa-home')).toBe(true);
14+
});
15+
16+
it('should create icon element with FontAwesome solid icon', () => {
17+
const template = createFormIconTemplate('fa-solid fa-user');
18+
const $icon = template();
19+
20+
expect($icon.hasClass('dx-icon')).toBe(true);
21+
expect($icon.hasClass('fa-solid')).toBe(true);
22+
expect($icon.hasClass('fa-user')).toBe(true);
23+
});
24+
});
25+
26+
describe('DevExtreme icons support', () => {
27+
it('should create icon element with DevExtreme icon class', () => {
28+
const template = createFormIconTemplate('tags');
29+
const $icon = template();
30+
31+
expect($icon.hasClass('dx-icon')).toBe(true);
32+
expect($icon.hasClass('dx-icon-tags')).toBe(true);
33+
});
34+
});
35+
36+
describe('empty icon', () => {
37+
it('should create sized gap element when icon name is empty', () => {
38+
const template = createFormIconTemplate('');
39+
const $element = template();
40+
41+
expect($element.hasClass('dx-scheduler-form-icon-sized-gap')).toBe(true);
42+
});
43+
});
44+
});

packages/devextreme/js/__internal/scheduler/appointment_popup/utils.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@ import { isDefined } from '@js/core/utils/type';
66
import type { Properties as DateBoxProperties } from '@js/ui/date_box';
77
import type { SimpleItem } from '@js/ui/form';
88

9+
import { getImageContainer } from '../../core/utils/m_icon';
910
import { getRecurrenceString, parseRecurrenceRule } from '../recurrence/base';
1011
import { daysFromByDayRule } from '../recurrence/days_from_by_day_rule';
1112
import type { Rule } from '../recurrence/types';
1213

13-
export const createFormIconTemplate = (iconName: string): () => dxElementWrapper => {
14-
if (iconName.length === 0) {
15-
return (): dxElementWrapper => $('<div>').addClass('dx-scheduler-form-icon-sized-gap');
16-
}
17-
18-
return (): dxElementWrapper => $('<i>').addClass('dx-icon').addClass(`dx-icon-${iconName}`);
19-
};
14+
export const createFormIconTemplate = (iconName: string): () => dxElementWrapper => (): dxElementWrapper => getImageContainer(iconName) ?? $('<div>').addClass('dx-scheduler-form-icon-sized-gap');
2015

2116
export const getStartDateCommonConfig = (firstDayOfWeek: string): SimpleItem => ({
2217
colSpan: 1,

0 commit comments

Comments
 (0)