|
| 1 | +import CardView from 'devextreme-testcafe-models/cardView'; |
| 2 | +import { createScreenshotsComparer } from 'devextreme-screenshot-comparer'; |
| 3 | +import { ClientFunction } from 'testcafe'; |
| 4 | +import url from '../../../helpers/getPageUrl'; |
| 5 | +import { createWidget } from '../../../helpers/createWidget'; |
| 6 | +import { testScreenshot } from '../../../helpers/themeUtils'; |
| 7 | + |
| 8 | +fixture.disablePageReloads`CardView - ContextMenu Behavior` |
| 9 | + .page(url(__dirname, '../../container.html')); |
| 10 | + |
| 11 | +test('Context menu should be shown at the mouse cursor', async (t) => { |
| 12 | + const cardView = new CardView('#container'); |
| 13 | + const { takeScreenshot, compareResults } = createScreenshotsComparer(t); |
| 14 | + |
| 15 | + await t |
| 16 | + .rightClick(cardView.getHeaders().getHeaderItemNth(0).element, { offsetX: -10, offsetY: -10 }); |
| 17 | + |
| 18 | + await testScreenshot(t, takeScreenshot, 'card-view_context-menu_mouse-click_position.png', { element: cardView.element }); |
| 19 | + |
| 20 | + await t |
| 21 | + .expect(compareResults.isValid()) |
| 22 | + .ok(compareResults.errorMessages()); |
| 23 | +}).before(async () => { |
| 24 | + await createWidget('dxCardView', { |
| 25 | + dataSource: [{ ID: 1 }], |
| 26 | + }); |
| 27 | +}); |
| 28 | + |
| 29 | +export const triggerCustomContextMenu = ClientFunction((selector) => { |
| 30 | + const element = selector() as Element; |
| 31 | + |
| 32 | + const rect = element.getBoundingClientRect(); |
| 33 | + const xPosition = rect.left + rect.width / 2; |
| 34 | + const yPosition = rect.top + rect.height / 2; |
| 35 | + |
| 36 | + const event = new MouseEvent('contextmenu'); |
| 37 | + /* |
| 38 | + Note: By default, TestCafe sets the pageX and pageY properties of MouseEvent to 0. |
| 39 | + There is no supported way to define custom pageX and pageY values for the contextmenu event. |
| 40 | + Additionally, TestCafe does not support system keys, so triggering combinations like Shift+F10 |
| 41 | + or the Context Menu key is not possible. |
| 42 | + */ |
| 43 | + Object.defineProperty(event, 'pageX', { value: xPosition }); |
| 44 | + Object.defineProperty(event, 'pageY', { value: yPosition }); |
| 45 | + |
| 46 | + element.dispatchEvent(event as any); |
| 47 | +}); |
| 48 | + |
| 49 | +test('Context menu should be shown at center of the header item if shown with the keyboard', async (t) => { |
| 50 | + const cardView = new CardView('#container'); |
| 51 | + const { takeScreenshot, compareResults } = createScreenshotsComparer(t); |
| 52 | + |
| 53 | + await triggerCustomContextMenu(cardView.getHeaders().getHeaderItemNth(0).element); |
| 54 | + await testScreenshot(t, takeScreenshot, 'card-view_context-menu_keyboard_position.png', { element: cardView.element }); |
| 55 | + |
| 56 | + await t |
| 57 | + .expect(compareResults.isValid()) |
| 58 | + .ok(compareResults.errorMessages()); |
| 59 | +}).before(async () => { |
| 60 | + await createWidget('dxCardView', { |
| 61 | + dataSource: [{ ID: 1 }], |
| 62 | + }); |
| 63 | +}); |
0 commit comments