|
| 1 | +import { |
| 2 | + afterEach, beforeEach, describe, expect, it, |
| 3 | +} from '@jest/globals'; |
| 4 | +import $ from '@js/core/renderer'; |
| 5 | + |
| 6 | +import fx from '../../../common/core/animation/fx'; |
| 7 | +import CustomStore from '../../../data/custom_store'; |
| 8 | +import { createScheduler } from './__mock__/create_scheduler'; |
| 9 | +import { setupSchedulerTestEnvironment } from './__mock__/m_mock_scheduler'; |
| 10 | + |
| 11 | +const CLASSES = { |
| 12 | + scheduler: 'dx-scheduler', |
| 13 | + workSpace: 'dx-scheduler-work-space', |
| 14 | +}; |
| 15 | + |
| 16 | +describe('Workspace Recalculation with Async Templates (T661335)', () => { |
| 17 | + beforeEach(() => { |
| 18 | + fx.off = true; |
| 19 | + setupSchedulerTestEnvironment({ height: 600 }); |
| 20 | + }); |
| 21 | + |
| 22 | + afterEach(() => { |
| 23 | + const $scheduler = $(document.querySelector(`.${CLASSES.scheduler}`)); |
| 24 | + // @ts-expect-error |
| 25 | + $scheduler.dxScheduler('dispose'); |
| 26 | + document.body.innerHTML = ''; |
| 27 | + fx.off = false; |
| 28 | + }); |
| 29 | + |
| 30 | + it('should not duplicate workspace elements when resources are loaded asynchronously (T661335)', async () => { |
| 31 | + const { scheduler, container } = await createScheduler({ |
| 32 | + templatesRenderAsynchronously: true, |
| 33 | + currentView: 'day', |
| 34 | + views: ['day'], |
| 35 | + groups: ['owner'], |
| 36 | + resources: [ |
| 37 | + { |
| 38 | + fieldExpr: 'owner', |
| 39 | + dataSource: [{ id: 1, text: 'Owner 1' }], |
| 40 | + }, |
| 41 | + { |
| 42 | + fieldExpr: 'room', |
| 43 | + dataSource: new CustomStore({ |
| 44 | + load(): Promise<unknown> { |
| 45 | + return new Promise((resolve) => { |
| 46 | + setTimeout(() => { |
| 47 | + resolve([{ id: 1, text: 'Room 1', color: '#ff0000' }]); |
| 48 | + }); |
| 49 | + }); |
| 50 | + }, |
| 51 | + }), |
| 52 | + }, |
| 53 | + ], |
| 54 | + dataSource: [ |
| 55 | + { |
| 56 | + text: 'Meeting in Room 1', |
| 57 | + startDate: new Date(2017, 4, 25, 9, 0), |
| 58 | + endDate: new Date(2017, 4, 25, 10, 0), |
| 59 | + roomId: 1, |
| 60 | + }, |
| 61 | + ], |
| 62 | + startDayHour: 9, |
| 63 | + currentDate: new Date(2017, 4, 25), |
| 64 | + height: 600, |
| 65 | + }); |
| 66 | + |
| 67 | + scheduler.option('groups', ['room']); |
| 68 | + |
| 69 | + await new Promise((r) => { setTimeout(r); }); |
| 70 | + |
| 71 | + const $workSpaces = $(container).find(`.${CLASSES.workSpace}`); |
| 72 | + const $groupHeader = $(container).find('.dx-scheduler-group-header'); |
| 73 | + |
| 74 | + expect($workSpaces.length).toBe(1); |
| 75 | + |
| 76 | + expect($groupHeader.length).toBeGreaterThan(0); |
| 77 | + expect($groupHeader.text()).toContain('Room 1'); |
| 78 | + }); |
| 79 | +}); |
0 commit comments