Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c309487f
Commit
c309487f
authored
Nov 18, 2019
by
Fabio Huser
Committed by
Phil Hughes
Nov 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(dropzone): prevent dropzone exception if target element missing
parent
71953508
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
37 deletions
+56
-37
app/assets/javascripts/dropzone_input.js
app/assets/javascripts/dropzone_input.js
+1
-1
changelogs/unreleased/fix-dropzone-no-element-exception.yml
changelogs/unreleased/fix-dropzone-no-element-exception.yml
+5
-0
spec/javascripts/dropzone_input_spec.js
spec/javascripts/dropzone_input_spec.js
+50
-36
No files found.
app/assets/javascripts/dropzone_input.js
View file @
c309487f
...
@@ -290,5 +290,5 @@ export default function dropzoneInput(form) {
...
@@ -290,5 +290,5 @@ export default function dropzoneInput(form) {
formTextarea
.
focus
();
formTextarea
.
focus
();
});
});
return
Dropzone
.
forElement
(
$formDropzone
.
get
(
0
))
;
return
$formDropzone
.
get
(
0
)
?
Dropzone
.
forElement
(
$formDropzone
.
get
(
0
))
:
null
;
}
}
changelogs/unreleased/fix-dropzone-no-element-exception.yml
0 → 100644
View file @
c309487f
---
title
:
Prevent Dropzone.js initialisation error by checking target element existence
merge_request
:
20256
author
:
Fabio Huser
type
:
fixed
spec/javascripts/dropzone_input_spec.js
View file @
c309487f
...
@@ -13,54 +13,68 @@ const TEMPLATE = `<form class="gfm-form" data-uploads-path="${TEST_UPLOAD_PATH}"
...
@@ -13,54 +13,68 @@ const TEMPLATE = `<form class="gfm-form" data-uploads-path="${TEST_UPLOAD_PATH}"
</form>`
;
</form>`
;
describe
(
'
dropzone_input
'
,
()
=>
{
describe
(
'
dropzone_input
'
,
()
=>
{
let
form
;
it
(
'
returns null when failed to initialize
'
,
()
=>
{
let
dropzone
;
const
dropzone
=
dropzoneInput
(
$
(
'
<form class="gfm-form"></form>
'
));
let
xhr
;
let
oldXMLHttpRequest
;
beforeEach
(()
=>
{
expect
(
dropzone
).
toBeNull
();
form
=
$
(
TEMPLATE
);
}
);
dropzone
=
dropzoneInput
(
form
);
it
(
'
returns valid dropzone when successfully initialize
'
,
()
=>
{
const
dropzone
=
dropzoneInput
(
$
(
TEMPLATE
));
xhr
=
jasmine
.
createSpyObj
(
Object
.
keys
(
XMLHttpRequest
.
prototype
));
expect
(
dropzone
.
version
).
toBeTruthy
();
oldXMLHttpRequest
=
window
.
XMLHttpRequest
;
window
.
XMLHttpRequest
=
()
=>
xhr
;
});
});
afterEach
(()
=>
{
describe
(
'
shows error message
'
,
()
=>
{
window
.
XMLHttpRequest
=
oldXMLHttpRequest
;
let
form
;
});
let
dropzone
;
let
xhr
;
let
oldXMLHttpRequest
;
it
(
'
shows error message, when AJAX fails with json
'
,
()
=>
{
beforeEach
(()
=>
{
xhr
=
{
form
=
$
(
TEMPLATE
);
...
xhr
,
statusCode
:
400
,
readyState
:
4
,
responseText
:
JSON
.
stringify
({
message
:
TEST_ERROR_MESSAGE
}),
getResponseHeader
:
()
=>
'
application/json
'
,
};
dropzone
.
processFile
(
TEST_FILE
);
dropzone
=
dropzoneInput
(
form
);
xhr
.
onload
();
xhr
=
jasmine
.
createSpyObj
(
Object
.
keys
(
XMLHttpRequest
.
prototype
));
oldXMLHttpRequest
=
window
.
XMLHttpRequest
;
window
.
XMLHttpRequest
=
()
=>
xhr
;
});
expect
(
form
.
find
(
'
.uploading-error-message
'
).
text
()).
toEqual
(
TEST_ERROR_MESSAGE
);
afterEach
(()
=>
{
});
window
.
XMLHttpRequest
=
oldXMLHttpRequest
;
});
it
(
'
when AJAX fails with json
'
,
()
=>
{
xhr
=
{
...
xhr
,
statusCode
:
400
,
readyState
:
4
,
responseText
:
JSON
.
stringify
({
message
:
TEST_ERROR_MESSAGE
}),
getResponseHeader
:
()
=>
'
application/json
'
,
};
dropzone
.
processFile
(
TEST_FILE
);
xhr
.
onload
();
expect
(
form
.
find
(
'
.uploading-error-message
'
).
text
()).
toEqual
(
TEST_ERROR_MESSAGE
);
});
it
(
'
shows error message,
when AJAX fails with text
'
,
()
=>
{
it
(
'
when AJAX fails with text
'
,
()
=>
{
xhr
=
{
xhr
=
{
...
xhr
,
...
xhr
,
statusCode
:
400
,
statusCode
:
400
,
readyState
:
4
,
readyState
:
4
,
responseText
:
TEST_ERROR_MESSAGE
,
responseText
:
TEST_ERROR_MESSAGE
,
getResponseHeader
:
()
=>
'
text/plain
'
,
getResponseHeader
:
()
=>
'
text/plain
'
,
};
};
dropzone
.
processFile
(
TEST_FILE
);
dropzone
.
processFile
(
TEST_FILE
);
xhr
.
onload
();
xhr
.
onload
();
expect
(
form
.
find
(
'
.uploading-error-message
'
).
text
()).
toEqual
(
TEST_ERROR_MESSAGE
);
expect
(
form
.
find
(
'
.uploading-error-message
'
).
text
()).
toEqual
(
TEST_ERROR_MESSAGE
);
});
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment