Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1388,53 +1388,6 @@ describe('Appointment Form', () => {
});
});
});

describe('Customization', () => {
it('should propagate editing.form options to the form instance', async () => {
const { scheduler, POM } = await createScheduler({
...getDefaultConfig(),
editing: {
allowAdding: true,
allowUpdating: true,
form: {
height: 500,
},
},
});

scheduler.showAppointmentPopup(commonAppointment);

const { dxForm: form } = POM.popup;
const formHeight = form.option('height') as number;

expect(formHeight).toBe(500);
});

it('should merge editing.form options with default form configuration', async () => {
const { scheduler, POM } = await createScheduler({
...getDefaultConfig(),
editing: {
allowAdding: true,
allowUpdating: true,
form: {
height: 500,
elementAttr: { id: 'custom-form' },
},
},
});

scheduler.showAppointmentPopup(commonAppointment);

const { dxForm: form } = POM.popup;
const formHeight = form.option('height') as number;
const elementAttr = form.option('elementAttr') as { class?: string; id?: string };
const { class: className, id } = elementAttr;

expect(formHeight).toBe(500);
expect(className).toBe('dx-scheduler-form');
expect(id).toBe('custom-form');
});
});
});

describe('Appointment Popup', () => {
Expand Down Expand Up @@ -1628,214 +1581,6 @@ describe('Appointment Popup', () => {
});

describe('Customization', () => {
it('should pass custom popup options from editing.popup to appointment popup', async () => {
const { scheduler, POM } = await createScheduler({
...getDefaultConfig(),
editing: {
allowAdding: true,
allowUpdating: true,
popup: {
showTitle: true,
title: 'Custom Appointment Form',
maxHeight: '80%',
dragEnabled: true,
},
},
});

scheduler.showAppointmentPopup(commonAppointment);

expect(POM.popup.component.option('showTitle')).toBe(true);
expect(POM.popup.component.option('title')).toBe('Custom Appointment Form');
expect(POM.popup.component.option('maxHeight')).toBe('80%');
expect(POM.popup.component.option('dragEnabled')).toBe(true);
});

it('should use default popup options when editing.popup is not specified', async () => {
const { scheduler, POM } = await createScheduler({
...getDefaultConfig(),
editing: {
allowAdding: true,
allowUpdating: true,
},
});

scheduler.showAppointmentPopup(commonAppointment);

expect(POM.popup.component.option('showTitle')).toBe(false);
expect(POM.popup.component.option('height')).toBe('auto');
expect(POM.popup.component.option('maxHeight')).toBe('90%');
});

it('should merge custom popup options with default options', async () => {
const { scheduler, POM } = await createScheduler({
...getDefaultConfig(),
editing: {
allowAdding: true,
allowUpdating: true,
popup: {
showTitle: true,
title: 'My Form',
},
},
});

scheduler.showAppointmentPopup(commonAppointment);

expect(POM.popup.component.option('showTitle')).toBe(true);
expect(POM.popup.component.option('title')).toBe('My Form');

expect(POM.popup.component.option('showCloseButton')).toBe(false);
expect(POM.popup.component.option('enableBodyScroll')).toBe(false);
expect(POM.popup.component.option('preventScrollEvents')).toBe(false);
});

it('should allow overriding default popup options', async () => {
const { scheduler, POM } = await createScheduler({
...getDefaultConfig(),
editing: {
allowAdding: true,
allowUpdating: true,
popup: {
showCloseButton: true,
enableBodyScroll: true,
},
},
});

scheduler.showAppointmentPopup(commonAppointment);

expect(POM.popup.component.option('showCloseButton')).toBe(true);
expect(POM.popup.component.option('enableBodyScroll')).toBe(true);
});

it('should apply wrapperAttr configuration to popup', async () => {
const { scheduler, POM } = await createScheduler({
...getDefaultConfig(),
editing: {
allowAdding: true,
allowUpdating: true,
popup: {
wrapperAttr: {
id: 'test',
},
},
},
});

scheduler.showAppointmentPopup(commonAppointment);

const wrapperAttr = POM.popup.component.option('wrapperAttr');
expect(wrapperAttr.id).toBe('test');
expect(wrapperAttr.class).toBeDefined();
});

it('should call onInitialized callback when popup is initialized', async () => {
const onInitialized = jest.fn();
const { scheduler, POM } = await createScheduler({
...getDefaultConfig(),
editing: {
allowAdding: true,
allowUpdating: true,
popup: {
onInitialized,
},
},
});

scheduler.showAppointmentPopup(commonAppointment);

expect(POM.isPopupVisible()).toBe(true);
expect(onInitialized).toHaveBeenCalled();
expect(onInitialized).toHaveBeenCalledTimes(1);
});

it('should call onShowing callback when popup is shown', async () => {
const onShowing = jest.fn();
const onAppointmentFormOpening = jest.fn();
const { scheduler } = await createScheduler({
...getDefaultConfig(),
editing: {
allowAdding: true,
allowUpdating: true,
popup: {
onShowing,
},
},
onAppointmentFormOpening,
});

scheduler.showAppointmentPopup(commonAppointment);

expect(onShowing).toHaveBeenCalled();
expect(onShowing).toHaveBeenCalledTimes(1);
expect(onAppointmentFormOpening).toHaveBeenCalled();
expect(onAppointmentFormOpening).toHaveBeenCalledTimes(1);
});

it('should call onHiding callback when popup is hidden', async () => {
const onHiding = jest.fn();
const { scheduler } = await createScheduler({
...getDefaultConfig(),
editing: {
allowAdding: true,
allowUpdating: true,
popup: {
onHiding,
},
},
});

const focusSpy = jest.spyOn(scheduler, 'focus');

scheduler.showAppointmentPopup(commonAppointment);

expect(onHiding).not.toHaveBeenCalled();
expect(focusSpy).not.toHaveBeenCalled();

scheduler.hideAppointmentPopup();

expect(onHiding).toHaveBeenCalled();
expect(onHiding).toHaveBeenCalledTimes(1);
expect(focusSpy).toHaveBeenCalled();
expect(focusSpy).toHaveBeenCalledTimes(1);

focusSpy.mockRestore();
});

it('should preserve custom toolbarItems when popup opens', async () => {
const { scheduler, POM } = await createScheduler({
...getDefaultConfig(),
editing: {
popup: {
toolbarItems: [{
toolbar: 'top', location: 'before', text: 'Custom Title', cssClass: 'custom-title',
}, {
toolbar: 'top', location: 'after', widget: 'dxButton', options: { text: 'Custom Save' },
}],
},
},
});

scheduler.showAppointmentPopup(commonAppointment);

const toolbarItems = POM.popup.component.option('toolbarItems');

expect(toolbarItems).toBeDefined();
expect(toolbarItems).toHaveLength(2);
expect(toolbarItems).toContainEqual(expect.objectContaining({
cssClass: 'custom-title', location: 'before', text: 'Custom Title', toolbar: 'top',
}));
expect(toolbarItems).toContainEqual(expect.objectContaining(
{
toolbar: 'top',
location: 'after',
widget: 'dxButton',
options: expect.objectContaining({ text: 'Custom Save' }),
},
));
});

it('should preserve custom toolbarItems when popup is reopened', async () => {
const { scheduler, POM } = await createScheduler({
...getDefaultConfig(),
Expand All @@ -1857,93 +1602,6 @@ describe('Appointment Popup', () => {
expect(toolbarItems).toHaveLength(1);
expect(toolbarItems?.[0]?.text).toBe('Custom Toolbar');
});

it('should open popup if popup.deferRendering is false', async () => {
const { scheduler, POM } = await createScheduler({
...getDefaultConfig(),
editing: {
allowAdding: true,
allowUpdating: true,
popup: {
deferRendering: false,
},
},
});

scheduler.showAppointmentPopup(commonAppointment);

expect(POM.isPopupVisible()).toBe(true);
});

describe('Popup width and maxWidth options', () => {
// Mock window width to avoid fullscreen mode
beforeEach(() => {
Object.defineProperty(document.documentElement, 'clientWidth', {
value: 1280,
});
});

it('should use custom maxWidth when specified', async () => {
const { scheduler, POM } = await createScheduler({
...getDefaultConfig(),
editing: {
allowAdding: true,
allowUpdating: true,
popup: {
maxWidth: 500,
},
},
});

scheduler.showAppointmentPopup(commonAppointment);

const maxWidth = POM.popup.component.option('maxWidth');
expect(maxWidth).toBe(500);
});

it('should use custom width as maxWidth when maxWidth is not specified', async () => {
const { scheduler, POM } = await createScheduler({
...getDefaultConfig(),
editing: {
allowAdding: true,
allowUpdating: true,
popup: {
width: 600,
},
},
});

scheduler.showAppointmentPopup(commonAppointment);

const width = POM.popup.component.option('width');
expect(width).toBe(600);

const maxWidth = POM.popup.component.option('maxWidth');
expect(maxWidth).toBe(600);
});

it('should use maxWidth option value (not width) for maxWidth when both maxWidth and width are specified', async () => {
const { scheduler, POM } = await createScheduler({
...getDefaultConfig(),
editing: {
allowAdding: true,
allowUpdating: true,
popup: {
width: 600,
maxWidth: 500,
},
},
});

scheduler.showAppointmentPopup(commonAppointment);

const width = POM.popup.component.option('width');
expect(width).toBe(600);

const maxWidth = POM.popup.component.option('maxWidth');
expect(maxWidth).toBe(500);
});
});
});
});

Expand Down
Loading
Loading