Skip to content

Commit ecd0692

Browse files
authored
Scheduler - Appointment Form - Reimplement legacy QUnit tests for the new form - Part 2 (#31929)
1 parent 801a6b1 commit ecd0692

File tree

2 files changed

+161
-1
lines changed

2 files changed

+161
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,14 @@ export class PopupModel {
340340
return editSeriesButton;
341341
};
342342

343+
getEditAppointmentButton = (): HTMLElement => {
344+
const editAppointmentButton = document.querySelector('[aria-label="Edit appointment"]') as HTMLElement;
345+
if (!editAppointmentButton) {
346+
throw new Error('Edit appointment button not found');
347+
}
348+
return editAppointmentButton;
349+
};
350+
343351
openRecurrenceSettings = (): void => {
344352
if (!this.repeatEditor) {
345353
throw new Error('Repeat editor not found');

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

Lines changed: 153 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
afterEach, beforeEach, describe, expect, it, jest,
33
} from '@jest/globals';
4+
import { CustomStore } from '@js/common/data/custom_store';
45
import $ from '@js/core/renderer';
56
import type { GroupItem, Item as FormItem } from '@js/ui/form';
67
import type { ToolbarItem } from '@js/ui/popup';
@@ -297,6 +298,38 @@ describe('Appointment Form', () => {
297298

298299
expect(dataSource.items()[0].roomId).toBe(2);
299300
});
301+
302+
it('should create separate appointment when saving single appointment from series', async () => {
303+
const appointment = {
304+
text: 'recurring-app',
305+
startDate: '2017-05-01T09:30:00.000Z',
306+
endDate: '2017-05-01T11:00:00.000Z',
307+
recurrenceRule: 'FREQ=DAILY;COUNT=5',
308+
};
309+
310+
const { scheduler, POM } = await createScheduler({
311+
...getDefaultConfig(),
312+
dataSource: [{ ...appointment }],
313+
});
314+
const dataSource = (scheduler as any).getDataSource();
315+
316+
POM.openPopupByDblClick('recurring-app');
317+
POM.popup.getEditAppointmentButton().click();
318+
POM.popup.setInputValue('subjectEditor', 'single appointment');
319+
scheduler.hideAppointmentPopup(true);
320+
321+
expect(dataSource.items()).toHaveLength(2);
322+
expect(dataSource.items()[0]).toEqual({
323+
...appointment,
324+
recurrenceException: '20170501T093000Z',
325+
});
326+
expect(dataSource.items()[1]).toEqual({
327+
...appointment,
328+
text: 'single appointment',
329+
recurrenceRule: '',
330+
allDay: false,
331+
});
332+
});
300333
});
301334

302335
describe('Validation', () => {
@@ -752,6 +785,38 @@ describe('Appointment Form', () => {
752785
expect(customFieldValue).toBe('FREQ=DAILY');
753786
expect(defaultFieldValue).toBeUndefined();
754787
});
788+
789+
it('should update correct resource field if fieldExpr for resource is defined', async () => {
790+
const defaultField = 'roomId';
791+
792+
const { scheduler, POM } = await createScheduler({
793+
...getDefaultConfig(),
794+
editing: {
795+
allowUpdating: true,
796+
allowTimeZoneEditing: true,
797+
},
798+
resources: [{
799+
fieldExpr: exprValue,
800+
allowMultiple: false,
801+
dataSource: [
802+
{ text: 'Room 1', id: 1, color: '#00af2c' },
803+
{ text: 'Room 2', id: 2, color: '#56ca85' },
804+
{ text: 'Room 3', id: 3, color: '#8ecd3c' },
805+
],
806+
}],
807+
});
808+
809+
scheduler.showAppointmentPopup();
810+
811+
POM.popup.setInputValue(exprValue, 2);
812+
scheduler.hideAppointmentPopup(true);
813+
814+
const customFieldValue = scheduler.option(`dataSource[0].${exprValue}`);
815+
const defaultFieldValue = scheduler.option(`dataSource[0].${defaultField}`);
816+
817+
expect(customFieldValue).toBe(2);
818+
expect(defaultFieldValue).toBeUndefined();
819+
});
755820
});
756821

757822
describe('allDay switch', () => {
@@ -906,7 +971,7 @@ describe('Appointment Form', () => {
906971
});
907972
});
908973

909-
describe('Timezones', () => {
974+
describe('Timezone Editors', () => {
910975
it('should have correct timezone editors values', async () => {
911976
const { scheduler, POM } = await createScheduler({
912977
...getDefaultConfig(),
@@ -1130,6 +1195,93 @@ describe('Appointment Form', () => {
11301195
]),
11311196
);
11321197
});
1198+
1199+
it('should create dxTagBox for resource with multiple selection', async () => {
1200+
const { scheduler, POM } = await createScheduler({
1201+
...getDefaultConfig(),
1202+
dataSource: [{
1203+
text: 'Resource test app',
1204+
startDate: new Date(2017, 4, 9, 9, 30),
1205+
endDate: new Date(2017, 4, 9, 11),
1206+
ownerId: [1, 2],
1207+
}],
1208+
resources: [{
1209+
fieldExpr: 'ownerId',
1210+
allowMultiple: true,
1211+
dataSource: [{ text: 'Owner 1', id: 1 }, { text: 'Owner 2', id: 2 }, { text: 'Owner 3', id: 3 }],
1212+
}],
1213+
});
1214+
const dataSource = (scheduler as any).getDataSource();
1215+
const appointment = dataSource.items()[0];
1216+
1217+
scheduler.showAppointmentPopup(appointment);
1218+
1219+
const resourceEditor = POM.popup.form.getEditor('ownerId') as any;
1220+
expect(resourceEditor.NAME).toBe('dxTagBox');
1221+
expect(resourceEditor.option('value')).toEqual([1, 2]);
1222+
});
1223+
1224+
it('should create dxSelectBox for resource with single selection', async () => {
1225+
const { scheduler, POM } = await createScheduler({
1226+
...getDefaultConfig(),
1227+
dataSource: [{
1228+
text: 'Resource test app',
1229+
startDate: new Date(2017, 4, 9, 9, 30),
1230+
endDate: new Date(2017, 4, 9, 11),
1231+
ownerId: 2,
1232+
}],
1233+
resources: [{
1234+
fieldExpr: 'ownerId',
1235+
allowMultiple: false,
1236+
dataSource: [{ text: 'Owner 1', id: 1 }, { text: 'Owner 2', id: 2 }, { text: 'Owner 3', id: 3 }],
1237+
}],
1238+
});
1239+
const dataSource = (scheduler as any).getDataSource();
1240+
const appointment = dataSource.items()[0];
1241+
1242+
scheduler.showAppointmentPopup(appointment);
1243+
1244+
const resourceEditor = POM.popup.form.getEditor('ownerId') as any;
1245+
expect(resourceEditor.NAME).toBe('dxSelectBox');
1246+
expect(resourceEditor.option('value')).toEqual(2);
1247+
});
1248+
1249+
it('should load resource dataSource only once', async () => {
1250+
const resourceDataSource = new CustomStore({
1251+
load: () => [
1252+
{ text: 'Owner 1', id: 1 },
1253+
{ text: 'Owner 2', id: 2 },
1254+
{ text: 'Owner 3', id: 3 },
1255+
],
1256+
byKey: () => {},
1257+
});
1258+
const loadSpy = jest.spyOn(resourceDataSource, 'load');
1259+
const byKeySpy = jest.spyOn(resourceDataSource, 'byKey');
1260+
1261+
const { scheduler } = await createScheduler({
1262+
...getDefaultConfig(),
1263+
dataSource: [{
1264+
text: 'Resource test app',
1265+
startDate: new Date(2017, 4, 9, 9, 30),
1266+
endDate: new Date(2017, 4, 9, 11),
1267+
ownerId: [2],
1268+
}],
1269+
resources: [{
1270+
allowMultiple: true,
1271+
fieldExpr: 'ownerId',
1272+
dataSource: resourceDataSource,
1273+
}],
1274+
});
1275+
const dataSource = (scheduler as any).getDataSource();
1276+
const appointment = dataSource.items()[0];
1277+
1278+
expect(loadSpy).toHaveBeenCalledTimes(1);
1279+
1280+
scheduler.showAppointmentPopup(appointment);
1281+
1282+
expect(loadSpy).toHaveBeenCalledTimes(1);
1283+
expect(byKeySpy).toHaveBeenCalledTimes(0);
1284+
});
11331285
});
11341286

11351287
describe('Recurrence Form', () => {

0 commit comments

Comments
 (0)