diff --git a/tests/functional-all.js b/tests/functional-all.js index 788b46c2c..73703d3a9 100644 --- a/tests/functional-all.js +++ b/tests/functional-all.js @@ -16,10 +16,11 @@ define([ './functional/comments-non-auth.js', './functional/contributors-non-auth.js', './functional/comments-auth.js', + './functional/history-navigation-non-auth.js', + './functional/image-uploads-non-auth.js', './functional/index-non-auth.js', './functional/issue-list-non-auth.js', './functional/issues-non-auth.js', - './functional/history-navigation-non-auth.js', './functional/search-non-auth.js', './functional/search-auth.js', './functional/issues-auth.js', diff --git a/tests/functional-nonauth.js b/tests/functional-nonauth.js index f7d72a5bb..54ada1b9e 100644 --- a/tests/functional-nonauth.js +++ b/tests/functional-nonauth.js @@ -14,6 +14,7 @@ define([ './functional/reporting-non-auth.js', './functional/comments-non-auth.js', './functional/contributors-non-auth.js', + './functional/image-uploads-non-auth.js', './functional/index-non-auth.js', './functional/issue-list-non-auth.js', './functional/issues-non-auth.js', diff --git a/tests/functional/image-uploads-non-auth.js b/tests/functional/image-uploads-non-auth.js new file mode 100644 index 000000000..fc4c7cb24 --- /dev/null +++ b/tests/functional/image-uploads-non-auth.js @@ -0,0 +1,73 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +define([ + 'intern', + 'intern!object', + 'intern/chai!assert', + 'require', + 'intern/node_modules/dojo/node!path', +], function(intern, registerSuite, assert) { + 'use strict'; + + var url = intern.config.siteRoot; + + registerSuite({ + name: 'Image Uploads (non-auth)', + + 'postMessaged dataURI preview': function() { + return this.remote + .setFindTimeout(intern.config.wc.pageLoadTimeout) + .get(require.toUrl(url + '?open=1')) + // send a small base64 encoded green test square + .execute('postMessage("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAIAAABLixI0AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAB3RJTUUH3gYSAig452t/EQAAAClJREFUOMvtzkENAAAMg0A25ZU+E032AQEXoNcApCGFLX5paWlpaWl9dqq9AS6CKROfAAAAAElFTkSuQmCC", "http://localhost:5000")') + .sleep(1000) + .findByCssSelector('.js-image-upload-label').getAttribute('style') + .then(function(inlineStyle) { + assert.include(inlineStyle, 'data:image/png;base64,iVBOR', 'Base64 data shown as preview background'); + }) + .end(); + }, + + 'postMessaged dataURI image upload worked': function() { + return this.remote + .setFindTimeout(intern.config.wc.pageLoadTimeout) + .get(require.toUrl(url + '?open=1')) + // send a small base64 encoded green test square + .execute('postMessage("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAIAAABLixI0AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAB3RJTUUH3gYSAig452t/EQAAAClJREFUOMvtzkENAAAMg0A25ZU+E032AQEXoNcApCGFLX5paWlpaWl9dqq9AS6CKROfAAAAAElFTkSuQmCC", "http://localhost:5000")') + .sleep(1000) + .findByCssSelector('#description').getProperty('value') + .then(function(val) { + assert.include(val, '![Screenshot Description](http://localhost:5000/uploads/', 'The data URI was correctly uploaded and its URL was copied to the bug description.'); + }) + .end(); + }, + + 'postMessaged dataURI remove button': function() { + return this.remote + .setFindTimeout(intern.config.wc.pageLoadTimeout) + .get(require.toUrl(url + '?open=1')) + // send a small base64 encoded green test square + .execute('postMessage("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAIAAABLixI0AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAB3RJTUUH3gYSAig452t/EQAAAClJREFUOMvtzkENAAAMg0A25ZU+E032AQEXoNcApCGFLX5paWlpaWl9dqq9AS6CKROfAAAAAElFTkSuQmCC", "http://localhost:5000")') + .sleep(1000) + .findByCssSelector('.js-image-upload-label .wc-UploadForm-button').isDisplayed() + .then(function(isDisplayed) { + assert.equal(isDisplayed, true, 'Remove button is displayed'); + }) + .end() + .findByCssSelector('.js-image-upload-label .wc-UploadForm-button').click() + .end() + .findByCssSelector('.js-image-upload-label').getAttribute('style') + .then(function(inlineStyle) { + assert.notInclude(inlineStyle, 'data:image/png;base64,iVBOR', 'Preview was removed'); + }) + .end() + .findByCssSelector('#description').getProperty('value') + .then(function(val) { + assert.notInclude(val, '![Screenshot Description](http://localhost:5000/uploads/', 'The data URI was correctly uploaded and its URL was copied to the bug description.'); + }) + .end(); + } + }); +});