Skip to content

Commit 6314c13

Browse files
committed
add jest tests
1 parent effedd4 commit 6314c13

File tree

13 files changed

+126
-88
lines changed

13 files changed

+126
-88
lines changed

e2e/testcafe-devextreme/tests/scheduler/common/layout/appointments/collector.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ generateOptionMatrix({
8686
});
8787
});
8888

89+
['generic.light', 'material.blue.light', 'fluent.blue.light'].forEach((theme) => {
90+
test(`Appointment collector has correct offset when month view with double interval theme=${theme}`, async (t) => {
91+
const scheduler = new Scheduler('#container');
92+
93+
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);
94+
95+
await t
96+
.expect(await takeScreenshot(`appointment-collector-month-double-interval-${theme}.png`, scheduler.workSpace))
97+
.ok()
98+
99+
.expect(compareResults.isValid())
100+
.ok(compareResults.errorMessages());
101+
}).before(async () => {
102+
await changeTheme(theme);
103+
104+
return createWidget('dxScheduler', {
105+
...getSchedulerBaseOptions('month'),
106+
views: [{ type: 'month', intervalCount: 2 }],
107+
});
108+
}).after(async () => {
109+
await changeTheme('generic.light');
110+
});
111+
});
112+
89113
generateOptionMatrix({
90114
view: ['day', 'week', 'workWeek', 'month', 'timelineDay', 'timelineWeek', 'timelineWorkWeek', 'timelineMonth'],
91115
variants: [

packages/devextreme/js/__internal/scheduler/appointments/m_appointment_collection.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ class SchedulerAppointments extends CollectionWidget {
234234
allowResize: true,
235235
allowAllDayResize: true,
236236
onAppointmentDblClick: null,
237-
_collectorOffset: 0,
238237
groups: [],
239238
resources: [],
240239
});
@@ -1006,7 +1005,7 @@ class SchedulerAppointments extends CollectionWidget {
10061005
items,
10071006
buttonColor: items.colors[0],
10081007
sortedIndex: appointment.sortedIndex,
1009-
width: appointment.width - this.option('_collectorOffset'),
1008+
width: appointment.width,
10101009
height: appointment.height,
10111010
onAppointmentClick: this.option('onItemClick'),
10121011
allowDrag: this.option('allowDrag'),
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import {
2+
describe, expect, it,
3+
} from '@jest/globals';
4+
5+
import { VIEW_TYPES } from '../../utils/options/constants_view';
6+
import type { ViewType } from '../../utils/options/types';
7+
import { getDeltaTime } from './get_delta_time';
8+
9+
describe('getDeltaTime', () => {
10+
VIEW_TYPES.forEach((view) => {
11+
it(`should return zero for not resized appointment in ${view} view`, () => {
12+
expect(getDeltaTime(
13+
{ width: 100, height: 100 },
14+
{ width: 100, height: 100 },
15+
{
16+
viewType: view,
17+
cellSize: { width: 50, height: 50 },
18+
resizableStep: 50,
19+
cellDurationInMinutes: 30,
20+
isAllDay: true,
21+
},
22+
)).toBe(0);
23+
});
24+
});
25+
26+
['day', 'week', 'workWeek'].forEach((view) => {
27+
it(`should return correct delta in px for resized appointment in vertical ${view} view`, () => {
28+
expect(getDeltaTime(
29+
{ width: 100, height: 50 },
30+
{ width: 100, height: 100 },
31+
{
32+
viewType: view as ViewType,
33+
cellSize: { width: 50, height: 50 },
34+
resizableStep: 50,
35+
cellDurationInMinutes: 30,
36+
isAllDay: false,
37+
},
38+
)).toBe(-30 * 60_000);
39+
});
40+
41+
it(`should return correct delta in px for resized all day appointment in vertical ${view} view`, () => {
42+
expect(getDeltaTime(
43+
{ width: 50, height: 100 },
44+
{ width: 100, height: 100 },
45+
{
46+
viewType: view as ViewType,
47+
cellSize: { width: 50, height: 50 },
48+
resizableStep: 50,
49+
cellDurationInMinutes: 30,
50+
isAllDay: true,
51+
},
52+
)).toBe(-24 * 3600_000);
53+
});
54+
});
55+
56+
['timelineMonth', 'month'].forEach((view) => {
57+
it(`should return correct delta in px for resized appointment in ${view} view`, () => {
58+
expect(getDeltaTime(
59+
{ width: 50, height: 100 },
60+
{ width: 100, height: 100 },
61+
{
62+
viewType: view as ViewType,
63+
cellSize: { width: 50, height: 50 },
64+
resizableStep: 50,
65+
cellDurationInMinutes: 30,
66+
isAllDay: false,
67+
},
68+
)).toBe(-24 * 3600_000);
69+
});
70+
});
71+
72+
['timelineDay', 'timelineWeek', 'timelineWorkWeek'].forEach((view) => {
73+
it(`should return zero for not resized appointment in horizontal ${view} view`, () => {
74+
expect(getDeltaTime(
75+
{ width: 50, height: 100 },
76+
{ width: 100, height: 100 },
77+
{
78+
viewType: view as ViewType,
79+
cellSize: { width: 50, height: 50 },
80+
resizableStep: 50,
81+
cellDurationInMinutes: 30,
82+
isAllDay: false,
83+
},
84+
)).toBe(-30 * 60_000);
85+
});
86+
});
87+
});

packages/devextreme/js/__internal/scheduler/appointments/resizing/get_delta_time.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import dateUtils from '@js/core/utils/date';
22

3-
import type { SafeAppointment, ViewType } from '../../types';
3+
import type { ViewType } from '../../types';
44

55
const toMs = dateUtils.dateToMilliseconds;
66
const VERTICAL_VIEW_TYPES = ['day', 'week', 'workWeek'];
@@ -14,7 +14,7 @@ interface Options {
1414
cellSize: Size;
1515
cellDurationInMinutes: number;
1616
resizableStep: number;
17-
isAllDay: (itemData: SafeAppointment) => boolean;
17+
isAllDay: boolean;
1818
}
1919

2020
const MIN_RESIZABLE_STEP = 2;
@@ -44,7 +44,6 @@ const getVerticalDeltaTime = (args: Size, initialSize: Size, {
4444
export const getDeltaTime = (
4545
args: Size,
4646
initialSize: Size,
47-
itemData: SafeAppointment,
4847
options: Options,
4948
): number => {
5049
const { viewType, resizableStep, isAllDay } = options;
@@ -53,10 +52,10 @@ export const getDeltaTime = (
5352
return getAllDayDeltaWidth(args, initialSize, resizableStep) * toMs('day');
5453
case viewType === 'agenda':
5554
return 0;
56-
case VERTICAL_VIEW_TYPES.includes(viewType) && !isAllDay(itemData):
55+
case VERTICAL_VIEW_TYPES.includes(viewType) && !isAllDay:
5756
return getVerticalDeltaTime(args, initialSize, options);
5857
default:
59-
return isAllDay(itemData)
58+
return isAllDay
6059
? getAllDayDeltaWidth(args, initialSize, resizableStep) * toMs('day')
6160
: getHorizontalDeltaTime(args, initialSize, options);
6261
}

packages/devextreme/js/__internal/scheduler/m_scheduler.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,8 +1301,6 @@ class Scheduler extends SchedulerOptionsBaseWidget {
13011301
if (currentViewOptions.startDate) {
13021302
this._updateOption('header', 'currentDate', this._workSpace._getHeaderDate());
13031303
}
1304-
1305-
this._appointments.option('_collectorOffset', this.getCollectorOffset());
13061304
}
13071305

13081306
_recalculateWorkspace() {

packages/devextreme/js/__internal/scheduler/m_subscribes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@ const subscribes = {
181181
},
182182

183183
getDeltaTime(e, initialSize, itemData) {
184-
return getDeltaTime(e, initialSize, itemData, {
184+
return getDeltaTime(e, initialSize, {
185185
viewType: this.currentView.type,
186186
cellSize: {
187187
width: this.getWorkSpace().getCellWidth(),
188188
height: this.getWorkSpace().getCellHeight(),
189189
},
190190
cellDurationInMinutes: this.getWorkSpace().option('cellDuration'),
191191
resizableStep: this.getWorkSpace().positionHelper.getResizableStep(),
192-
isAllDay: (appointmentData) => isAllDay(this, appointmentData),
192+
isAllDay: isAllDay(this, itemData),
193193
});
194194
},
195195

packages/devextreme/js/__internal/scheduler/view_model/generate_view_model/rendering_strategies/m_strategy_base.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@ class BaseRenderingStrategy {
132132
return coordinates;
133133
}
134134

135-
needCorrectAppointmentDates() {
136-
return true;
137-
}
138-
139135
getDirection() {
140136
return 'horizontal';
141137
}
@@ -636,7 +632,7 @@ class BaseRenderingStrategy {
636632
if ((coordinates.count - countFullWidthAppointmentInCell) > 0) {
637633
const { top, left } = coordinates;
638634
const compactRender = this.isAdaptive || !isAllDay && this.supportCompactDropDownAppointments();
639-
const width = this.getDropDownAppointmentWidth(this.intervalCount, isAllDay);
635+
const width = this.getDropDownAppointmentWidth(this.intervalCount, isAllDay) - this.options._collectorOffset;
640636
const height = this.getDropDownAppointmentHeight();
641637
const rtlOffset = this.rtlEnabled ? width : 0;
642638
coordinates.virtual = {
@@ -846,15 +842,6 @@ class BaseRenderingStrategy {
846842
return this._getAppointmentDefaultWidth();
847843
}
848844

849-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
850-
_needVerticalGroupBounds(allDay) {
851-
return false;
852-
}
853-
854-
_needHorizontalGroupBounds() {
855-
return false;
856-
}
857-
858845
getAppointmentDurationInMs(apptStartDate, apptEndDate, allDay) {
859846
if (allDay) {
860847
const appointmentDuration = apptEndDate.getTime() - apptStartDate.getTime();

packages/devextreme/js/__internal/scheduler/view_model/generate_view_model/rendering_strategies/m_strategy_horizontal_month.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,6 @@ class HorizontalMonthRenderingStrategy extends HorizontalMonthLineRenderingStrat
174174
const offset = intervalCount > 1 ? MONTH_DROPDOWN_APPOINTMENT_MAX_RIGHT_OFFSET : MONTH_DROPDOWN_APPOINTMENT_MIN_RIGHT_OFFSET;
175175
return this.cellWidth - offset;
176176
}
177-
178-
needCorrectAppointmentDates() {
179-
return false;
180-
}
181-
182-
_needVerticalGroupBounds() {
183-
return false;
184-
}
185-
186-
_needHorizontalGroupBounds() {
187-
return true;
188-
}
189177
}
190178

191179
export default HorizontalMonthRenderingStrategy;

packages/devextreme/js/__internal/scheduler/view_model/generate_view_model/rendering_strategies/m_strategy_horizontal_month_line.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ class HorizontalMonthLineRenderingStrategy extends HorizontalAppointmentsStrateg
6868
return result;
6969
}
7070

71-
needCorrectAppointmentDates() {
72-
return false;
73-
}
74-
7571
getPositionShift(timeShift) {
7672
return {
7773
top: 0,

packages/devextreme/js/__internal/scheduler/view_model/generate_view_model/rendering_strategies/m_strategy_vertical.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,6 @@ class VerticalRenderingStrategy extends BaseAppointmentsStrategy {
423423
return this.allDayHeight || this.getAppointmentMinSize();
424424
}
425425

426-
// eslint-disable-next-line class-methods-use-this
427-
_needVerticalGroupBounds(allDay) {
428-
return !allDay;
429-
}
430-
431-
_needHorizontalGroupBounds() {
432-
return false;
433-
}
434-
435426
getPositionShift(timeShift, isAllDay) {
436427
if (!isAllDay && this.isAdaptive && this._getMaxAppointmentCountPerCellByType(isAllDay) === 0) {
437428
return {

0 commit comments

Comments
 (0)