|
1 | 1 | import { |
2 | 2 | afterEach, beforeEach, describe, expect, it, jest, |
3 | 3 | } from '@jest/globals'; |
| 4 | +import { CustomStore } from '@js/common/data/custom_store'; |
4 | 5 | import $ from '@js/core/renderer'; |
5 | 6 | import type { GroupItem, Item as FormItem } from '@js/ui/form'; |
6 | 7 | import type { ToolbarItem } from '@js/ui/popup'; |
@@ -297,6 +298,38 @@ describe('Appointment Form', () => { |
297 | 298 |
|
298 | 299 | expect(dataSource.items()[0].roomId).toBe(2); |
299 | 300 | }); |
| 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 | + }); |
300 | 333 | }); |
301 | 334 |
|
302 | 335 | describe('Validation', () => { |
@@ -752,6 +785,38 @@ describe('Appointment Form', () => { |
752 | 785 | expect(customFieldValue).toBe('FREQ=DAILY'); |
753 | 786 | expect(defaultFieldValue).toBeUndefined(); |
754 | 787 | }); |
| 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 | + }); |
755 | 820 | }); |
756 | 821 |
|
757 | 822 | describe('allDay switch', () => { |
@@ -906,7 +971,7 @@ describe('Appointment Form', () => { |
906 | 971 | }); |
907 | 972 | }); |
908 | 973 |
|
909 | | - describe('Timezones', () => { |
| 974 | + describe('Timezone Editors', () => { |
910 | 975 | it('should have correct timezone editors values', async () => { |
911 | 976 | const { scheduler, POM } = await createScheduler({ |
912 | 977 | ...getDefaultConfig(), |
@@ -1130,6 +1195,93 @@ describe('Appointment Form', () => { |
1130 | 1195 | ]), |
1131 | 1196 | ); |
1132 | 1197 | }); |
| 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 | + }); |
1133 | 1285 | }); |
1134 | 1286 |
|
1135 | 1287 | describe('Recurrence Form', () => { |
|
0 commit comments