Test the address and 'use scratch' steps.

This commit is contained in:
cwillaim 2016-12-18 21:57:47 -05:00 committed by Ray Schamp
parent 29a38ca917
commit 432fd1a81b
3 changed files with 212 additions and 2 deletions

View file

@ -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')));
});
});
};

View file

@ -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();
});
});
});

View file

@ -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();
});
});
});