diff --git a/tests/functional/image-uploads-non-auth.js b/tests/functional/image-uploads-non-auth.js index 122224a79..2536fcdc3 100755 --- a/tests/functional/image-uploads-non-auth.js +++ b/tests/functional/image-uploads-non-auth.js @@ -1,335 +1,335 @@ -// "use strict"; -// /* 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/. */ -// /*global WindowHelpers:true*/ -// const intern = require("intern").default; -// const { assert } = intern.getPlugin("chai"); -// const { registerSuite } = intern.getInterface("object"); -// const FunctionalHelpers = require("./lib/helpers.js"); -// const path = require("path"); -// const url = intern.config.siteRoot + "/issues/new"; -// const cwd = intern.config.basePath; +"use strict"; +/* 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/. */ +/*global WindowHelpers:true*/ +const intern = require("intern").default; +const { assert } = intern.getPlugin("chai"); +const { registerSuite } = intern.getInterface("object"); +const FunctionalHelpers = require("./lib/helpers.js"); +const path = require("path"); +const url = intern.config.siteRoot + "/issues/new"; +const cwd = intern.config.basePath; -// // This string is executed by calls to `execute()` in various tests -// // it postMessages a small green test square. -// const POSTMESSAGE_TEST_SQUARE = -// 'postMessage("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAIAAABLixI0AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAB3RJTUUH3gYSAig452t/EQAAAClJREFUOMvtzkENAAAMg0A25ZU+E032AQEXoNcApCGFLX5paWlpaWl9dqq9AS6CKROfAAAAAElFTkSuQmCC", "http://localhost:5000")'; -// const VALID_IMAGE_PATH = path.join(cwd, "tests/fixtures", "green_square.png"); -// const BAD_IMAGE_PATH = path.join(cwd, "tests/fixtures", "evil.py"); +// This string is executed by calls to `execute()` in various tests +// it postMessages a small green test square. +const POSTMESSAGE_TEST_SQUARE = + 'postMessage("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAIAAABLixI0AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAB3RJTUUH3gYSAig452t/EQAAAClJREFUOMvtzkENAAAMg0A25ZU+E032AQEXoNcApCGFLX5paWlpaWl9dqq9AS6CKROfAAAAAElFTkSuQmCC", "http://localhost:5000")'; +const VALID_IMAGE_PATH = path.join(cwd, "tests/fixtures", "green_square.png"); +const BAD_IMAGE_PATH = path.join(cwd, "tests/fixtures", "evil.py"); -// registerSuite("Image Uploads (non-auth)", { -// tests: { -// "postMessaged dataURI preview"() { -// return ( -// FunctionalHelpers.openPage(this, url, ".js-image-upload") -// // send a small base64 encoded green test square -// .execute(POSTMESSAGE_TEST_SQUARE) -// .sleep(1000) -// .findByCssSelector(".js-image-upload") -// .getAttribute("style") -// .then(function(inlineStyle) { -// assert.include( -// inlineStyle, -// "data:image/png;base64,iVBOR", -// "Base64 data shown as preview background" -// ); -// }) -// .end() -// ); -// }, -// "postMessaged blob preview"() { -// return ( -// FunctionalHelpers.openPage(this, url, ".js-image-upload") -// // Build up a green test square in canvas, toBlob that, and then postMessage the blob -// // see window-helpers.js for more details. -// .execute(function() { -// WindowHelpers.getBlob().then(WindowHelpers.sendBlob); -// }) -// .sleep(1000) -// .findByCssSelector(".js-image-upload") -// .getAttribute("style") -// .then(function(inlineStyle) { -// assert.include( -// inlineStyle, -// "data:image/png;base64,iVBOR", -// "Base64 data shown as preview background" -// ); -// }) -// .end() -// ); -// }, +registerSuite("Image Uploads (non-auth)", { + tests: { + "postMessaged dataURI preview"() { + return ( + FunctionalHelpers.openPage(this, url, ".js-image-upload") + // send a small base64 encoded green test square + .execute(POSTMESSAGE_TEST_SQUARE) + .sleep(1000) + .findByCssSelector(".js-image-upload") + .getAttribute("style") + .then(function(inlineStyle) { + assert.include( + inlineStyle, + "data:image/png;base64,iVBOR", + "Base64 data shown as preview background" + ); + }) + .end() + ); + }, + "postMessaged blob preview"() { + return ( + FunctionalHelpers.openPage(this, url, ".js-image-upload") + // Build up a green test square in canvas, toBlob that, and then postMessage the blob + // see window-helpers.js for more details. + .execute(function() { + WindowHelpers.getBlob().then(WindowHelpers.sendBlob); + }) + .sleep(1000) + .findByCssSelector(".js-image-upload") + .getAttribute("style") + .then(function(inlineStyle) { + assert.include( + inlineStyle, + "data:image/png;base64,iVBOR", + "Base64 data shown as preview background" + ); + }) + .end() + ); + }, -// "postMessaged blob preview that was sent as part of an object"() { -// return ( -// FunctionalHelpers.openPage(this, url, ".js-image-upload") -// // Build up a green test square in canvas, toBlob that, and then postMessage the blob -// // see window-helpers.js for more details. -// .execute(function() { -// WindowHelpers.getBlob().then(WindowHelpers.sendBlobInObject); -// }) -// .sleep(1000) -// .findByCssSelector(".js-image-upload") -// .getAttribute("style") -// .then(function(inlineStyle) { -// assert.include( -// inlineStyle, -// "data:image/png;base64,iVBOR", -// "Base64 data shown as preview background" -// ); -// }) -// .end() -// ); -// }, + "postMessaged blob preview that was sent as part of an object"() { + return ( + FunctionalHelpers.openPage(this, url, ".js-image-upload") + // Build up a green test square in canvas, toBlob that, and then postMessage the blob + // see window-helpers.js for more details. + .execute(function() { + WindowHelpers.getBlob().then(WindowHelpers.sendBlobInObject); + }) + .sleep(1000) + .findByCssSelector(".js-image-upload") + .getAttribute("style") + .then(function(inlineStyle) { + assert.include( + inlineStyle, + "data:image/png;base64,iVBOR", + "Base64 data shown as preview background" + ); + }) + .end() + ); + }, -// "uploaded image file preview"() { -// return FunctionalHelpers.openPage(this, url, ".js-image-upload") -// .findById("image") -// .type("tests/fixtures/green_square.png") -// .end() -// .sleep(1000) -// .findByCssSelector(".js-image-upload") -// .getAttribute("style") -// .then(function(inlineStyle) { -// assert.include( -// inlineStyle, -// "data:image/png;base64,iVBOR", -// "Base64 data shown as preview background" -// ); -// }) -// .end(); -// }, + "uploaded image file preview"() { + return FunctionalHelpers.openPage(this, url, ".js-image-upload") + .findById("image") + .type("tests/fixtures/green_square.png") + .end() + .sleep(1000) + .findByCssSelector(".js-image-upload") + .getAttribute("style") + .then(function(inlineStyle) { + assert.include( + inlineStyle, + "data:image/png;base64,iVBOR", + "Base64 data shown as preview background" + ); + }) + .end(); + }, -// "postMessaged dataURI image doesn't upload before form submission"() { -// return ( -// FunctionalHelpers.openPage(this, url, ".js-image-upload") -// // send a small base64 encoded green test square -// .execute(POSTMESSAGE_TEST_SQUARE) -// .sleep(1000) -// .findByCssSelector("#steps_reproduce") -// .getProperty("value") -// .then(function(val) { -// assert.notInclude( -// val, -// "[![Screenshot Description](http://localhost:5000/uploads/", -// "The data URI was not uploaded before form submission." -// ); -// }) -// .end() -// ); -// }, + "postMessaged dataURI image doesn't upload before form submission"() { + return ( + FunctionalHelpers.openPage(this, url, ".js-image-upload") + // send a small base64 encoded green test square + .execute(POSTMESSAGE_TEST_SQUARE) + .sleep(1000) + .findByCssSelector("#steps_reproduce") + .getProperty("value") + .then(function(val) { + assert.notInclude( + val, + "[![Screenshot Description](http://localhost:5000/uploads/", + "The data URI was not uploaded before form submission." + ); + }) + .end() + ); + }, -// "postMessaged blob image doesn't upload before form submission"() { -// return ( -// FunctionalHelpers.openPage(this, url, ".js-image-upload") -// // Build up a green test square in canvas, toBlob that, and then postMessage the blob -// .execute(function() { -// WindowHelpers.getBlob().then(WindowHelpers.sendBlob); -// }) -// .sleep(1000) -// .findByCssSelector("#steps_reproduce") -// .getProperty("value") -// .then(function(val) { -// assert.notInclude( -// val, -// "[![Screenshot Description](http://localhost:5000/uploads/", -// "The data URI was not uploaded before form submission." -// ); -// }) -// .end() -// ); -// }, + "postMessaged blob image doesn't upload before form submission"() { + return ( + FunctionalHelpers.openPage(this, url, ".js-image-upload") + // Build up a green test square in canvas, toBlob that, and then postMessage the blob + .execute(function() { + WindowHelpers.getBlob().then(WindowHelpers.sendBlob); + }) + .sleep(1000) + .findByCssSelector("#steps_reproduce") + .getProperty("value") + .then(function(val) { + assert.notInclude( + val, + "[![Screenshot Description](http://localhost:5000/uploads/", + "The data URI was not uploaded before form submission." + ); + }) + .end() + ); + }, -// "uploaded image file doesn't upload before form submission"() { -// return FunctionalHelpers.openPage(this, url, ".js-image-upload") -// .findById("image") -// .type("tests/fixtures/green_square.png") -// .end() -// .sleep(1000) -// .findByCssSelector("#steps_reproduce") -// .getProperty("value") -// .then(function(val) { -// assert.notInclude( -// val, -// "[![Screenshot Description](http://localhost:5000/uploads/", -// "The data URI was not uploaded before form submission." -// ); -// }) -// .end(); -// }, + "uploaded image file doesn't upload before form submission"() { + return FunctionalHelpers.openPage(this, url, ".js-image-upload") + .findById("image") + .type("tests/fixtures/green_square.png") + .end() + .sleep(1000) + .findByCssSelector("#steps_reproduce") + .getProperty("value") + .then(function(val) { + assert.notInclude( + val, + "[![Screenshot Description](http://localhost:5000/uploads/", + "The data URI was not uploaded before form submission." + ); + }) + .end(); + }, -// "remove image upload button is shown"() { -// return ( -// FunctionalHelpers.openPage(this, url, ".js-remove-upload") -// // send a small base64 encoded green test square -// .execute(POSTMESSAGE_TEST_SQUARE) -// .sleep(1000) -// .findByCssSelector(".js-remove-upload") -// .isDisplayed() -// .then(function(isDisplayed) { -// assert.equal(isDisplayed, true, "Remove button is displayed"); -// }) -// .end() -// .findByCssSelector(".js-image-upload") -// .getAttribute("class") -// .then(function(className) { -// assert.notInclude( -// "is-validated", -// className, -// "parent container got the right class after an image was postMessage'd" -// ); -// }) -// .end() -// ); -// }, + "remove image upload button is shown"() { + return ( + FunctionalHelpers.openPage(this, url, ".js-remove-upload") + // send a small base64 encoded green test square + .execute(POSTMESSAGE_TEST_SQUARE) + .sleep(1000) + .findByCssSelector(".js-remove-upload") + .isDisplayed() + .then(function(isDisplayed) { + assert.equal(isDisplayed, true, "Remove button is displayed"); + }) + .end() + .findByCssSelector(".js-image-upload") + .getAttribute("class") + .then(function(className) { + assert.notInclude( + "is-validated", + className, + "parent container got the right class after an image was postMessage'd" + ); + }) + .end() + ); + }, -// "clicking remove image upload button removes preview"() { -// return ( -// FunctionalHelpers.openPage(this, url, ".js-remove-upload") -// // send a small base64 encoded green test square -// .execute(POSTMESSAGE_TEST_SQUARE) -// .sleep(1000) -// .execute(() => { -// // work around for chrome "Other element would receive the click" -// // error -// $(".js-remove-upload")[0].click(); -// }) -// .end() -// .findByCssSelector(".js-image-upload") -// .getAttribute("style") -// .then(function(inlineStyle) { -// assert.notInclude( -// inlineStyle, -// "data:image/png;base64,iVBOR", -// "Preview was removed" -// ); -// }) -// .end() -// ); -// }, + "clicking remove image upload button removes preview"() { + return ( + FunctionalHelpers.openPage(this, url, ".js-remove-upload") + // send a small base64 encoded green test square + .execute(POSTMESSAGE_TEST_SQUARE) + .sleep(1000) + .execute(() => { + // work around for chrome "Other element would receive the click" + // error + $(".js-remove-upload")[0].click(); + }) + .end() + .findByCssSelector(".js-image-upload") + .getAttribute("style") + .then(function(inlineStyle) { + assert.notInclude( + inlineStyle, + "data:image/png;base64,iVBOR", + "Preview was removed" + ); + }) + .end() + ); + }, -// "clicking remove image upload button removes image URL"() { -// return ( -// FunctionalHelpers.openPage(this, url, ".js-remove-upload") -// // send a small base64 encoded green test square -// .execute(POSTMESSAGE_TEST_SQUARE) -// .sleep(1000) -// .execute(() => { -// // work around for chrome "Other element would receive the click" -// // error -// $(".js-remove-upload")[0].click(); -// }) -// .end() -// .findByCssSelector(".js-image-upload") -// .getAttribute("style") -// .then(function(inlineStyle) { -// assert.notInclude( -// inlineStyle, -// "data:image/png;base64,iVBOR", -// "Preview was removed" -// ); -// }) -// .end() -// ); -// }, + "clicking remove image upload button removes image URL"() { + return ( + FunctionalHelpers.openPage(this, url, ".js-remove-upload") + // send a small base64 encoded green test square + .execute(POSTMESSAGE_TEST_SQUARE) + .sleep(1000) + .execute(() => { + // work around for chrome "Other element would receive the click" + // error + $(".js-remove-upload")[0].click(); + }) + .end() + .findByCssSelector(".js-image-upload") + .getAttribute("style") + .then(function(inlineStyle) { + assert.notInclude( + inlineStyle, + "data:image/png;base64,iVBOR", + "Preview was removed" + ); + }) + .end() + ); + }, -// "double image select works"() { -// return FunctionalHelpers.openPage(this, url, ".js-remove-upload") -// .execute(POSTMESSAGE_TEST_SQUARE) -// .sleep(1000) -// .execute(() => { -// $(".js-image-upload")[0].click(); -// }) -// .execute(POSTMESSAGE_TEST_SQUARE) -// .sleep(1000) -// .execute(() => { -// $(".js-image-upload")[0].click(); -// }) -// .sleep(1000) -// .findByCssSelector(".js-image-upload") -// .getAttribute("style") -// .then(function(inlineStyle) { -// assert.include( -// inlineStyle, -// "data:image/png;base64,iVBOR", -// "Preview is shown" -// ); -// }) -// .end(); -// }, + "double image select works"() { + return FunctionalHelpers.openPage(this, url, ".js-remove-upload") + .execute(POSTMESSAGE_TEST_SQUARE) + .sleep(1000) + .execute(() => { + $(".js-image-upload")[0].click(); + }) + .execute(POSTMESSAGE_TEST_SQUARE) + .sleep(1000) + .execute(() => { + $(".js-image-upload")[0].click(); + }) + .sleep(1000) + .findByCssSelector(".js-image-upload") + .getAttribute("style") + .then(function(inlineStyle) { + assert.include( + inlineStyle, + "data:image/png;base64,iVBOR", + "Preview is shown" + ); + }) + .end(); + }, -// "Image extension validation"() { -// return ( -// FunctionalHelpers.openPage(this, url, ".js-report-buttons") -// .findByCssSelector("#image") -// .type(BAD_IMAGE_PATH) -// .end() -// .findByCssSelector(".form-upload-error") -// .getVisibleText() -// .then(function(text) { -// assert.include( -// text, -// "Image must be one of the following", -// "Image type validation message is shown" -// ); -// }) -// .end() -// // pick a valid file type -// .findByCssSelector("#image") -// .type(VALID_IMAGE_PATH) -// .end() -// // validation message should be gone -// .waitForDeletedByCssSelector(".form-upload-error") -// .end() -// ); -// }, + "Image extension validation"() { + return ( + FunctionalHelpers.openPage(this, url, ".js-report-buttons") + .findByCssSelector("#image") + .type(BAD_IMAGE_PATH) + .end() + .findByCssSelector(".form-upload-error") + .getVisibleText() + .then(function(text) { + assert.include( + text, + "Image must be one of the following", + "Image type validation message is shown" + ); + }) + .end() + // pick a valid file type + .findByCssSelector("#image") + .type(VALID_IMAGE_PATH) + .end() + // validation message should be gone + .waitForDeletedByCssSelector(".form-upload-error") + .end() + ); + }, -// "Selecting an invalid image after a valid one"() { -// return ( -// FunctionalHelpers.openPage(this, url, ".js-report-buttons") -// .findByCssSelector("#image") -// .type(VALID_IMAGE_PATH) -// .end() -// .findByCssSelector("#image") -// .type(BAD_IMAGE_PATH) -// .end() -// .findByCssSelector(".form-upload-error") -// .getVisibleText() -// .then(function(text) { -// assert.include( -// text, -// "Image must be one of the following", -// "Image type validation message is shown" -// ); -// }) -// .end() -// .findByCssSelector(".js-image-upload") -// .getAttribute("style") -// .then(function(inlineStyle) { -// assert.notInclude( -// inlineStyle, -// "data:image/png;base64,iVBOR", -// "The previous valid image preview should be removed." -// ); -// }) -// .end() -// .findByCssSelector(".js-label-upload") -// .isDisplayed() -// .then(function(isDisplayed) { -// assert.isFalse( -// isDisplayed, -// "Upload label is hidden while the error is displayed" -// ); -// }) -// .end() -// // pick a valid file type -// .findByCssSelector("#image") -// .type(VALID_IMAGE_PATH) -// .end() -// // validation message should be gone -// .waitForDeletedByCssSelector(".form-upload-error") -// .end() -// ); -// } -// } -// }); + "Selecting an invalid image after a valid one"() { + return ( + FunctionalHelpers.openPage(this, url, ".js-report-buttons") + .findByCssSelector("#image") + .type(VALID_IMAGE_PATH) + .end() + .findByCssSelector("#image") + .type(BAD_IMAGE_PATH) + .end() + .findByCssSelector(".form-upload-error") + .getVisibleText() + .then(function(text) { + assert.include( + text, + "Image must be one of the following", + "Image type validation message is shown" + ); + }) + .end() + .findByCssSelector(".js-image-upload") + .getAttribute("style") + .then(function(inlineStyle) { + assert.notInclude( + inlineStyle, + "data:image/png;base64,iVBOR", + "The previous valid image preview should be removed." + ); + }) + .end() + .findByCssSelector(".js-label-upload") + .isDisplayed() + .then(function(isDisplayed) { + assert.isFalse( + isDisplayed, + "Upload label is hidden while the error is displayed" + ); + }) + .end() + // pick a valid file type + .findByCssSelector("#image") + .type(VALID_IMAGE_PATH) + .end() + // validation message should be gone + .waitForDeletedByCssSelector(".form-upload-error") + .end() + ); + } + } +}); diff --git a/tests/functional/new-issue-non-auth.js b/tests/functional/new-issue-non-auth.js index 2c87401be..efe8874e7 100755 --- a/tests/functional/new-issue-non-auth.js +++ b/tests/functional/new-issue-non-auth.js @@ -1,31 +1,31 @@ -// "use strict"; -// /* 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/. */ -// const intern = require("intern").default; -// const { assert } = intern.getPlugin("chai"); -// const { registerSuite } = intern.getInterface("object"); -// const FunctionalHelpers = require("./lib/helpers.js"); +"use strict"; +/* 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/. */ +const intern = require("intern").default; +const { assert } = intern.getPlugin("chai"); +const { registerSuite } = intern.getInterface("object"); +const FunctionalHelpers = require("./lib/helpers.js"); -// var url = function(path) { -// return intern.config.siteRoot + path; -// }; +var url = function(path) { + return intern.config.siteRoot + path; +}; -// registerSuite("New Issue Page", { -// tests: { -// "new issue page loads"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-Navbar-link" -// ) -// .findByCssSelector(".js-Navbar-link") -// .getVisibleText() -// .then(function(text) { -// assert.include(text, "Home"); -// assert.notInclude(text, "Download our"); -// }) -// .end(); -// } -// } -// }); +registerSuite("New Issue Page", { + tests: { + "new issue page loads"() { + return FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-Navbar-link" + ) + .findByCssSelector(".js-Navbar-link") + .getVisibleText() + .then(function(text) { + assert.include(text, "Home"); + assert.notInclude(text, "Download our"); + }) + .end(); + } + } +}); diff --git a/tests/functional/reporting-auth.js b/tests/functional/reporting-auth.js index 63fcdc929..4028da577 100755 --- a/tests/functional/reporting-auth.js +++ b/tests/functional/reporting-auth.js @@ -1,38 +1,38 @@ -// "use strict"; -// /* 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/. */ -// const intern = require("intern").default; -// const { assert } = intern.getPlugin("chai"); -// const { registerSuite } = intern.getInterface("object"); -// const FunctionalHelpers = require("./lib/helpers.js"); +"use strict"; +/* 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/. */ +const intern = require("intern").default; +const { assert } = intern.getPlugin("chai"); +const { registerSuite } = intern.getInterface("object"); +const FunctionalHelpers = require("./lib/helpers.js"); -// var url = function(path) { -// return intern.config.siteRoot + path; -// }; +var url = function(path) { + return intern.config.siteRoot + path; +}; -// registerSuite("Reporting (auth)", { -// before() { -// return FunctionalHelpers.login(this); -// }, +registerSuite("Reporting (auth)", { + before() { + return FunctionalHelpers.login(this); + }, -// after() { -// return FunctionalHelpers.logout(this); -// }, + after() { + return FunctionalHelpers.logout(this); + }, -// tests: { -// "Report button shows name"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-Navbar-link" -// ) -// .findByCssSelector("#submitgithub") -// .getVisibleText() -// .then(function(text) { -// assert.include(text, "Report as"); //Report as FooUser (logged in) -// }) -// .end(); -// } -// } -// }); + tests: { + "Report button shows name"() { + return FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-Navbar-link" + ) + .findByCssSelector("#submitgithub") + .getVisibleText() + .then(function(text) { + assert.include(text, "Report as"); //Report as FooUser (logged in) + }) + .end(); + } + } +}); diff --git a/tests/functional/reporting-non-auth.js b/tests/functional/reporting-non-auth.js index d2bfcee44..c63de803b 100755 --- a/tests/functional/reporting-non-auth.js +++ b/tests/functional/reporting-non-auth.js @@ -1,421 +1,421 @@ -// "use strict"; -// /* 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/. */ -// const intern = require("intern").default; -// const { assert } = intern.getPlugin("chai"); -// const { registerSuite } = intern.getInterface("object"); -// const FunctionalHelpers = require("./lib/helpers.js"); -// const path = require("path"); +"use strict"; +/* 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/. */ +const intern = require("intern").default; +const { assert } = intern.getPlugin("chai"); +const { registerSuite } = intern.getInterface("object"); +const FunctionalHelpers = require("./lib/helpers.js"); +const path = require("path"); -// var cwd = intern.config.basePath; -// var VALID_IMAGE_PATH = path.join(cwd, "tests/fixtures", "green_square.png"); -// // DETAILS_STRING is a URL encoded object, stringified to JSON. -// var DETAILS_STRING = -// '{"gfx.webrender.all"%3Afalse%2C"gfx.webrender.blob-images"%3A2%2C"gfx.webrender.enabled"%3Afalse%2C"image.mem.shared"%3A2%2C"layout.css.servo.enabled"%3Atrue}'; +var cwd = intern.config.basePath; +var VALID_IMAGE_PATH = path.join(cwd, "tests/fixtures", "green_square.png"); +// DETAILS_STRING is a URL encoded object, stringified to JSON. +var DETAILS_STRING = + '{"gfx.webrender.all"%3Afalse%2C"gfx.webrender.blob-images"%3A2%2C"gfx.webrender.enabled"%3Afalse%2C"image.mem.shared"%3A2%2C"layout.css.servo.enabled"%3Atrue}'; -// var url = function(path) { -// return intern.config.siteRoot + path; -// }; +var url = function(path) { + return intern.config.siteRoot + path; +}; -// registerSuite("Reporting (non-auth)", { -// tests: { -// "Submit buttons are disabled"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-report-buttons" -// ) -// .findAllByCssSelector(".js-report-buttons button") -// .getAttribute("disabled") -// .then(function(values) { -// values.forEach(function(value) { -// assert.isNotNull(value); -// }); -// }) -// .end(); -// }, +registerSuite("Reporting (non-auth)", { + tests: { + "Submit buttons are disabled"() { + return FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-report-buttons" + ) + .findAllByCssSelector(".js-report-buttons button") + .getAttribute("disabled") + .then(function(values) { + values.forEach(function(value) { + assert.isNotNull(value); + }); + }) + .end(); + }, -// "Wyciwyg bug workaround"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues/new?url=wyciwyg://0/http://bbs.csdn.net/topics/20282413"), -// "#url" -// ) -// .findByCssSelector("#url") -// .getProperty("value") -// .then(function(value) { -// assert.notInclude(value, "wyciwyg://0/"); -// }) -// .end(); -// }, + "Wyciwyg bug workaround"() { + return FunctionalHelpers.openPage( + this, + url("/issues/new?url=wyciwyg://0/http://bbs.csdn.net/topics/20282413"), + "#url" + ) + .findByCssSelector("#url") + .getProperty("value") + .then(function(value) { + assert.notInclude(value, "wyciwyg://0/"); + }) + .end(); + }, -// "Report button shows via GitHub"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-report-buttons" -// ) -// .findByCssSelector("#submitgithub") -// .getVisibleText() -// .then(function(text) { -// assert.include(text, "Report via"); //Report via GitHub (logged out) -// }) -// .end(); -// }, + "Report button shows via GitHub"() { + return FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-report-buttons" + ) + .findByCssSelector("#submitgithub") + .getVisibleText() + .then(function(text) { + assert.include(text, "Report via"); //Report via GitHub (logged out) + }) + .end(); + }, -// "space in domain name validation"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-report-buttons" -// ) -// .findByCssSelector("#url") -// .click() -// .type("http:// example.com") -// .end() -// .execute(function() { -// var elm = document.querySelector("#url"); -// WindowHelpers.sendEvent(elm, "blur"); -// }) -// .sleep(500) -// .findByCssSelector(".form-message-error"); -// }, + "space in domain name validation"() { + return FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-report-buttons" + ) + .findByCssSelector("#url") + .click() + .type("http:// example.com") + .end() + .execute(function() { + var elm = document.querySelector("#url"); + WindowHelpers.sendEvent(elm, "blur"); + }) + .sleep(500) + .findByCssSelector(".form-message-error"); + }, -// "URL validation"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-report-buttons" -// ) -// .findByCssSelector("#url") -// .click() -// .type("sup") -// .end() -// .sleep(500) -// .execute(function() { -// var elm = document.querySelector("#url"); -// WindowHelpers.sendEvent(elm, "blur"); -// }) -// .findByCssSelector(".form-message-error") -// .getVisibleText() -// .then(function(texts) { -// assert.include( -// texts, -// "A valid URL is required", -// "URL validation message is shown" -// ); -// }) -// .end() -// .findByCssSelector("#url") -// .clearValue() -// .type("http://sup.com") -// .end() -// .waitForDeletedByCssSelector(".form-message-error") -// .end(); -// }, + "URL validation"() { + return FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-report-buttons" + ) + .findByCssSelector("#url") + .click() + .type("sup") + .end() + .sleep(500) + .execute(function() { + var elm = document.querySelector("#url"); + WindowHelpers.sendEvent(elm, "blur"); + }) + .findByCssSelector(".form-message-error") + .getVisibleText() + .then(function(texts) { + assert.include( + texts, + "A valid URL is required", + "URL validation message is shown" + ); + }) + .end() + .findByCssSelector("#url") + .clearValue() + .type("http://sup.com") + .end() + .waitForDeletedByCssSelector(".form-message-error") + .end(); + }, -// "Description validation"() { -// return ( -// FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-report-buttons" -// ) -// .findByCssSelector("#url") -// .type("http://coolguy.biz") -// .end() -// // pick a problem type -// .findByCssSelector("[for=problem_category-0]") -// .click() -// .end() -// .findByCssSelector(".js-Button-wrapper") -// .click() -// .end() -// .sleep(500) -// .findByCssSelector(".form-message-error") -// .getVisibleText() -// .then(function(text) { -// assert.include( -// text, -// "A problem summary is required", -// "Problem summary validation message is shown" -// ); -// }) -// .end() -// // enter a bug description -// .findByCssSelector("#description") -// .type("bug description") -// .end() -// // validation message should be gone -// .waitForDeletedByCssSelector(".form-message-error") -// .end() -// ); -// }, + "Description validation"() { + return ( + FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-report-buttons" + ) + .findByCssSelector("#url") + .type("http://coolguy.biz") + .end() + // pick a problem type + .findByCssSelector("[for=problem_category-0]") + .click() + .end() + .findByCssSelector(".js-Button-wrapper") + .click() + .end() + .sleep(500) + .findByCssSelector(".form-message-error") + .getVisibleText() + .then(function(text) { + assert.include( + text, + "A problem summary is required", + "Problem summary validation message is shown" + ); + }) + .end() + // enter a bug description + .findByCssSelector("#description") + .type("bug description") + .end() + // validation message should be gone + .waitForDeletedByCssSelector(".form-message-error") + .end() + ); + }, -// "(optional) browser + os validation"() { -// return ( -// FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-report-buttons" -// ) -// // make sure we can see the valid checkbox (i.e. it's background image is non-empty) -// .execute(function() { -// return window -// .getComputedStyle( -// document.querySelector(".js-bug-form-os"), -// ":after" -// ) -// .getPropertyValue("background-image"); -// }) -// .then(function(bgImage) { -// assert.include( -// bgImage, -// "checkmark.svg", -// "The valid checkbox pseudo is visible" -// ); -// }) -// .end() -// .execute(function() { -// var elm = document.querySelector("#os"); -// elm.value = ""; -// WindowHelpers.sendEvent(elm, "blur"); -// }) -// .end() -// .sleep(500) -// // make sure we can't see the valid checkbox (i.e. it's background image is empty) -// .execute(function() { -// return window -// .getComputedStyle( -// document.querySelector(".js-bug-form-os"), -// ":after" -// ) -// .getPropertyValue("background-image"); -// }) -// .then(function(bgImage) { -// assert.notInclude( -// bgImage, -// "checkmark.svg", -// "The valid checkbox pseudo is not visible" -// ); -// }) -// .end() -// ); -// }, + "(optional) browser + os validation"() { + return ( + FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-report-buttons" + ) + // make sure we can see the valid checkbox (i.e. it's background image is non-empty) + .execute(function() { + return window + .getComputedStyle( + document.querySelector(".js-bug-form-os"), + ":after" + ) + .getPropertyValue("background-image"); + }) + .then(function(bgImage) { + assert.include( + bgImage, + "checkmark.svg", + "The valid checkbox pseudo is visible" + ); + }) + .end() + .execute(function() { + var elm = document.querySelector("#os"); + elm.value = ""; + WindowHelpers.sendEvent(elm, "blur"); + }) + .end() + .sleep(500) + // make sure we can't see the valid checkbox (i.e. it's background image is empty) + .execute(function() { + return window + .getComputedStyle( + document.querySelector(".js-bug-form-os"), + ":after" + ) + .getPropertyValue("background-image"); + }) + .then(function(bgImage) { + assert.notInclude( + bgImage, + "checkmark.svg", + "The valid checkbox pseudo is not visible" + ); + }) + .end() + ); + }, -// "Submits are enabled"() { -// return ( -// FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-report-buttons" -// ) -// // pick a valid file type -// .findByCssSelector("#image") -// .type(VALID_IMAGE_PATH) -// .end() -// .findByCssSelector("#url") -// .type("http://coolguy.biz") -// .end() -// // pick a problem type -// .findByCssSelector("[for=problem_category-0]") -// .click() -// .end() -// .findByCssSelector("#description") -// .type("test for desktop site") -// //.click() -// .end() -// // wait a bit -// .sleep(250) -// // now make sure the buttons aren't disabled anymore -// .findAllByCssSelector(".js-report-buttons button") -// .getAttribute("disabled") -// .then(function(values) { -// values.forEach(function(value) { -// assert.isNull(value); -// }); -// }) -// .end() -// ); -// }, + "Submits are enabled"() { + return ( + FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-report-buttons" + ) + // pick a valid file type + .findByCssSelector("#image") + .type(VALID_IMAGE_PATH) + .end() + .findByCssSelector("#url") + .type("http://coolguy.biz") + .end() + // pick a problem type + .findByCssSelector("[for=problem_category-0]") + .click() + .end() + .findByCssSelector("#description") + .type("test for desktop site") + //.click() + .end() + // wait a bit + .sleep(250) + // now make sure the buttons aren't disabled anymore + .findAllByCssSelector(".js-report-buttons button") + .getAttribute("disabled") + .then(function(values) { + values.forEach(function(value) { + assert.isNull(value); + }); + }) + .end() + ); + }, -// "problem_type param selects problem type"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues/new?problem_type=video_bug"), -// ".js-report-buttons" -// ) -// .findByCssSelector("[value=video_bug]") -// .isSelected() -// .then(function(isSelected) { -// assert.isTrue(isSelected, "The right option is selected"); -// }) -// .end(); -// }, + "problem_type param selects problem type"() { + return FunctionalHelpers.openPage( + this, + url("/issues/new?problem_type=video_bug"), + ".js-report-buttons" + ) + .findByCssSelector("[value=video_bug]") + .isSelected() + .then(function(isSelected) { + assert.isTrue(isSelected, "The right option is selected"); + }) + .end(); + }, -// "details param doesn't add info to description"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues/new?details=" + DETAILS_STRING), -// "#description" -// ) -// .findByCssSelector("#steps_reproduce") -// .getProperty("value") -// .then(function(text) { -// assert.notInclude( -// text, -// "gfx.webrender.all", -// "details param is added after reporting (legacy or not)" -// ); -// }); -// }, + "details param doesn't add info to description"() { + return FunctionalHelpers.openPage( + this, + url("/issues/new?details=" + DETAILS_STRING), + "#description" + ) + .findByCssSelector("#steps_reproduce") + .getProperty("value") + .then(function(text) { + assert.notInclude( + text, + "gfx.webrender.all", + "details param is added after reporting (legacy or not)" + ); + }); + }, -// "GitHub contact name with a leading @"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-report-buttons" -// ) -// .findByCssSelector("#contact") -// .click() -// .type("@webcompat-bot") -// .end() -// .sleep(500) -// .findByCssSelector(".form-message-error") -// .getVisibleText() -// .then(function(text) { -// assert.include( -// text, -// "GitHub nicknames are 39", -// "contact validation message is shown" -// ); -// }) -// .end(); -// }, + "GitHub contact name with a leading @"() { + return FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-report-buttons" + ) + .findByCssSelector("#contact") + .click() + .type("@webcompat-bot") + .end() + .sleep(500) + .findByCssSelector(".form-message-error") + .getVisibleText() + .then(function(text) { + assert.include( + text, + "GitHub nicknames are 39", + "contact validation message is shown" + ); + }) + .end(); + }, -// "Mixed and lowercase GitHub usernames are valid"() { -// return ( -// FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-report-buttons" -// ) -// .findByCssSelector("#contact") -// .click() -// .type("WebCompat-Bot") -// .end() -// .sleep(500) -// // make sure we can see the valid checkbox (i.e. it's background image is non-empty) -// .execute(function() { -// return window -// .getComputedStyle( -// document.querySelector(".js-bug-form-contact"), -// ":after" -// ) -// .getPropertyValue("background-image"); -// }) -// .then(function(bgImage) { -// assert.include( -// bgImage, -// "checkmark.svg", -// "The valid checkbox pseudo is visible" -// ); -// }) -// .end() -// .findByCssSelector("#contact") -// .click() -// .type("webcompat-bot") -// .end() -// .sleep(500) -// // make sure we can see the valid checkbox (i.e. it's background image is non-empty) -// .execute(function() { -// return window -// .getComputedStyle( -// document.querySelector(".js-bug-form-contact"), -// ":after" -// ) -// .getPropertyValue("background-image"); -// }) -// .then(function(bgImage) { -// assert.include( -// bgImage, -// "checkmark.svg", -// "The valid checkbox pseudo is visible" -// ); -// }) -// .end() -// ); -// }, + "Mixed and lowercase GitHub usernames are valid"() { + return ( + FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-report-buttons" + ) + .findByCssSelector("#contact") + .click() + .type("WebCompat-Bot") + .end() + .sleep(500) + // make sure we can see the valid checkbox (i.e. it's background image is non-empty) + .execute(function() { + return window + .getComputedStyle( + document.querySelector(".js-bug-form-contact"), + ":after" + ) + .getPropertyValue("background-image"); + }) + .then(function(bgImage) { + assert.include( + bgImage, + "checkmark.svg", + "The valid checkbox pseudo is visible" + ); + }) + .end() + .findByCssSelector("#contact") + .click() + .type("webcompat-bot") + .end() + .sleep(500) + // make sure we can see the valid checkbox (i.e. it's background image is non-empty) + .execute(function() { + return window + .getComputedStyle( + document.querySelector(".js-bug-form-contact"), + ":after" + ) + .getPropertyValue("background-image"); + }) + .then(function(bgImage) { + assert.include( + bgImage, + "checkmark.svg", + "The valid checkbox pseudo is visible" + ); + }) + .end() + ); + }, -// "GitHub contact name with two consecutives --"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-report-buttons" -// ) -// .findByCssSelector("#contact") -// .click() -// .type("wrong--name") -// .end() -// .sleep(500) -// .findByCssSelector(".form-message-error") -// .getVisibleText() -// .then(function(text) { -// assert.include( -// text, -// "GitHub nicknames are 39", -// "contact validation message is shown" -// ); -// }) -// .end(); -// }, + "GitHub contact name with two consecutives --"() { + return FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-report-buttons" + ) + .findByCssSelector("#contact") + .click() + .type("wrong--name") + .end() + .sleep(500) + .findByCssSelector(".form-message-error") + .getVisibleText() + .then(function(text) { + assert.include( + text, + "GitHub nicknames are 39", + "contact validation message is shown" + ); + }) + .end(); + }, -// "GitHub contact name too long"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-report-buttons" -// ) -// .findByCssSelector("#contact") -// .click() -// .type("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") -// .end() -// .sleep(500) -// .findByCssSelector(".form-message-error") -// .getVisibleText() -// .then(function(text) { -// assert.include( -// text, -// "GitHub nicknames are 39", -// "contact validation message is shown" -// ); -// }) -// .end(); -// }, -// "Submitting form without filling anything"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-report-buttons" -// ) -// .findByCssSelector(".js-Button-wrapper") -// .click() -// .end() -// .sleep(500) -// .findAllByCssSelector(".form-message-error") -// .getVisibleText() -// .then(function(texts) { -// var errorTexts = [ -// "A valid URL is required.", -// "Problem type required.", -// "A problem summary is required." -// ]; -// errorTexts.forEach(function(expectedText) { -// assert.include(texts, expectedText, "Error messages don't match"); -// }); -// }) -// .end(); -// } -// } -// }); + "GitHub contact name too long"() { + return FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-report-buttons" + ) + .findByCssSelector("#contact") + .click() + .type("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") + .end() + .sleep(500) + .findByCssSelector(".form-message-error") + .getVisibleText() + .then(function(text) { + assert.include( + text, + "GitHub nicknames are 39", + "contact validation message is shown" + ); + }) + .end(); + }, + "Submitting form without filling anything"() { + return FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-report-buttons" + ) + .findByCssSelector(".js-Button-wrapper") + .click() + .end() + .sleep(500) + .findAllByCssSelector(".form-message-error") + .getVisibleText() + .then(function(texts) { + var errorTexts = [ + "A valid URL is required.", + "Problem type required.", + "A problem summary is required." + ]; + errorTexts.forEach(function(expectedText) { + assert.include(texts, expectedText, "Error messages don't match"); + }); + }) + .end(); + } + } +}); diff --git a/tests/functional/reporting-postMessage.js b/tests/functional/reporting-postMessage.js index b848ff95b..a6683a5a7 100644 --- a/tests/functional/reporting-postMessage.js +++ b/tests/functional/reporting-postMessage.js @@ -1,52 +1,52 @@ -// "use strict"; -// /* 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/. */ -// const intern = require("intern").default; -// const { assert } = intern.getPlugin("chai"); -// const { registerSuite } = intern.getInterface("object"); -// const FunctionalHelpers = require("./lib/helpers.js"); +"use strict"; +/* 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/. */ +const intern = require("intern").default; +const { assert } = intern.getPlugin("chai"); +const { registerSuite } = intern.getInterface("object"); +const FunctionalHelpers = require("./lib/helpers.js"); -// const url = intern.config.siteRoot + "/issues/new"; +const url = intern.config.siteRoot + "/issues/new"; -// // This string is executed by calls to `execute()` in various tests -// // it postMessages a small green test square. -// const POSTMESSAGE_TEST = -// 'postMessage({screenshot:{}, message: {"url":"http://example.com","utm_source":"desktop-reporter","utm_campaign":"report-site-issue-button","src":"desktop-reporter","details":{"gfx.webrender.all":false,"gfx.webrender.blob-images":true,"gfx.webrender.enabled":false,"image.mem.shared":true,"buildID":"20191016225400","channel":"default","consoleLog":[],"hasTouchScreen":false,"mixed active content blocked":false,"mixed passive content blocked":false,"tracking content blocked":"false","hasMarfeel":true},"extra_labels":["type-marfeel"]}}, "http://localhost:5000")'; +// This string is executed by calls to `execute()` in various tests +// it postMessages a small green test square. +const POSTMESSAGE_TEST = + 'postMessage({screenshot:{}, message: {"url":"http://example.com","utm_source":"desktop-reporter","utm_campaign":"report-site-issue-button","src":"desktop-reporter","details":{"gfx.webrender.all":false,"gfx.webrender.blob-images":true,"gfx.webrender.enabled":false,"image.mem.shared":true,"buildID":"20191016225400","channel":"default","consoleLog":[],"hasTouchScreen":false,"mixed active content blocked":false,"mixed passive content blocked":false,"tracking content blocked":"false","hasMarfeel":true},"extra_labels":["type-marfeel"]}}, "http://localhost:5000")'; -// registerSuite("Reporting through postMessage", { -// tests: { -// "postMessaged object"() { -// return ( -// FunctionalHelpers.openPage(this, url, ".js-report-buttons") -// // send data object through postMessage -// .execute(POSTMESSAGE_TEST) -// .sleep(1000) -// .findByCssSelector("#url") -// .getProperty("value") -// .then(function(value) { -// assert.include(value, "http://example.com"); -// }) -// .end() -// .findByCssSelector("#details") -// .getProperty("value") -// .then(function(value) { -// assert.include(value, "gfx.webrender.all"); -// }) -// .end() -// .findByCssSelector("#reported_with") -// .getProperty("value") -// .then(function(value) { -// assert.include(value, "desktop-reporter"); -// }) -// .end() -// .findByCssSelector("#extra_labels") -// .getProperty("value") -// .then(function(value) { -// assert.include(value, "type-marfeel"); -// }) -// .end() -// ); -// } -// } -// }); +registerSuite("Reporting through postMessage", { + tests: { + "postMessaged object"() { + return ( + FunctionalHelpers.openPage(this, url, ".js-report-buttons") + // send data object through postMessage + .execute(POSTMESSAGE_TEST) + .sleep(1000) + .findByCssSelector("#url") + .getProperty("value") + .then(function(value) { + assert.include(value, "http://example.com"); + }) + .end() + .findByCssSelector("#details") + .getProperty("value") + .then(function(value) { + assert.include(value, "gfx.webrender.all"); + }) + .end() + .findByCssSelector("#reported_with") + .getProperty("value") + .then(function(value) { + assert.include(value, "desktop-reporter"); + }) + .end() + .findByCssSelector("#extra_labels") + .getProperty("value") + .then(function(value) { + assert.include(value, "type-marfeel"); + }) + .end() + ); + } + } +}); diff --git a/tests/functional/search-auth.js b/tests/functional/search-auth.js index 22eae6b2f..b153d1f73 100755 --- a/tests/functional/search-auth.js +++ b/tests/functional/search-auth.js @@ -1,277 +1,277 @@ -// "use strict"; -// /* 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/. */ -// const intern = require("intern").default; -// const { assert } = intern.getPlugin("chai"); -// const { registerSuite } = intern.getInterface("object"); -// const FunctionalHelpers = require("./lib/helpers.js"); +"use strict"; +/* 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/. */ +const intern = require("intern").default; +const { assert } = intern.getPlugin("chai"); +const { registerSuite } = intern.getInterface("object"); +const FunctionalHelpers = require("./lib/helpers.js"); -// var url = function(path, params) { -// var fullUrl = -// params !== undefined -// ? intern.config.siteRoot + path + params -// : intern.config.siteRoot + path; -// return fullUrl; -// }; +var url = function(path, params) { + var fullUrl = + params !== undefined + ? intern.config.siteRoot + path + params + : intern.config.siteRoot + path; + return fullUrl; +}; -// registerSuite("Search (auth)", { -// before() { -// return FunctionalHelpers.login(this); -// }, +registerSuite("Search (auth)", { + before() { + return FunctionalHelpers.login(this); + }, -// after() { -// return FunctionalHelpers.logout(this); -// }, + after() { + return FunctionalHelpers.logout(this); + }, -// tests: { -// "Search/filter interaction"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues"), -// ".js-SearchForm-button" -// ) -// .findDisplayedByCssSelector(".js-SearchForm-button") -// .click() -// .type("taco") -// .end() -// .findAllByCssSelector(".needsdiagnosis.js-Tag") -// .click() -// .end() -// .findByCssSelector("#js-SearchForm-input") -// .getVisibleText() -// .then(function(text) { -// assert.equal(text, "", "Clicking filter should empty search text"); -// }) -// .end() -// .findAllByCssSelector(".needsdiagnosis.js-Tag") -// .click() -// .end() -// .findByCssSelector(".js-SearchForm-button") -// .click() -// .type("taco") -// .end() -// .findAllByCssSelector(".needsdiagnosis.js-Tag") -// .getAttribute("class") -// .then(function(className) { -// assert.notInclude( -// className, -// "is-active", -// "Searching should clear all filters" -// ); -// }) -// .end(); -// }, + tests: { + "Search/filter interaction"() { + return FunctionalHelpers.openPage( + this, + url("/issues"), + ".js-SearchForm-button" + ) + .findDisplayedByCssSelector(".js-SearchForm-button") + .click() + .type("taco") + .end() + .findAllByCssSelector(".needsdiagnosis.js-Tag") + .click() + .end() + .findByCssSelector("#js-SearchForm-input") + .getVisibleText() + .then(function(text) { + assert.equal(text, "", "Clicking filter should empty search text"); + }) + .end() + .findAllByCssSelector(".needsdiagnosis.js-Tag") + .click() + .end() + .findByCssSelector(".js-SearchForm-button") + .click() + .type("taco") + .end() + .findAllByCssSelector(".needsdiagnosis.js-Tag") + .getAttribute("class") + .then(function(className) { + assert.notInclude( + className, + "is-active", + "Searching should clear all filters" + ); + }) + .end(); + }, -// "Results are loaded from the query params"() { -// var params = -// "?page=1&per_page=50&state=open&stage=all&sort=created&direction=desc&q=vladvlad"; -// return FunctionalHelpers.openPage( -// this, -// url("/issues", params), -// ".js-IssueList:nth-of-type(1)" -// ) -// .findDisplayedByCssSelector(".js-IssueList:nth-of-type(1) a") -// .getVisibleText() -// .then(function(text) { -// assert.include( -// text, -// "vladvlad", -// "The search query results show up on the page." -// ); -// }) -// .end() -// .getCurrentUrl() -// .then(function(currUrl) { -// assert.include( -// currUrl, -// "q=vladvlad", -// "Our params didn't go anywhere." -// ); -// }) -// .end(); -// }, + "Results are loaded from the query params"() { + var params = + "?page=1&per_page=50&state=open&stage=all&sort=created&direction=desc&q=vladvlad"; + return FunctionalHelpers.openPage( + this, + url("/issues", params), + ".js-IssueList:nth-of-type(1)" + ) + .findDisplayedByCssSelector(".js-IssueList:nth-of-type(1) a") + .getVisibleText() + .then(function(text) { + assert.include( + text, + "vladvlad", + "The search query results show up on the page." + ); + }) + .end() + .getCurrentUrl() + .then(function(currUrl) { + assert.include( + currUrl, + "q=vladvlad", + "Our params didn't go anywhere." + ); + }) + .end(); + }, -// "Search works by icon click (issues page)"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues"), -// ".js-IssueList:nth-of-type(10)" -// ) -// .findByCssSelector(".js-SearchForm input") -// .type("vladvlad") -// .end() -// .findByCssSelector(".js-SearchForm button") -// .click() -// .end() -// .findDisplayedByCssSelector(".js-IssueList:only-of-type a") -// .getVisibleText() -// .then(function(text) { -// assert.include( -// text, -// "vladvlad", -// "The search results show up on the page." -// ); -// }) -// .end(); -// }, + "Search works by icon click (issues page)"() { + return FunctionalHelpers.openPage( + this, + url("/issues"), + ".js-IssueList:nth-of-type(10)" + ) + .findByCssSelector(".js-SearchForm input") + .type("vladvlad") + .end() + .findByCssSelector(".js-SearchForm button") + .click() + .end() + .findDisplayedByCssSelector(".js-IssueList:only-of-type a") + .getVisibleText() + .then(function(text) { + assert.include( + text, + "vladvlad", + "The search results show up on the page." + ); + }) + .end(); + }, -// "Search opens by icon click (new issue page)"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues/new"), -// ".js-ReportForm" -// ) -// .findByCssSelector(".js-SearchBarOpen") -// .click() -// .end() -// .findDisplayedByCssSelector("#search-bar") -// .isDisplayed() -// .then(function(isDisplayed) { -// assert.equal(isDisplayed, true, "Search form is visible."); -// }) -// .end(); -// }, + "Search opens by icon click (new issue page)"() { + return FunctionalHelpers.openPage( + this, + url("/issues/new"), + ".js-ReportForm" + ) + .findByCssSelector(".js-SearchBarOpen") + .click() + .end() + .findDisplayedByCssSelector("#search-bar") + .isDisplayed() + .then(function(isDisplayed) { + assert.equal(isDisplayed, true, "Search form is visible."); + }) + .end(); + }, -// "Search works by icon click (home page)"() { -// return FunctionalHelpers.openPage(this, url("/"), ".js-SearchBarOpen") -// .findByCssSelector(".js-SearchBarOpen") -// .click() -// .end() -// .findDisplayedByCssSelector("#search-bar") -// .isDisplayed() -// .then(function(isDisplayed) { -// assert.equal(isDisplayed, true, "Search form is visible."); -// }) -// .end(); -// }, + "Search works by icon click (home page)"() { + return FunctionalHelpers.openPage(this, url("/"), ".js-SearchBarOpen") + .findByCssSelector(".js-SearchBarOpen") + .click() + .end() + .findDisplayedByCssSelector("#search-bar") + .isDisplayed() + .then(function(isDisplayed) { + assert.equal(isDisplayed, true, "Search form is visible."); + }) + .end(); + }, -// "Search works by Return key"() { -// return FunctionalHelpers.openPage( -// this, -// url("/issues"), -// ".js-SearchForm input" -// ) -// .findDisplayedByCssSelector(".js-SearchForm input") -// .type("vladvlad") -// .type("\uE007") -// .end() -// .findDisplayedByCssSelector(".js-IssueList:only-of-type a") -// .getVisibleText() -// .then(function(text) { -// assert.include( -// text, -// "vladvlad", -// "The search results show up on the page." -// ); -// }) -// .end(); -// }, + "Search works by Return key"() { + return FunctionalHelpers.openPage( + this, + url("/issues"), + ".js-SearchForm input" + ) + .findDisplayedByCssSelector(".js-SearchForm input") + .type("vladvlad") + .type("\uE007") + .end() + .findDisplayedByCssSelector(".js-IssueList:only-of-type a") + .getVisibleText() + .then(function(text) { + assert.include( + text, + "vladvlad", + "The search results show up on the page." + ); + }) + .end(); + }, -// "Search from the homepage"() { -// return ( -// FunctionalHelpers.openPage(this, url("/"), ".js-SearchBarOpen") -// .get(url("/")) -// .findByCssSelector(".js-SearchBarOpen") -// .click() -// .end() -// // Wait for animation to complete. -// .sleep(1000) -// .findByCssSelector(".js-SearchBar input") -// .click() -// .type("vladvlad") -// .type("\uE007") -// .end() -// .findDisplayedByCssSelector(".js-IssueList:only-of-type a") -// .getVisibleText() -// .then(function(text) { -// assert.include( -// text, -// "vladvlad", -// "The search query results show up on the page." -// ); -// }) -// .end() -// .getCurrentUrl() -// .then(function(currUrl) { -// assert.include(currUrl, "page=1", "Default params got merged."); -// }) -// .end() -// ); -// }, + "Search from the homepage"() { + return ( + FunctionalHelpers.openPage(this, url("/"), ".js-SearchBarOpen") + .get(url("/")) + .findByCssSelector(".js-SearchBarOpen") + .click() + .end() + // Wait for animation to complete. + .sleep(1000) + .findByCssSelector(".js-SearchBar input") + .click() + .type("vladvlad") + .type("\uE007") + .end() + .findDisplayedByCssSelector(".js-IssueList:only-of-type a") + .getVisibleText() + .then(function(text) { + assert.include( + text, + "vladvlad", + "The search query results show up on the page." + ); + }) + .end() + .getCurrentUrl() + .then(function(currUrl) { + assert.include(currUrl, "page=1", "Default params got merged."); + }) + .end() + ); + }, -// "Search with a dash works"() { -// // load up a garbage search, so we can more easily detect when -// // the search values we want are loaded. -// var searchParam = "?q=jfdkjfkdjfkdjfdkjfkd"; -// return FunctionalHelpers.openPage( -// this, -// url("/issues", searchParam), -// ".js-no-results" -// ) -// .findByCssSelector("#js-SearchForm-input") -// .clearValue() -// .click() -// .type("label:status-tacos") -// .type("\uE007") -// .end() -// .findDisplayedByCssSelector( -// ".js-IssueList:first-of-type .js-Issue-label" -// ) -// .getVisibleText() -// .then(function(text) { -// assert.include( -// text, -// "tacos", -// "The label:status-tacos search worked." -// ); -// }) -// .end(); -// }, + "Search with a dash works"() { + // load up a garbage search, so we can more easily detect when + // the search values we want are loaded. + var searchParam = "?q=jfdkjfkdjfkdjfdkjfkd"; + return FunctionalHelpers.openPage( + this, + url("/issues", searchParam), + ".js-no-results" + ) + .findByCssSelector("#js-SearchForm-input") + .clearValue() + .click() + .type("label:status-tacos") + .type("\uE007") + .end() + .findDisplayedByCssSelector( + ".js-IssueList:first-of-type .js-Issue-label" + ) + .getVisibleText() + .then(function(text) { + assert.include( + text, + "tacos", + "The label:status-tacos search worked." + ); + }) + .end(); + }, -// "After search without results, suggested label appear and have a clickable URL."() { -// return FunctionalHelpers.openPage(this, url("/issues"), ".grid") -// .findByCssSelector("#js-SearchForm-input") -// .click() -// .type("noExpectedResult123") -// .end() -// .findByCssSelector("#x-search-bar") -// .submit() -// .end() -// .sleep(2000) -// .findDisplayedByCssSelector(".label-browser-android") -// .click() -// .end() -// .getCurrentUrl() -// .then(function(url) { -// assert( -// url.includes( -// "q=label%3Abrowser-android", -// "Redirect from a suggested label goes to correct URL." -// ) -// ); -// }); -// }, + "After search without results, suggested label appear and have a clickable URL."() { + return FunctionalHelpers.openPage(this, url("/issues"), ".grid") + .findByCssSelector("#js-SearchForm-input") + .click() + .type("noExpectedResult123") + .end() + .findByCssSelector("#x-search-bar") + .submit() + .end() + .sleep(2000) + .findDisplayedByCssSelector(".label-browser-android") + .click() + .end() + .getCurrentUrl() + .then(function(url) { + assert( + url.includes( + "q=label%3Abrowser-android", + "Redirect from a suggested label goes to correct URL." + ) + ); + }); + }, -// "Search input is loaded from q param (with dashes)"() { -// // load up a garbage search, so we can more easily detect when -// // the search values we want are loaded. -// var searchParam = "?q=one:two-three"; -// return FunctionalHelpers.openPage( -// this, -// url("/issues", searchParam), -// ".js-no-results" -// ) -// .findByCssSelector("#js-SearchForm-input") -// .getProperty("value") -// .then(function(text) { -// assert.include( -// text, -// "one:two-three", -// "The q param populated the search input." -// ); -// }) -// .end(); -// } -// } -// }); + "Search input is loaded from q param (with dashes)"() { + // load up a garbage search, so we can more easily detect when + // the search values we want are loaded. + var searchParam = "?q=one:two-three"; + return FunctionalHelpers.openPage( + this, + url("/issues", searchParam), + ".js-no-results" + ) + .findByCssSelector("#js-SearchForm-input") + .getProperty("value") + .then(function(text) { + assert.include( + text, + "one:two-three", + "The q param populated the search input." + ); + }) + .end(); + } + } +}); diff --git a/tests/unit/test_form.py b/tests/unit/test_form.py index 8fbcf57e7..523b17e49 100644 --- a/tests/unit/test_form.py +++ b/tests/unit/test_form.py @@ -294,9 +294,7 @@ def test_report_issue_anonymous_fails_with_wrong_credentials(self): submit_type='punkcat-submit', url='http://testing.example.org', username='yeeha')) - # temprorarily return the maintenance page - self.assertEqual(rv.status_code, 200) - # self.assertEqual(rv.status_code, 400) + self.assertEqual(rv.status_code, 400) if __name__ == '__main__': diff --git a/tests/unit/test_rendering.py b/tests/unit/test_rendering.py index 443a232b6..c56819171 100644 --- a/tests/unit/test_rendering.py +++ b/tests/unit/test_rendering.py @@ -52,8 +52,7 @@ def test_titles(self): ('/contributors', 'Contributors'), ('/issues/' + issue_number, 'Issue #' + issue_number), ('/issues', 'Issues'), - # FIXME: This should be 'New Issue' when #3118 is fixed - ('issues/new', 'Oops!'), + ('issues/new', 'New Issue'), ('/privacy', 'Privacy Policy'), ('/404', default_title) ] @@ -103,15 +102,14 @@ def test_addon_link(self): expected = b'Give Feedback' self.assertTrue(expected in rv.data) - # FIXME: uncomment when #3118 is fixed - # def test_form_rendering(self): - # """Double Check that the form is properly populated.""" - # url = '/issues/new?url=http://example.com/&label=type-stylo' - # headers = {'HTTP_USER_AGENT': FIREFOX_UA} - # rv = self.app.get(url, environ_base=headers) - # self.assertTrue(b'Firefox 61.0' in rv.data) - # self.assertTrue(b'Mac OS X 10.13' in rv.data) - # self.assertTrue(b'http://example.com/' in rv.data) + def test_form_rendering(self): + """Double Check that the form is properly populated.""" + url = '/issues/new?url=http://example.com/&label=type-stylo' + headers = {'HTTP_USER_AGENT': FIREFOX_UA} + rv = self.app.get(url, environ_base=headers) + self.assertTrue(b'Firefox 61.0' in rv.data) + self.assertTrue(b'Mac OS X 10.13' in rv.data) + self.assertTrue(b'http://example.com/' in rv.data) def test_wellknown_subpath(self): """Test that the /.wellknown/subpath route gets 404.""" diff --git a/tests/unit/test_urls.py b/tests/unit/test_urls.py index 2f797aa3a..b6fd20368 100644 --- a/tests/unit/test_urls.py +++ b/tests/unit/test_urls.py @@ -71,13 +71,11 @@ def test_successful_post_new_issue(self, mock_proxy): submit_type='github-proxy-report', url='http://testing.example.org', username='yeeha')) - # temprorarily return the maintenance page - self.assertEqual(rv.status_code, 200) - # self.assertEqual(rv.status_code, 302) - # self.assertEqual( - # rv.headers['Location'], 'http://localhost/issues/1544') - # self.assertTrue( - # b'/issues/1544' in rv.data) + self.assertEqual(rv.status_code, 302) + self.assertEqual( + rv.headers['Location'], 'http://localhost/issues/1544') + self.assertTrue( + b'/issues/1544' in rv.data) @patch('webcompat.issues.proxy_request') def test_fail_post_new_issue(self, mock_proxy): @@ -96,9 +94,7 @@ def test_fail_post_new_issue(self, mock_proxy): problem_category='what', submit_type='github-proxy-report', username='PunkCat',)) - # temporarily return the maintenance page - self.assertEqual(rv.status_code, 200) - # self.assertEqual(rv.status_code, 400) + self.assertEqual(rv.status_code, 400) def test_about(self): """Test that /about exists.""" @@ -213,9 +209,7 @@ def test_missing_parameters_for_new_issue(self): rv = self.app.post('/issues/new', content_type='multipart/form-data', data=dict(url='foo')) - # temporarily return the maintenance page - self.assertEqual(rv.status_code, 200) - # self.assertEqual(rv.status_code, 400) + self.assertEqual(rv.status_code, 400) def test_new_issue_should_not_crash(self): """/issues/new POST exit with 400 if missing parameters.""" @@ -228,9 +222,7 @@ def test_new_issue_should_not_crash(self): rv = self.app.post('/issues/new', content_type='multipart/form-data', data=data) - # temporarily return the maintenance page - self.assertEqual(rv.status_code, 200) - # self.assertEqual(rv.status_code, 400) + self.assertEqual(rv.status_code, 400) def test_dashboard_triage(self): """Request to /dashboard/triage should be 308.""" @@ -273,13 +265,12 @@ def test_extracted_ga_params_end_up_as_inline_js(self): # do we have a nonce-hash in our CSP? self.assertIn('nonce-', rv.headers['Content-Security-Policy']) # do we have a