Skip to content

Commit 5e6a253

Browse files
bit-byte0Maksim Zakharov
andauthored
Scheduler: refactor appointment_popup module (TS) (#33575)
Co-authored-by: Maksim Zakharov <maksim.zakharov@devexpress.com>
1 parent 01982b3 commit 5e6a253

18 files changed

Lines changed: 304 additions & 146 deletions

packages/devextreme/js/__internal/scheduler/__tests__/__mock__/create_appointment_popup.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { jest } from '@jest/globals';
2+
import type { DayOfWeek } from '@js/common';
23
import $ from '@js/core/renderer';
34
// eslint-disable-next-line devextreme-custom/no-deferred
45
import { Deferred } from '@js/core/utils/deferred';
56

67
import { mockTimeZoneCalculator } from '../../__mock__/timezone_calculator.mock';
7-
import { AppointmentForm } from '../../appointment_popup/m_form';
8+
import { AppointmentForm } from '../../appointment_popup/form';
89
import {
910
APPOINTMENT_POPUP_CLASS,
1011
AppointmentPopup,
11-
} from '../../appointment_popup/m_popup';
12+
} from '../../appointment_popup/popup';
1213
import {
1314
AppointmentDataAccessor,
1415
} from '../../utils/data_accessor/appointment_data_accessor';
@@ -118,7 +119,7 @@ export const createAppointmentPopup = async (
118119
dataAccessors,
119120
editing,
120121
resourceManager,
121-
firstDayOfWeek: options.firstDayOfWeek ?? 0,
122+
firstDayOfWeek: (options.firstDayOfWeek ?? 0) as DayOfWeek,
122123
startDayHour: options.startDayHour ?? 0,
123124
createComponent,
124125
getCalculatedEndDate: (startDate: Date): Date => {
@@ -130,7 +131,7 @@ export const createAppointmentPopup = async (
130131

131132
const form = new AppointmentForm(formConfig);
132133

133-
const noop = (): void => {};
134+
const noop = (): void => { };
134135

135136
const popupSchedulerProxy = {
136137
getElement: (): ReturnType<typeof $> => $(container),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { within } from '@testing-library/dom';
22
import { ToolbarModel } from '@ts/scheduler/__tests__/__mock__/model/toolbar';
33

4-
import { APPOINTMENT_POPUP_CLASS } from '../../../appointment_popup/m_popup';
4+
import { APPOINTMENT_POPUP_CLASS } from '../../../appointment_popup/popup';
55
import { POPUP_DIALOG_CLASS } from '../../../m_scheduler';
66
import type { AppointmentModel } from './appointment';
77
import { createAppointmentModel } from './appointment';

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ describe('Scheduler scrollTo', () => {
109109
const item = (scheduler as any).getDataSource().items()[0];
110110
scheduler.showAppointmentPopup(item);
111111
POM.popup.saveButton.click();
112+
await Promise.resolve();
112113

113114
expect(scrollLeftBeforeSave).toBe(0);
114115
expect(scrollableContainer.scrollLeft).toBeGreaterThan(0);

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ describe('Appointment Form', () => {
8585
scheduler.showAppointmentPopup(item);
8686
POM.popup.setInputValue('subjectEditor', 'New Subject');
8787
POM.popup.saveButton.click();
88+
await Promise.resolve();
8889

8990
expect(dataSource.items()[0]).toMatchObject({
9091
...commonAppointment,
@@ -121,6 +122,7 @@ describe('Appointment Form', () => {
121122
POM.popup.setInputValue('subjectEditor', 'New Subject');
122123
POM.popup.recurrenceSettingsButton.click();
123124
POM.popup.saveButton.click();
125+
await Promise.resolve();
124126

125127
expect(dataSource.items()[0]).toMatchObject({
126128
...recurringAppointment,
@@ -156,6 +158,7 @@ describe('Appointment Form', () => {
156158
scheduler.showAppointmentPopup(item);
157159
POM.popup.selectRepeatValue('daily');
158160
POM.popup.saveButton.click();
161+
await Promise.resolve();
159162

160163
expect(dataSource.items()[0]).toMatchObject({
161164
...commonAppointment,
@@ -190,6 +193,7 @@ describe('Appointment Form', () => {
190193
scheduler.showAppointmentPopup(item);
191194
POM.popup.editSeriesButton.click();
192195
POM.popup.saveButton.click();
196+
await Promise.resolve();
193197

194198
expect(dataSource.items()[0]).toMatchObject(recurringAppointment);
195199
});
@@ -207,6 +211,7 @@ describe('Appointment Form', () => {
207211
POM.popup.editSeriesButton.click();
208212
POM.popup.selectRepeatValue('never');
209213
POM.popup.saveButton.click();
214+
await Promise.resolve();
210215

211216
expect(dataSource.items()[0]).toMatchObject({
212217
...recurringAppointment,
@@ -231,6 +236,7 @@ describe('Appointment Form', () => {
231236
scheduler.showAppointmentPopup(appointment);
232237
POM.popup.setInputValue('subjectEditor', 'Updated subject');
233238
scheduler.hideAppointmentPopup(true);
239+
await Promise.resolve();
234240

235241
const items = (scheduler as any).getDataSource().items();
236242

@@ -261,6 +267,7 @@ describe('Appointment Form', () => {
261267
POM.popup.setInputValue('endTimeEditor', new Date(2017, 4, 25, 10, 0));
262268
POM.popup.setInputValue('descriptionEditor', 'New appointment description');
263269
scheduler.hideAppointmentPopup(true);
270+
await Promise.resolve();
264271

265272
const items = (scheduler as any).getDataSource().items();
266273

@@ -297,6 +304,7 @@ describe('Appointment Form', () => {
297304
scheduler.showAppointmentPopup(item);
298305
POM.popup.setInputValue('roomId', 2);
299306
POM.popup.saveButton.click();
307+
await Promise.resolve();
300308

301309
expect(dataSource.items()[0].roomId).toBe(2);
302310
});
@@ -319,6 +327,7 @@ describe('Appointment Form', () => {
319327
POM.popup.editAppointmentButton.click();
320328
POM.popup.setInputValue('subjectEditor', 'single appointment');
321329
scheduler.hideAppointmentPopup(true);
330+
await Promise.resolve();
322331

323332
expect(dataSource.items()).toHaveLength(2);
324333
expect(dataSource.items()[0]).toEqual({
@@ -344,6 +353,7 @@ describe('Appointment Form', () => {
344353

345354
POM.popup.setInputValue(editorName, null);
346355
POM.popup.saveButton.click();
356+
await Promise.resolve();
347357

348358
expect(POM.isPopupVisible()).toBe(true);
349359
});
@@ -358,6 +368,7 @@ describe('Appointment Form', () => {
358368
POM.popup.setInputValue(editorName, null);
359369
POM.popup.selectRepeatValue('daily');
360370
POM.popup.saveButton.click();
371+
await Promise.resolve();
361372

362373
expect(POM.isPopupVisible()).toBe(true);
363374
});
@@ -373,6 +384,7 @@ describe('Appointment Form', () => {
373384
expect(POM.popup.getInputValue('recurrenceStartDateEditor')).toBe('5/9/2017');
374385

375386
POM.popup.saveButton.click();
387+
await Promise.resolve();
376388

377389
expect(POM.isPopupVisible()).toBe(false);
378390
});
@@ -477,6 +489,7 @@ describe('Appointment Form', () => {
477489

478490
scheduler.showAppointmentPopup({ ...commonAppointment }, true);
479491
scheduler.hideAppointmentPopup(true);
492+
await Promise.resolve();
480493

481494
const item = dataSource.items()[0];
482495

@@ -665,6 +678,7 @@ describe('Appointment Form', () => {
665678

666679
POM.popup.setInputValue(editorName, value);
667680
scheduler.hideAppointmentPopup(true);
681+
await Promise.resolve();
668682

669683
const customFieldValue = scheduler.option(`dataSource[0].${exprValue}`);
670684
const defaultFieldValue = scheduler.option(`dataSource[0].${defaultField}`);
@@ -695,6 +709,7 @@ describe('Appointment Form', () => {
695709
POM.popup.setInputValue(dateEditorName, value);
696710
POM.popup.setInputValue(timeEditorName, value);
697711
scheduler.hideAppointmentPopup(true);
712+
await Promise.resolve();
698713

699714
const customFieldValue = scheduler.option(`dataSource[0].${exprValue}`);
700715
const defaultFieldValue = scheduler.option(`dataSource[0].${defaultField}`);
@@ -719,6 +734,7 @@ describe('Appointment Form', () => {
719734
scheduler.showAppointmentPopup();
720735
POM.popup.selectRepeatValue('daily');
721736
scheduler.hideAppointmentPopup(true);
737+
await Promise.resolve();
722738

723739
const customFieldValue = scheduler.option(`dataSource[0].${exprValue}`);
724740
const defaultFieldValue = scheduler.option(`dataSource[0].${defaultField}`);
@@ -751,6 +767,7 @@ describe('Appointment Form', () => {
751767

752768
POM.popup.setInputValue(exprValue, 2);
753769
scheduler.hideAppointmentPopup(true);
770+
await Promise.resolve();
754771

755772
const customFieldValue = scheduler.option(`dataSource[0].${exprValue}`);
756773
const defaultFieldValue = scheduler.option(`dataSource[0].${defaultField}`);
@@ -1702,6 +1719,14 @@ describe('Appointment Form', () => {
17021719
});
17031720

17041721
describe('firstDayOfWeek', () => {
1722+
beforeEach(() => {
1723+
jest.spyOn(dateLocalization, 'firstDayOfWeekIndex').mockReturnValue(3);
1724+
});
1725+
1726+
afterEach(() => {
1727+
jest.restoreAllMocks();
1728+
});
1729+
17051730
it('should apply firstDayOfWeek to week day buttons', async () => {
17061731
const { POM, scheduler } = await createScheduler(getDefaultConfig());
17071732

@@ -1777,7 +1802,7 @@ describe('Appointment Form', () => {
17771802
expect(endDateEditorAfter?.option('calendarOptions.firstDayOfWeek')).toBe(0);
17781803
});
17791804

1780-
it('should pass undefined firstDayOfWeek to calendars when option is not set', async () => {
1805+
it('should pass value from localization firstDayOfWeek to calendars when option is not set', async () => {
17811806
const { POM, scheduler } = await createScheduler({
17821807
...getDefaultConfig(),
17831808
firstDayOfWeek: undefined,
@@ -1787,7 +1812,7 @@ describe('Appointment Form', () => {
17871812

17881813
const startDateEditor = POM.popup.dxForm.getEditor('startDateEditor');
17891814
expect(startDateEditor).toBeDefined();
1790-
expect(startDateEditor?.option('calendarOptions.firstDayOfWeek')).toBeUndefined();
1815+
expect(startDateEditor?.option('calendarOptions.firstDayOfWeek')).toBe(3);
17911816
});
17921817
});
17931818

@@ -1922,6 +1947,7 @@ describe('Appointment Form', () => {
19221947

19231948
scheduler.showAppointmentPopup({ ...commonAppointment }, true);
19241949
POM.popup.saveButton.click();
1950+
await Promise.resolve();
19251951

19261952
expect(addAppointmentSpy).toHaveBeenCalledTimes(1);
19271953
expect(addAppointmentSpy).toHaveBeenCalledWith(
@@ -1937,6 +1963,7 @@ describe('Appointment Form', () => {
19371963

19381964
scheduler.showAppointmentPopup({ ...commonAppointment }, true);
19391965
POM.popup.saveButton.click();
1966+
await Promise.resolve();
19401967

19411968
const dataSource = (scheduler as any).getDataSource();
19421969
expect(dataSource.items().length).toBe(0);
@@ -1950,6 +1977,7 @@ describe('Appointment Form', () => {
19501977

19511978
scheduler.showAppointmentPopup({ ...commonAppointment }, true);
19521979
POM.popup.saveButton.click();
1980+
await Promise.resolve();
19531981

19541982
const dataSource = (scheduler as any).getDataSource();
19551983
expect(dataSource.items().length).toBe(1);
@@ -1970,6 +1998,7 @@ describe('Appointment Form', () => {
19701998
scheduler.showAppointmentPopup(updatedItem);
19711999
POM.popup.setInputValue('subjectEditor', 'Updated Subject');
19722000
POM.popup.saveButton.click();
2001+
await Promise.resolve();
19732002

19742003
expect(updateAppointmentSpy).toHaveBeenCalledTimes(1);
19752004
expect(updateAppointmentSpy).toHaveBeenCalledWith(updatedItem, updatedItem);
@@ -1987,6 +2016,7 @@ describe('Appointment Form', () => {
19872016
scheduler.showAppointmentPopup(updatedItem);
19882017
POM.popup.setInputValue('subjectEditor', 'Updated Subject');
19892018
POM.popup.saveButton.click();
2019+
await Promise.resolve();
19902020

19912021
expect(dataSource.items()[0]).toEqual(commonAppointment);
19922022
});
@@ -2003,6 +2033,7 @@ describe('Appointment Form', () => {
20032033
scheduler.showAppointmentPopup(updatedItem);
20042034
POM.popup.setInputValue('subjectEditor', 'New Subject');
20052035
POM.popup.saveButton.click();
2036+
await Promise.resolve();
20062037

20072038
expect(dataSource.items()[0]).toEqual({
20082039
allDay: false,
@@ -2119,6 +2150,7 @@ describe('Appointment Form', () => {
21192150
scheduler.showAppointmentPopup(item);
21202151
POM.popup.setInputValue('subjectEditor', 'New Subject');
21212152
scheduler.hideAppointmentPopup(true);
2153+
await Promise.resolve();
21222154

21232155
expect(dataSource.items()[0]).toMatchObject({ ...commonAppointment, text: 'New Subject' });
21242156
});
@@ -2135,6 +2167,7 @@ describe('Appointment Form', () => {
21352167
POM.popup.selectRepeatValue('weekly');
21362168
POM.popup.setInputValue('recurrenceStartDateEditor', new Date(2024, 4, 25));
21372169
scheduler.hideAppointmentPopup(true);
2170+
await Promise.resolve();
21382171

21392172
expect(dataSource.items()[0]).toMatchObject({
21402173
...commonAppointment,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ describe('Isolated AppointmentPopup environment', () => {
5454
});
5555

5656
POM.saveButton.click();
57+
await new Promise(process.nextTick);
5758

5859
expect(callbacks.onSave).toHaveBeenCalledTimes(1);
5960
expect(callbacks.onSave).toHaveBeenCalledWith(
@@ -75,6 +76,7 @@ describe('Isolated AppointmentPopup environment', () => {
7576
});
7677

7778
POM.saveButton.click();
79+
await new Promise(process.nextTick);
7880

7981
expect(callbacks.addAppointment).not.toHaveBeenCalled();
8082
expect(callbacks.updateAppointment).not.toHaveBeenCalled();
@@ -139,6 +141,7 @@ describe('Isolated AppointmentPopup environment', () => {
139141
});
140142

141143
POM.saveButton.click();
144+
await new Promise(process.nextTick);
142145

143146
expect(onSave).toHaveBeenCalledTimes(1);
144147
expect(updateAppointment).toHaveBeenCalledWith(sourceAppointment, updatedAppointment);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
describe, expect, it,
33
} from '@jest/globals';
44

5-
import { type ConfigItem, customizeFormItems, type FormItem } from './m_customize_form_items';
5+
import { type ConfigItem, customizeFormItems, type FormItem } from './customize_form_items';
66

77
const subjectGroup: FormItem = {
88
name: 'subjectGroup',

packages/devextreme/js/__internal/scheduler/appointment_popup/m_customize_form_items.ts renamed to packages/devextreme/js/__internal/scheduler/appointment_popup/customize_form_items.ts

File renamed without changes.

0 commit comments

Comments
 (0)