Skip to content

Commit

Permalink
Issue #3250 - Adjusts functional tests to the wizard form
Browse files Browse the repository at this point in the history
some tests have been removed because duplicated elsewhere. some partially rewritten. The new form is definitely more challending to test than the previous one and there is a lot of repeat. In fact I would probably see in the future a way where we can branch scenarios in the tests through meta function, instead of repeating the same code again and again.
  • Loading branch information
karlcow committed Mar 26, 2020
1 parent b17959d commit 7ceb984
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 552 deletions.
103 changes: 0 additions & 103 deletions tests/functional/image-uploads-non-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ 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");

registerSuite("Image Uploads (non-auth)", {
tests: {
Expand Down Expand Up @@ -158,31 +154,6 @@ registerSuite("Image Uploads (non-auth)", {
.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")
Expand Down Expand Up @@ -256,80 +227,6 @@ registerSuite("Image Uploads (non-auth)", {
);
})
.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()
);
}
}
});
84 changes: 72 additions & 12 deletions tests/functional/reporting-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,78 @@ registerSuite("Reporting (auth)", {
},

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();
"Wizard stepper - scenario 1"() {
return (
FunctionalHelpers.openPage(this, url("/issues/new"), "#js-ReportForm")
// Manual url enter
.findByCssSelector("#url")
.type("http://example.com")
.end()
// Click on "Confirm"
.findByCssSelector(".button.step-1")
.click()
.end()
.execute(function() {
// Click on "Desktop site instead of mobile site"
$("[for=problem_category-0]")[0].click();
})
.sleep(1000)
// Click on "Yes"
.findByCssSelector(".button.step-4")
.click()
.end()
.sleep(500)
.findByCssSelector(".button.step-6")
.getAttribute("class")
.then(function(className) {
// Make sure that "Confirm" button is disabled if browser is not selected
assert.include(className, "disabled");
})
.execute(function() {
// Click on "Chrome"
$("[for=tested_browsers-0]")[0].click();
})
.end()
.sleep(500)
// Click on "Confirm"
.findByCssSelector(".button.step-6")
.click()
.end()
// Enter less than 30 characters in the description field
.findById("steps_reproduce")
.type("not enough characters")
.end()
.sleep(500)
.findDisplayedByCssSelector(".button.step-8")
.getAttribute("class")
.then(function(className) {
// Make sure "Continue" is disabled if there are not enough characters
assert.include(className, "disabled");
})
.end()
.findById("steps_reproduce")
.clearValue()
// Enter more than 30 characters in the description field
.type("This paragraph contains more than 30 characters")
.end()
.sleep(500)
// Click on "Continue"
.findByCssSelector(".button.step-8")
.click()
.end()
.sleep(500)
.findDisplayedByCssSelector(".button.step-10")
// Click on "Continue without"
.click()
.end()
.sleep(500)
// Make sure Report as FooUser (logged in)
.findByCssSelector("#submitgithub")
.getVisibleText()
.then(function(text) {
assert.include(text, "Report as");
})
);
}
}
});
50 changes: 42 additions & 8 deletions tests/functional/reporting-issue-wizard-non-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@ const path = require("path");

const cwd = intern.config.basePath;
const VALID_IMAGE_PATH = path.join(cwd, "tests/fixtures", "green_square.png");
const BAD_IMAGE_PATH = path.join(cwd, "tests/fixtures", "evil.py");

const url = function(path) {
return intern.config.siteRoot + path;
};

registerSuite("Reporting with wizard", {
before() {
return FunctionalHelpers.setCookie(this, { name: "exp", value: "form-v2" });
},

after() {
return FunctionalHelpers.deleteCookie(this, "exp");
},

tests: {
"Space in domain name validation"() {
return FunctionalHelpers.openPage(
Expand Down Expand Up @@ -368,6 +361,47 @@ registerSuite("Reporting with wizard", {
.findByCssSelector("#image")
.type(VALID_IMAGE_PATH)
.end()
// Change for a bad image
.findByCssSelector("#image")
.type(BAD_IMAGE_PATH)
.end()
// check the error message
.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()
.sleep(500)
.findDisplayedByCssSelector(".button.step-10")
.getVisibleText()
Expand Down
Loading

0 comments on commit 7ceb984

Please sign in to comment.