|
1 | | -export function createDrawer({ |
2 | | - openedStateMode, shading, createOuterContent, createDrawerContent, createInnerContent, |
3 | | -}: { [key: string]: any }): void { |
4 | | - function createDrawerInt($container: any): void { |
| 1 | +import { ClientFunction } from 'testcafe'; |
| 2 | +import { Properties } from 'devextreme/ui/drawer'; |
| 3 | + |
| 4 | +interface CreateDrawerConfig { |
| 5 | + options?: Properties; |
| 6 | + createDrawerContent?: ($drawerContent: JQuery) => void; |
| 7 | + createOuterContent?: ($container: JQuery) => void; |
| 8 | + testInPopup?: boolean; |
| 9 | +} |
| 10 | + |
| 11 | +export const createDrawer = ClientFunction(({ |
| 12 | + options = {}, |
| 13 | + createDrawerContent, |
| 14 | + createOuterContent, |
| 15 | + testInPopup = false, |
| 16 | +}: CreateDrawerConfig) => { |
| 17 | + const createDrawerInt = ($container: JQuery) => { |
5 | 18 | if (createOuterContent) { |
6 | 19 | createOuterContent($container); |
7 | 20 | } |
8 | 21 |
|
9 | | - const $drawer = $('<div id=\'drawer1\'>'); |
10 | | - const $templateView = $('<div style=\'background-color: aquamarine; height: 100%;\'>').appendTo($drawer); |
11 | | - if (openedStateMode === 'overlap') { |
12 | | - $templateView.css('padding-left', '200px'); |
13 | | - } |
14 | | - if (openedStateMode === 'push') { |
15 | | - $templateView.css('padding-right', '200px'); |
16 | | - } |
| 22 | + const $drawer = $('<div id="drawer">'); |
| 23 | + const $templateView = $('<div style="background-color: aquamarine; height: 100%;">').appendTo($drawer); |
17 | 24 |
|
18 | | - if (createInnerContent) { |
19 | | - createInnerContent($templateView); |
20 | | - } |
| 25 | + $('<div id="inner">') |
| 26 | + .text('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Penatibus et magnis dis parturient. Eget dolor morbi non arcu risus. Tristique magna sit amet purus gravida quis blandit. Auctor urna nunc id cursus metus aliquam eleifend mi in.') |
| 27 | + .appendTo($templateView); |
21 | 28 |
|
22 | 29 | ($drawer.appendTo($container) as any).dxDrawer({ |
23 | | - openedStateMode, |
24 | | - shading, |
25 | 30 | opened: true, |
| 31 | + shading: true, |
26 | 32 | height: 400, |
27 | 33 | template: () => { |
28 | | - const $result = $('<div>').width('200px').css('background-color', 'aqua').css('height', '100%'); |
| 34 | + const isTopOrBottom = options.position === 'top' || options.position === 'bottom'; |
| 35 | + const cssSizeProperty = isTopOrBottom ? 'width' : 'height'; |
| 36 | + |
| 37 | + const $result = $('<div>') |
| 38 | + .css('background-color', 'aqua') |
| 39 | + .css(cssSizeProperty, '100%'); |
| 40 | + |
| 41 | + if (isTopOrBottom) { |
| 42 | + $result.height('100px'); |
| 43 | + } else { |
| 44 | + $result.width('200px'); |
| 45 | + } |
| 46 | + |
29 | 47 | if (createDrawerContent) { |
30 | 48 | createDrawerContent($result); |
| 49 | + } else { |
| 50 | + $('<div>').text('Drawer Content').appendTo($result); |
31 | 51 | } |
| 52 | + |
32 | 53 | return $result; |
33 | 54 | }, |
| 55 | + ...options, |
34 | 56 | }); |
35 | | - } |
| 57 | + }; |
36 | 58 |
|
37 | | - ($('<div id="showPopupBtn">').appendTo($('#container')) as any) |
38 | | - .dxButton({ |
| 59 | + if (testInPopup) { |
| 60 | + ($('<div id="showPopupBtn">').appendTo($('#container')) as any).dxButton({ |
39 | 61 | text: 'Show Popup', |
40 | 62 | onClick: () => ($('#popup1') as any).dxPopup('instance').show(), |
41 | 63 | }); |
42 | | - ($('<div id=\'popup1\'>').appendTo($('#container')) as any).dxPopup({ |
43 | | - position: 'top', |
44 | | - height: 600, |
45 | | - showTitle: false, |
46 | | - contentTemplate: () => { |
47 | | - const $popupTemplate = $('<div id="popup1_template">').css('background-color', 'blanchedalmond').css('height', '100%'); |
48 | | - createDrawerInt($popupTemplate); |
49 | | - return $popupTemplate; |
50 | | - }, |
51 | | - }); |
| 64 | + |
| 65 | + ($('<div id="popup1">').appendTo($('#container')) as any).dxPopup({ |
| 66 | + position: 'top', |
| 67 | + height: 600, |
| 68 | + showTitle: false, |
| 69 | + contentTemplate: () => { |
| 70 | + const $popupTemplate = $('<div id="popup1_template">').css('background-color', 'blanchedalmond').css('height', '100%'); |
| 71 | + createDrawerInt($popupTemplate); |
| 72 | + return $popupTemplate; |
| 73 | + }, |
| 74 | + }); |
| 75 | + } |
52 | 76 |
|
53 | 77 | createDrawerInt($('#container')); |
54 | | -} |
| 78 | +}); |
0 commit comments