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
8a7b247f
Commit
8a7b247f
authored
Sep 05, 2018
by
Paul Slaughter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create spec for dropzone_input and refactor for testability
parent
03439714
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
1 deletion
+71
-1
app/assets/javascripts/dropzone_input.js
app/assets/javascripts/dropzone_input.js
+3
-1
spec/javascripts/dropzone_input_spec.js
spec/javascripts/dropzone_input_spec.js
+68
-0
No files found.
app/assets/javascripts/dropzone_input.js
View file @
8a7b247f
...
...
@@ -55,7 +55,7 @@ export default function dropzoneInput(form) {
if
(
!
uploadsPath
)
{
$formDropzone
.
addClass
(
'
js-invalid-dropzone
'
);
return
;
return
null
;
}
const
dropzone
=
$formDropzone
.
dropzone
({
...
...
@@ -285,4 +285,6 @@ export default function dropzoneInput(form) {
$
(
this
).
closest
(
'
.gfm-form
'
).
find
(
'
.div-dropzone
'
).
click
();
formTextarea
.
focus
();
});
return
Dropzone
.
forElement
(
$formDropzone
.
get
(
0
));
}
spec/javascripts/dropzone_input_spec.js
0 → 100644
View file @
8a7b247f
import
$
from
'
jquery
'
;
import
dropzoneInput
from
'
~/dropzone_input
'
;
import
{
TEST_HOST
}
from
'
spec/test_constants
'
;
const
TEST_FILE
=
{
upload
:
{},
};
const
TEST_UPLOAD_PATH
=
`
${
TEST_HOST
}
/upload/file`
;
const
TEST_ERROR_MESSAGE
=
'
A big error occurred!
'
;
const
TEMPLATE
=
(
`<form class="gfm-form" data-uploads-path="
${
TEST_UPLOAD_PATH
}
">
<textarea class="js-gfm-input"></textarea>
<div class="uploading-error-message"></div>
</form>`
);
describe
(
'
dropzone_input
'
,
()
=>
{
let
form
;
let
dropzone
;
let
xhr
;
let
oldXMLHttpRequest
;
beforeEach
(()
=>
{
form
=
$
(
TEMPLATE
);
dropzone
=
dropzoneInput
(
form
);
xhr
=
jasmine
.
createSpyObj
(
Object
.
keys
(
XMLHttpRequest
.
prototype
));
oldXMLHttpRequest
=
window
.
XMLHttpRequest
;
window
.
XMLHttpRequest
=
()
=>
xhr
;
});
afterEach
(()
=>
{
window
.
XMLHttpRequest
=
oldXMLHttpRequest
;
});
it
(
'
shows error message, 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
'
,
()
=>
{
xhr
=
{
...
xhr
,
statusCode
:
400
,
readyState
:
4
,
responseText
:
TEST_ERROR_MESSAGE
,
getResponseHeader
:
()
=>
'
text/plain
'
,
};
dropzone
.
processFile
(
TEST_FILE
);
xhr
.
onload
();
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