|
| 1 | +import { createScreenshotsComparer } from 'devextreme-screenshot-comparer'; |
| 2 | +import { Item } from 'devextreme/ui/menu.d'; |
| 3 | +import Menu from 'devextreme-testcafe-models/menu'; |
| 4 | +import { appendElementTo, setAttribute } from '../../../helpers/domUtils'; |
| 5 | +import { testScreenshot } from '../../../helpers/themeUtils'; |
| 6 | +import url from '../../../helpers/getPageUrl'; |
| 7 | +import { createWidget } from '../../../helpers/createWidget'; |
| 8 | +import { safeSizeTest } from '../../../helpers/safeSizeTest'; |
| 9 | + |
| 10 | +fixture.disablePageReloads`Menu_common` |
| 11 | + .page(url(__dirname, '../../container.html')); |
| 12 | + |
| 13 | +const items: Item[] = [ |
| 14 | + { text: 'Category 1' }, |
| 15 | + { |
| 16 | + text: 'Category 2', |
| 17 | + items: [ |
| 18 | + { text: 'Item long name 2-1' }, |
| 19 | + { text: 'Item long name 2-2' }, |
| 20 | + ], |
| 21 | + }, |
| 22 | + { |
| 23 | + text: 'Category 3', |
| 24 | + items: [ |
| 25 | + { text: 'Item 1' }, |
| 26 | + { text: 'Item 2' }, |
| 27 | + ], |
| 28 | + }, |
| 29 | + { |
| 30 | + text: 'Category 4', |
| 31 | + items: [ |
| 32 | + { text: 'Item long name 4-1' }, |
| 33 | + { text: 'Item long name 4-2' }, |
| 34 | + ], |
| 35 | + }, |
| 36 | +]; |
| 37 | + |
| 38 | +['horizontal', 'vertical'].forEach((orientation) => { |
| 39 | + const testName = `Menu delimiter, orientation=${orientation}`; |
| 40 | + safeSizeTest(testName, async (t) => { |
| 41 | + const { takeScreenshot, compareResults } = createScreenshotsComparer(t); |
| 42 | + const menu = new Menu(); |
| 43 | + |
| 44 | + await t |
| 45 | + .click(menu.getItem(2)) |
| 46 | + .pressKey('down'); |
| 47 | + |
| 48 | + await testScreenshot(t, takeScreenshot, `${testName}.png`); |
| 49 | + |
| 50 | + if (orientation === 'horizontal') { |
| 51 | + await t |
| 52 | + .click(menu.getItem(1)) |
| 53 | + .pressKey('down'); |
| 54 | + |
| 55 | + await testScreenshot(t, takeScreenshot, `${testName}, wide submenu.png`); |
| 56 | + } |
| 57 | + |
| 58 | + await t |
| 59 | + .expect(compareResults.isValid()) |
| 60 | + .ok(compareResults.errorMessages()); |
| 61 | + }, [500, 500]).before(() => createWidget( |
| 62 | + 'dxMenu', |
| 63 | + { |
| 64 | + items, |
| 65 | + orientation, |
| 66 | + }, |
| 67 | + '#container', |
| 68 | + )); |
| 69 | +}); |
| 70 | + |
| 71 | +['horizontal', 'vertical'].forEach((orientation) => { |
| 72 | + ['bottom', 'right', 'bottom right'].forEach((collision) => { |
| 73 | + const testName = `Menu delimiter ${collision} collision, orientation=${orientation}`; |
| 74 | + safeSizeTest(testName, async (t) => { |
| 75 | + const { takeScreenshot, compareResults } = createScreenshotsComparer(t); |
| 76 | + const menu = new Menu(); |
| 77 | + |
| 78 | + await t.click(menu.getItem(3)); |
| 79 | + |
| 80 | + await testScreenshot(t, takeScreenshot, `${testName}.png`); |
| 81 | + |
| 82 | + await t |
| 83 | + .expect(compareResults.isValid()) |
| 84 | + .ok(compareResults.errorMessages()); |
| 85 | + }, [515, 515]).before(async () => { |
| 86 | + await appendElementTo('#container', 'div', 'menu'); |
| 87 | + const additionalStyles = { |
| 88 | + bottom: 'justify-content: start;', |
| 89 | + right: 'align-content: start;', |
| 90 | + }; |
| 91 | + await setAttribute('#container', 'style', `width: 500px; height: 500px; display: grid; ${additionalStyles[collision] ?? ''}`); |
| 92 | + |
| 93 | + await createWidget( |
| 94 | + 'dxMenu', |
| 95 | + { |
| 96 | + elementAttr: { |
| 97 | + style: 'align-self: end; justify-self: end;', |
| 98 | + }, |
| 99 | + items, |
| 100 | + orientation, |
| 101 | + }, |
| 102 | + '#menu', |
| 103 | + ); |
| 104 | + }); |
| 105 | + }); |
| 106 | +}); |
| 107 | + |
| 108 | +safeSizeTest('Menu delimiter appearance when the Menu is used as a toolbar item', async (t) => { |
| 109 | + const { takeScreenshot, compareResults } = createScreenshotsComparer(t); |
| 110 | + const menu = new Menu(); |
| 111 | + |
| 112 | + await t.click(menu.getItem(1)); |
| 113 | + |
| 114 | + await testScreenshot(t, takeScreenshot, 'Menu delimiter, menu as toolbar item.png'); |
| 115 | + |
| 116 | + await t |
| 117 | + .expect(compareResults.isValid()) |
| 118 | + .ok(compareResults.errorMessages()); |
| 119 | +}, [500, 500]).before(async () => { |
| 120 | + const toolbarItems = [ |
| 121 | + { |
| 122 | + location: 'before', |
| 123 | + widget: 'dxMenu', |
| 124 | + options: { |
| 125 | + items: [{ |
| 126 | + text: 'Video Players', |
| 127 | + }, { |
| 128 | + text: 'Televisions', |
| 129 | + items: [{ |
| 130 | + id: '2_1', |
| 131 | + text: 'SuperLCD 42', |
| 132 | + }, { |
| 133 | + id: '2_2', |
| 134 | + text: 'SuperLED 42', |
| 135 | + }], |
| 136 | + }], |
| 137 | + }, |
| 138 | + }, { |
| 139 | + location: 'before', |
| 140 | + widget: 'dxButton', |
| 141 | + options: { |
| 142 | + icon: 'undo', |
| 143 | + }, |
| 144 | + }, { |
| 145 | + location: 'before', |
| 146 | + widget: 'dxButton', |
| 147 | + options: { |
| 148 | + icon: 'redo', |
| 149 | + }, |
| 150 | + }, |
| 151 | + ]; |
| 152 | + |
| 153 | + return createWidget('dxToolbar', { |
| 154 | + items: toolbarItems, |
| 155 | + width: '100%', |
| 156 | + }, '#container'); |
| 157 | +}); |
0 commit comments