Skip to content
Merged
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
@@ -1,8 +1,13 @@
import { within } from '@testing-library/dom';

export class PopupModel {
element: HTMLDivElement;

private readonly queries: ReturnType<typeof within>;

constructor(element: HTMLDivElement) {
this.element = element;
this.queries = within(element);
}

getLabelIdByText = (labelText: string): string => {
Expand Down Expand Up @@ -104,27 +109,25 @@ export class PopupModel {

getDoneButton = (): HTMLButtonElement => {
const doneButton = this.element.querySelector('.dx-button.dx-popup-done') as HTMLButtonElement;

if (!doneButton) {
throw new Error('Done button not found');
}

return doneButton;
};

getCancelButton = (): HTMLButtonElement => {
const cancelButton = this.element.querySelector('.dx-button.dx-popup-cancel') as HTMLButtonElement;

if (!cancelButton) {
throw new Error('Cancel button not found');
}

return cancelButton;
};

getCloseButton = (): HTMLButtonElement => {
const closeButton = this.element.querySelector('.dx-closebutton.dx-button') as HTMLButtonElement;
if (!closeButton) {
throw new Error('Close button not found');
}
return closeButton;
};
getCloseButton = (): HTMLButtonElement => this.queries.getByRole('button', { name: 'Close' }) as HTMLButtonElement;

getFormEditor = (fieldName: string): HTMLElement | null => {
const form = this.getForm();
Expand All @@ -134,11 +137,5 @@ export class PopupModel {
return form.querySelector(`[data-field="${fieldName}"]`);
};

getEditSeriesButton = (): HTMLElement => {
const editSeriesButton = document.querySelector('[aria-label="Edit series"]') as HTMLElement;
if (!editSeriesButton) {
throw new Error('Edit series button not found');
}
return editSeriesButton;
};
getEditSeriesButton = (): HTMLElement => this.queries.getByRole('button', { name: 'Edit series' }) as HTMLElement;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { within } from '@testing-library/dom';
import { ToolbarModel } from '@ts/scheduler/__tests__/__mock__/model/toolbar';

import { APPOINTMENT_POPUP_CLASS } from '../../../appointment_popup/m_popup';
Expand All @@ -7,40 +8,51 @@ import { createAppointmentModel } from './appointment';
import { PopupModel } from './popup';

const getTexts = (
cells: NodeListOf<Element>,
cells: ArrayLike<Element>,
): string[] => Array.from(cells).map((cell) => cell.textContent?.trim() ?? '');

export class SchedulerModel {
container: HTMLDivElement;

private readonly queries: ReturnType<typeof within>;

constructor(container: HTMLDivElement) {
this.container = container;
this.queries = within(container);
}

get popup(): PopupModel {
return this.getPopup();
}

get toolbar(): ToolbarModel {
return new ToolbarModel(this.container.querySelector('.dx-scheduler-header'));
return new ToolbarModel(this.queries.getByRole('toolbar'));
}

getStatusContent(): string {
return this.container.querySelector('.dx-scheduler-a11y-status-container')?.textContent ?? '';
const statusElement = this.container.querySelector('.dx-scheduler-a11y-status-container');
return statusElement?.textContent ?? '';
}

getAppointment(text?: string): AppointmentModel<HTMLDivElement | null> {
if (!text) {
return createAppointmentModel(this.container.querySelector('.dx-scheduler-appointment'));
const appointments = this.getAppointments();
return appointments.length > 0 ? appointments[0] : createAppointmentModel(null);
}
return this.getAppointments()
.find((appointment) => appointment.getText() === text) ?? createAppointmentModel(null);
}

getAppointments(): AppointmentModel[] {
return [...this.container.querySelectorAll('.dx-scheduler-appointment')].map(
(element) => createAppointmentModel(element as HTMLDivElement),
);
const allButtons = this.queries.queryAllByRole('button') as HTMLElement[];
const appointments = allButtons.filter((btn) => btn.classList.contains('dx-scheduler-appointment'));
return appointments.map((element) => createAppointmentModel(element as HTMLDivElement));
}

getCollectorTexts(): string[] {
const allButtons = this.queries.queryAllByRole('button') as HTMLElement[];
const collectors = allButtons.filter((btn) => btn.classList.contains('dx-scheduler-appointment-collector'));
return getTexts(collectors);
}

getDateTableContent(): string[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { within } from '@testing-library/dom';

export class ToolbarModel {
element: HTMLDivElement | null;
element: HTMLElement;

private readonly queries: ReturnType<typeof within>;

constructor(element: HTMLDivElement | null) {
constructor(element: HTMLElement) {
this.element = element;
this.queries = within(element);
}

getPrevButton(): HTMLDivElement | null | undefined {
return this.element?.querySelector('.dx-scheduler-navigator-previous');
getPrevButton(): HTMLElement {
return this.queries.getByRole('button', { name: 'Previous page' }) as HTMLElement;
}

getNextButton(): HTMLDivElement | null | undefined {
return this.element?.querySelector('.dx-scheduler-navigator-next');
getNextButton(): HTMLElement {
return this.queries.getByRole('button', { name: 'Next page' }) as HTMLElement;
}
}
3 changes: 3 additions & 0 deletions packages/devextreme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
"@jest/globals": "29.7.0",
"@stylistic/eslint-plugin": "catalog:",
"@testcafe-community/axe": "3.5.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/user-event": "^14.5.2",
"@types/enzyme": "3.10.18",
"@types/jquery": "3.5.29",
"@types/react": "16.14.34",
Expand Down
29 changes: 19 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading