Added failure scenario for uploading an image of incorrect format

* Also added scenarios for uploading an image of in insert mode (used in wysiwyg editor)

Fixes #2168
Refine JS to not hold a variable.