From 432fd1a81bd18c4d710894313231c0c6d77a6096 Mon Sep 17 00:00:00 2001 From: cwillaim Date: Sun, 18 Dec 2016 21:57:47 -0500 Subject: [PATCH] Test the address and 'use scratch' steps. --- .../teacher_registration_utils.js | 42 ++++++++- .../test_teacher_registration_address_step.js | 78 +++++++++++++++ ...st_teacher_registration_usescratch_step.js | 94 +++++++++++++++++++ 3 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 test/integration/teacher-registration/test_teacher_registration_address_step.js create mode 100644 test/integration/teacher-registration/test_teacher_registration_usescratch_step.js diff --git a/test/integration/teacher-registration/teacher_registration_utils.js b/test/integration/teacher-registration/teacher_registration_utils.js index 2889fed5d..51f3f6ade 100644 --- a/test/integration/teacher-registration/teacher_registration_utils.js +++ b/test/integration/teacher-registration/teacher_registration_utils.js @@ -1,7 +1,11 @@ module.exports.constants = { 'nextStepXpath': '//button[span[contains(text(), "Next Step")]]', 'generalErrorMessageXpath': '//span[@class="help-block validation-message" and contains(text(),' - + '"This field is required")]' + + '"This field is required")]', + 'loremIpsumTextLong': 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur viverra' + + 'nec mauris efficitur tincidunt. Vestibulum ut diam odio. Cum sociis natoque penatibus et magnis dis' + + 'parturient montes, nascetur ridiculus mus. Morbi non enim dolor. Vestibulum at enim vestibulum, ullamcorper' + + 'Duis eget quam pharetra, ultricies est eu, pharetra nisi. In tempor cursus nisi, non sagittis quam gravida.' }; module.exports.fillUsernameSlide = function (driver, seleniumWebdriver) { @@ -23,7 +27,7 @@ module.exports.fillDemographicsSlide = function (driver, seleniumWebdriver) { var clickMaleInput = driver.findElement(seleniumWebdriver.By.xpath('//input[@value="male"' + 'and @type="radio"]')).click(); var selectCountry = driver.findElement(seleniumWebdriver.By.xpath('//select[@name="user.country"]' + - '/option[2]')).click(); + '/option[@value="us"]')).click(); var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(module.exports.constants.nextStepXpath)); return Promise.all([clickMaleInput, selectCountry]).then(function () { nextStepButton.click().then(function () { @@ -58,3 +62,37 @@ module.exports.fillPhoneSlide = function (driver, seleniumWebdriver) { }); }); }; + +module.exports.fillOrganizationSlide = function (driver, seleniumWebdriver) { + var organizationInput = driver.findElement(seleniumWebdriver.By.name('organization.name')); + var titleInput = driver.findElement(seleniumWebdriver.By.name('organization.title')); + var typeCheckbox = driver.findElement(seleniumWebdriver.By.xpath('//input[@type="checkbox" and @value="3"]')); + var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(module.exports.constants.nextStepXpath)); + var organizationPromise = organizationInput.sendKeys('MIT Media Lab'); + var titlePromise = titleInput.sendKeys('Software Developer'); + var typePromise = typeCheckbox.click(); + return Promise.all([organizationPromise, titlePromise, typePromise]).then(function () { + nextStepButton.click().then(function () { + driver.wait(seleniumWebdriver.until + .elementLocated(seleniumWebdriver.By.className('address-step'))); + }); + }); +}; + +module.exports.fillAddressSlide = function (driver, seleniumWebdriver) { + var addressInput = driver.findElement(seleniumWebdriver.By.name('address.line1')); + var cityInput = driver.findElement(seleniumWebdriver.By.name('address.city')); + var zipCodeInput = driver.findElement(seleniumWebdriver.By.name('address.zip')); + var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(module.exports.constants.nextStepXpath)); + var addressPromise = addressInput.sendKeys('77 Massachusetts Avenue, E14/E15'); + var cityPromise = cityInput.sendKeys('Cambridge'); + var statePromise = driver.findElement(seleniumWebdriver.By.xpath('//select[@name="address.state"]' + + '/option[@value="us-ma"]')).click(); + var zipPromise = zipCodeInput.sendKeys('02139'); + return Promise.all([addressPromise, cityPromise, statePromise, zipPromise]).then(function () { + nextStepButton.click().then(function () { + driver.wait(seleniumWebdriver.until + .elementLocated(seleniumWebdriver.By.className('usescratch-step'))); + }); + }); +}; diff --git a/test/integration/teacher-registration/test_teacher_registration_address_step.js b/test/integration/teacher-registration/test_teacher_registration_address_step.js new file mode 100644 index 000000000..63770ee72 --- /dev/null +++ b/test/integration/teacher-registration/test_teacher_registration_address_step.js @@ -0,0 +1,78 @@ +/* + * Checks the behavior of the address step in the educators registration process + * + * Test cases: https://github.com/LLK/scratch-www/wiki/Testing-Scratch-www#All_Test_Cases_Teacher_Join_Flow + */ +require('chromedriver'); +var seleniumWebdriver = require('selenium-webdriver'); +var tap = require('tap'); + +var utils = require('./teacher_registration_utils.js'); +var constants = utils.constants; + +//Set test url through environment variable +//var rootUrl = process.ENV.ROOT_URL || 'http://localhost:8333'; + +//chrome driver +var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build(); + +var fillUsernameSlide = function () { + return utils.fillUsernameSlide(driver, seleniumWebdriver); +}; + +var fillDemographicsSlide = function () { + return utils.fillDemographicsSlide(driver, seleniumWebdriver); +}; + +var fillNameSlide = function () { + return utils.fillNameSlide(driver, seleniumWebdriver); +}; + +var fillPhoneSlide = function () { + return utils.fillPhoneSlide(driver, seleniumWebdriver); +}; + +var fillOrganizationSlide = function () { + return utils.fillOrganizationSlide(driver, seleniumWebdriver); +}; + +tap.plan(2); + +tap.tearDown(function () { + driver.quit(); +}); + +tap.beforeEach(function () { + driver.get('https://scratch.mit.edu/educators/register'); + return fillUsernameSlide() + .then(fillDemographicsSlide) + .then(fillNameSlide) + .then(fillPhoneSlide) + .then(fillOrganizationSlide); +}); + +//Selects Vatican City as the country, and checks that the state dropdown disappears +tap.test('checkStateDropdownOnlyPresentWhenNeeded', function (t) { + var selectCountry = driver.findElement(seleniumWebdriver.By.xpath('//select[@name="address.country"]' + + '/option[@value="va"]')).click(); + driver.findElements(seleniumWebdriver.By.name('address.state')) + .then(function (stateDropdown) { + t.equal(stateDropdown.length, 0); + t.end(); + }); +}); + +tap.test('checkZipCodeRequired', function (t) { + var nextStepButton = driver.findElement(seleniumWebdriver.By.xpath(constants.nextStepXpath)); + var errorMessageXPath = '//input[@name="address.zip"]/following-sibling::' + + 'span[@class="help-block validation-message" and contains(text(),' + + '"This field is required")]'; + nextStepButton.click().then(function () { + driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)) + .then(function (validationMessages) { + t.equal(validationMessages.length, 1); + t.end(); + }); + }); +}); + diff --git a/test/integration/teacher-registration/test_teacher_registration_usescratch_step.js b/test/integration/teacher-registration/test_teacher_registration_usescratch_step.js new file mode 100644 index 000000000..511813b21 --- /dev/null +++ b/test/integration/teacher-registration/test_teacher_registration_usescratch_step.js @@ -0,0 +1,94 @@ +/* + * Checks the behavior of the 'use scratch' step in the educators registration process + * + * Test cases: https://github.com/LLK/scratch-www/wiki/Testing-Scratch-www#All_Test_Cases_Teacher_Join_Flow + */ +require('chromedriver'); +var seleniumWebdriver = require('selenium-webdriver'); +var tap = require('tap'); + +var utils = require('./teacher_registration_utils.js'); +var constants = utils.constants; + +//Set test url through environment variable +//var rootUrl = process.ENV.ROOT_URL || 'http://localhost:8333'; + +//chrome driver +var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build(); + +var fillUsernameSlide = function () { + return utils.fillUsernameSlide(driver, seleniumWebdriver); +}; + +var fillDemographicsSlide = function () { + return utils.fillDemographicsSlide(driver, seleniumWebdriver); +}; + +var fillNameSlide = function () { + return utils.fillNameSlide(driver, seleniumWebdriver); +}; + +var fillPhoneSlide = function () { + return utils.fillPhoneSlide(driver, seleniumWebdriver); +}; + +var fillOrganizationSlide = function () { + return utils.fillOrganizationSlide(driver, seleniumWebdriver); +}; + +var fillAddressSlide = function () { + return utils.fillAddressSlide(driver, seleniumWebdriver); +}; + +tap.plan(3); + +tap.tearDown(function () { + driver.quit(); +}); + +tap.beforeEach(function () { + driver.get('https://scratch.mit.edu/educators/register'); + return fillUsernameSlide() + .then(fillDemographicsSlide) + .then(fillNameSlide) + .then(fillPhoneSlide) + .then(fillOrganizationSlide) + .then(fillAddressSlide); +}); + +tap.test('checkCharacterCountIsCorrect', function (t) { + var textarea = driver.findElement(seleniumWebdriver.By.name('useScratch')); + var charCount = driver.findElement(seleniumWebdriver.By.xpath('//p[@class="char-count"]')); + textarea.sendKeys('hello').then(function () { + charCount.getText().then(function (charCountText) { + t.equal(charCountText, '5/300'); + t.end(); + }); + }); +}); + +//Inputs more than 300 characters and checks that the char count gets the class 'overmax' +//which turns the text orange +tap.test('checkCharacterCountTurnsOrangeWhenTooLong', function (t) { + var textarea = driver.findElement(seleniumWebdriver.By.name('useScratch')); + var charCount = driver.findElement(seleniumWebdriver.By.xpath('//p[@class="char-count"]')); + textarea.sendKeys(constants.loremIpsumTextLong).then(function () { + charCount.getAttribute('class').then(function (charCountClasses) { + t.ok(charCountClasses.includes('overmax')); + t.end(); + }); + }); +}); + +tap.test('checkCharacterCountErrorAppersWhenTooLong', function (t) { + var textarea = driver.findElement(seleniumWebdriver.By.name('useScratch')); + var errorMessage = 'Description must be at most 300 characters'; + var errorMessageXPath = '//span[@class="help-block validation-message" and contains(text(),"' + + errorMessage + '")]'; + textarea.sendKeys(constants.loremIpsumTextLong).then(function () { + driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(function (validationMessages) { + t.equal(validationMessages.length, 1); + t.end(); + }); + }); +});