11import $ from 'jquery' ;
22import FileUploader from 'ui/file_uploader' ;
3+ import 'ui/drop_down_button' ;
4+ import 'ui/button_group' ;
35import devices from 'core/devices' ;
46import { Deferred } from 'core/utils/deferred' ;
57import keyboardMock from '../../helpers/keyboardMock.js' ;
@@ -20,6 +22,7 @@ QUnit.testStart(function() {
2022const internals = FileUploader . __internals ;
2123
2224const FILEUPLOADER_EMPTY_CLASS = 'dx-fileuploader-empty' ;
25+ const FILEUPLOADER_INVALID_CLASS = 'dx-fileuploader-invalid' ;
2326
2427const FILEUPLOADER_CONTENT_CLASS = 'dx-fileuploader-content' ;
2528const FILEUPLOADER_INPUT_WRAPPER_CLASS = 'dx-fileuploader-input-wrapper' ;
@@ -38,7 +41,7 @@ const FILEUPLOADER_CANCEL_BUTTON_CLASS = 'dx-fileuploader-cancel-button';
3841const FILEUPLOADER_UPLOAD_BUTTON_CLASS = 'dx-fileuploader-upload-button' ;
3942const FILEUPLOADER_FILE_STATUS_MESSAGE_CLASS = 'dx-fileuploader-file-status-message' ;
4043
41- const FILEUPLOADER_INVALID_CLASS = 'dx-fileuploader-invalid ' ;
44+ const BUTTON_GROUP_CLASS = 'dx-buttongroup ' ;
4245
4346const FILEUPLOADER_AFTER_LOAD_DELAY = 500 ;
4447
@@ -836,16 +839,16 @@ QUnit.module('custom uploading', moduleConfig, () => {
836839
837840 QUnit . test ( 'set custom dialog trigger attaches click event handler on targets' , function ( assert ) {
838841 const instance = $ ( '#fileuploader' ) . dxFileUploader ( ) . dxFileUploader ( 'instance' ) ;
839- sinon . stub ( instance , '_attachSelectFileDialogHandler ' ) ;
842+ sinon . stub ( instance , '_attachSelectFileDialogHandlers ' ) ;
840843
841844 instance . option ( 'dialogTrigger' , '.pic' ) ;
842845
843- assert . strictEqual ( instance . _attachSelectFileDialogHandler . callCount , 1 , 'attachHandlers method called' ) ;
844- const items = instance . _attachSelectFileDialogHandler . args [ 0 ] ;
846+ assert . strictEqual ( instance . _attachSelectFileDialogHandlers . callCount , 1 , 'attachHandlers method called' ) ;
847+ const items = instance . _attachSelectFileDialogHandlers . args [ 0 ] ;
845848 assert . strictEqual ( items . length , 1 , 'attachHandlers args is valid' ) ;
846849 assert . strictEqual ( items [ 0 ] , '.pic' , 'attachHandlers args is valid' ) ;
847850
848- instance . _attachSelectFileDialogHandler . restore ( ) ;
851+ instance . _attachSelectFileDialogHandlers . restore ( ) ;
849852 } ) ;
850853
851854 QUnit . test ( 'it is possible to drop files using custom dropzone' , function ( assert ) {
@@ -2039,8 +2042,8 @@ QUnit.module('option change', moduleConfig, () => {
20392042 const customDropZone = $ ( '<div>' ) . addClass ( 'dropZone' ) . appendTo ( '#qunit-fixture' ) ;
20402043 const customDialogTrigger = $ ( '<div>' ) . addClass ( 'trigger' ) . appendTo ( '#qunit-fixture' ) ;
20412044 const instance = $ ( '#fileuploader' ) . dxFileUploader ( ) . dxFileUploader ( 'instance' ) ;
2042- sinon . stub ( instance , '_attachSelectFileDialogHandler ' ) ;
2043- sinon . stub ( instance , '_detachSelectFileDialogHandler ' ) ;
2045+ sinon . stub ( instance , '_attachSelectFileDialogHandlers ' ) ;
2046+ sinon . stub ( instance , '_detachSelectFileDialogHandlers ' ) ;
20442047 sinon . stub ( instance , '_attachDragEventHandlers' ) ;
20452048 sinon . stub ( instance , '_detachDragEventHandlers' ) ;
20462049
@@ -2050,13 +2053,13 @@ QUnit.module('option change', moduleConfig, () => {
20502053 dropZone : '.dropZone'
20512054 } ) ;
20522055 this . clock . tick ( 100 ) ;
2053- instance . _detachSelectFileDialogHandler . reset ( ) ;
2056+ instance . _detachSelectFileDialogHandlers . reset ( ) ;
20542057 instance . _detachDragEventHandlers . reset ( ) ;
20552058
2056- assert . ok ( instance . _attachSelectFileDialogHandler . callCount >= 1 , '_attachSelectFileDialogHandler method called' ) ;
2057- let items = instance . _attachSelectFileDialogHandler . args [ 0 ] ;
2058- assert . strictEqual ( items . length , 1 , '_attachSelectFileDialogHandler args is valid' ) ;
2059- assert . strictEqual ( items [ 0 ] , '.trigger' , '_attachSelectFileDialogHandler args is valid' ) ;
2059+ assert . ok ( instance . _attachSelectFileDialogHandlers . callCount >= 1 , '_attachSelectFileDialogHandlers method called' ) ;
2060+ let items = instance . _attachSelectFileDialogHandlers . args [ 0 ] ;
2061+ assert . strictEqual ( items . length , 1 , '_attachSelectFileDialogHandlers args is valid' ) ;
2062+ assert . strictEqual ( items [ 0 ] , '.trigger' , '_attachSelectFileDialogHandlers args is valid' ) ;
20602063
20612064 assert . ok ( instance . _attachDragEventHandlers . callCount >= 1 , '_attachDragEventHandlers method called' ) ;
20622065 items = instance . _attachDragEventHandlers . args [ 0 ] ;
@@ -2065,18 +2068,18 @@ QUnit.module('option change', moduleConfig, () => {
20652068
20662069 instance . dispose ( ) ;
20672070
2068- assert . strictEqual ( instance . _detachSelectFileDialogHandler . callCount , 1 , '_detachSelectFileDialogHandler method called' ) ;
2069- items = instance . _detachSelectFileDialogHandler . args [ 0 ] || [ ] ;
2070- assert . strictEqual ( items . length , 1 , '_detachSelectFileDialogHandler args is valid' ) ;
2071- assert . strictEqual ( items [ 0 ] , '.trigger' , '_detachSelectFileDialogHandler args is valid' ) ;
2071+ assert . strictEqual ( instance . _detachSelectFileDialogHandlers . callCount , 1 , '_detachSelectFileDialogHandlers method called' ) ;
2072+ items = instance . _detachSelectFileDialogHandlers . args [ 0 ] || [ ] ;
2073+ assert . strictEqual ( items . length , 1 , '_detachSelectFileDialogHandlers args is valid' ) ;
2074+ assert . strictEqual ( items [ 0 ] , '.trigger' , '_detachSelectFileDialogHandlers args is valid' ) ;
20722075
20732076 assert . strictEqual ( instance . _detachDragEventHandlers . callCount , 1 , '_detachDragEventHandlers method called' ) ;
20742077 items = instance . _detachDragEventHandlers . args [ 0 ] || [ ] ;
20752078 assert . strictEqual ( items . length , 1 , '_detachDragEventHandlers args is valid' ) ;
20762079 assert . strictEqual ( items [ 0 ] , '.dropZone' , '_detachDragEventHandlers args is valid' ) ;
20772080
2078- instance . _attachSelectFileDialogHandler . restore ( ) ;
2079- instance . _detachSelectFileDialogHandler . restore ( ) ;
2081+ instance . _attachSelectFileDialogHandlers . restore ( ) ;
2082+ instance . _detachSelectFileDialogHandlers . restore ( ) ;
20802083 instance . _attachDragEventHandlers . restore ( ) ;
20812084 instance . _detachDragEventHandlers . restore ( ) ;
20822085 customDropZone . remove ( ) ;
@@ -4200,17 +4203,21 @@ QUnit.module('readOnly option', moduleConfig, () => {
42004203 assert . ok ( $cancelButtons . eq ( 1 ) . hasClass ( 'dx-state-disabled' ) , '2nd button is disabled' ) ;
42014204 } ) ;
42024205
4203- QUnit . test ( 'dialogTrigger should be unable to call _selectButtonClickHandler ' , function ( assert ) {
4204- const instance = $ ( '#fileuploader' ) . dxFileUploader ( {
4206+ QUnit . test ( 'File selection does not open if component is read-only ' , function ( assert ) {
4207+ const $element = $ ( '#fileuploader' ) . dxFileUploader ( {
42054208 readOnly : true ,
4206- uploadMode : 'useButtons'
4207- } ) . dxFileUploader ( 'instance' ) ;
4208- sinon . stub ( instance , '_selectButtonClickHandler' ) . callsFake ( ( ) => instance . _selectFileDialogHandler ( ) ) ;
4209+ uploadMode : 'useButtons' ,
4210+ } ) ;
4211+ const instance = $element . dxFileUploader ( 'instance' ) ;
4212+
4213+ instance . _selectFileDialogClickHandler ( ) ;
4214+
4215+ const fileUploaderInputClickSpy = sinon . spy ( ) ;
4216+ const $fileUploaderInput = $element . find ( `.${ FILEUPLOADER_INPUT_CLASS } ` ) ;
42094217
4210- instance . _selectButtonClickHandler ( ) ;
4211- assert . strictEqual ( instance . _selectButtonClickHandler . returnValues [ 0 ] , false , 'selectFile method not called' ) ;
4218+ $fileUploaderInput . on ( 'click' , fileUploaderInputClickSpy ) ;
42124219
4213- instance . _selectButtonClickHandler . restore ( ) ;
4220+ assert . strictEqual ( fileUploaderInputClickSpy . callCount , 0 , 'selectFile method not called' ) ;
42144221 } ) ;
42154222
42164223 QUnit . test ( 'uploading events can be fired (successful upload)' , function ( assert ) {
@@ -4355,38 +4362,33 @@ QUnit.module('readOnly option', moduleConfig, () => {
43554362 $fileUploader . find ( '.dx-fileuploader-input-wrapper' ) . trigger ( 'dragenter' ) ;
43564363 assert . notOk ( $fileUploader . hasClass ( 'dx-fileuploader-dragover' ) , 'drag event was not handled for input wrapper element' ) ;
43574364 } ) ;
4358-
43594365} ) ;
43604366
4361- QUnit . module ( 'dxButton integration' , moduleConfig , ( ) => {
4362- QUnit . test ( 'dialog should be shown after press enter key on dxButton (T1178836)' , function ( assert ) {
4363- if ( devices . real ( ) . deviceType !== 'desktop' ) {
4364- assert . ok ( true , 'keyboard is not supported for not generic devices' ) ;
4365- return ;
4366- }
4367+ QUnit . module ( 'integration of dx button components via dialogTrigger' , moduleConfig , ( ) => {
4368+ [ 'enter' , 'space' ] . forEach ( keyName => {
4369+ [ 'dxButton' , 'dxButtonGroup' , 'dxDropDownButton' ] . forEach ( component => {
4370+ QUnit . test ( `dialog should be shown after press ${ keyName } key on ${ component } (T1178836, T1256752)` , function ( assert ) {
4371+ if ( devices . real ( ) . deviceType !== 'desktop' ) {
4372+ assert . ok ( true , 'keyboard is not supported for not generic devices' ) ;
4373+ return ;
4374+ }
43674375
4368- const $customDialogTrigger = $ ( '<div>' ) . appendTo ( '#qunit-fixture' ) ;
4376+ const $dialogTrigger = $ ( '<div>' ) [ component ] ( ) . appendTo ( '#qunit-fixture' ) ;
43694377
4370- $customDialogTrigger . dxButton ( {
4371- text : 'button'
4372- } ) ;
4378+ $ ( '#fileuploader' ) . dxFileUploader ( { dialogTrigger : $dialogTrigger } ) ;
43734379
4374- const instance = $ ( '#fileuploader' ) . dxFileUploader ( {
4375- dialogTrigger : $customDialogTrigger ,
4376- visible : false
4377- } ) . dxFileUploader ( 'instance' ) ;
4378- const spy = sinon . spy ( ) ;
4380+ const $fileUploaderInput = $ ( `.${ FILEUPLOADER_INPUT_CLASS } ` ) ;
4381+ const $focusTarget = component === 'dxButton' ? $dialogTrigger : $ ( `.${ BUTTON_GROUP_CLASS } ` ) ;
43794382
4380- $ ( `.${ FILEUPLOADER_INPUT_CLASS } ` ) . on ( 'click' , spy ) ;
4383+ const fileUploaderInputClickSpy = sinon . spy ( ) ;
4384+ const keyboard = keyboardMock ( $focusTarget ) ;
43814385
4382- instance . option ( {
4383- uploadMode : 'useButtons' ,
4384- } ) ;
4385- assert . strictEqual ( spy . callCount , 0 , 'click on input not fired' ) ;
4386+ $fileUploaderInput . on ( 'click' , fileUploaderInputClickSpy ) ;
43864387
4387- const keyboard = keyboardMock ( $customDialogTrigger ) ;
4388- keyboard . keyDown ( 'enter' ) ;
4388+ keyboard . keyUp ( keyName ) ;
43894389
4390- assert . strictEqual ( spy . callCount , 1 , 'click on input fired' ) ;
4390+ assert . strictEqual ( fileUploaderInputClickSpy . calledOnce , true , 'click on input fired once' ) ;
4391+ } ) ;
4392+ } ) ;
43914393 } ) ;
43924394} ) ;
0 commit comments