2019-07-17 14:56:48 -04:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2023-10-24 14:22:28 -04:00
|
|
|
const seleniumWebdriver = require('selenium-webdriver');
|
|
|
|
const tap = require('tap');
|
2019-07-17 14:56:48 -04:00
|
|
|
|
2023-10-24 14:22:28 -04:00
|
|
|
const utils = require('./teacher_registration_utils.js');
|
|
|
|
const constants = utils.constants;
|
2019-07-17 14:56:48 -04:00
|
|
|
|
|
|
|
// Set test url through environment variable
|
2023-10-24 14:22:28 -04:00
|
|
|
const rootUrl = process.env.ROOT_URL || 'http://localhost:8333';
|
2019-07-17 14:56:48 -04:00
|
|
|
|
|
|
|
// chrome driver
|
2023-10-24 14:22:28 -04:00
|
|
|
const driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome())
|
2019-07-17 14:56:48 -04:00
|
|
|
.build();
|
|
|
|
|
|
|
|
tap.plan(3);
|
|
|
|
|
2023-10-24 14:22:28 -04:00
|
|
|
tap.tearDown(() => {
|
2019-07-17 14:56:48 -04:00
|
|
|
driver.quit();
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.beforeEach(function () {
|
2023-10-24 14:22:28 -04:00
|
|
|
driver.get(`${rootUrl}/educators/register`);
|
2019-07-17 14:56:48 -04:00
|
|
|
return utils.fillUsernameSlide(driver, seleniumWebdriver)
|
|
|
|
.then(utils.fillDemographicsSlide.bind(this, driver, seleniumWebdriver)) // eslint-disable-line no-invalid-this
|
|
|
|
.then(utils.fillNameSlide.bind(this, driver, seleniumWebdriver)) // eslint-disable-line no-invalid-this
|
|
|
|
.then(utils.fillPhoneSlide.bind(this, driver, seleniumWebdriver)) // eslint-disable-line no-invalid-this
|
|
|
|
.then(utils.fillOrganizationSlide.bind(this, driver, seleniumWebdriver)) // eslint-disable-line no-invalid-this
|
|
|
|
.then(utils.fillAddressSlide.bind(this, driver, seleniumWebdriver)); // eslint-disable-line no-invalid-this
|
|
|
|
});
|
|
|
|
|
2023-10-24 14:22:28 -04:00
|
|
|
tap.test('checkCharacterCountIsCorrect', t => {
|
|
|
|
const textarea = driver.findElement(seleniumWebdriver.By.name('useScratch'));
|
|
|
|
const charCount = driver.findElement(seleniumWebdriver.By.xpath('//p[@class="char-count"]'));
|
|
|
|
textarea.sendKeys('hello').then(() => {
|
|
|
|
charCount.getText().then(charCountText => {
|
2019-07-17 14:56:48 -04:00
|
|
|
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
|
2023-10-24 14:22:28 -04:00
|
|
|
tap.test('checkCharacterCountTurnsOrangeWhenTooLong', t => {
|
|
|
|
const textarea = driver.findElement(seleniumWebdriver.By.name('useScratch'));
|
|
|
|
const charCount = driver.findElement(seleniumWebdriver.By.xpath('//p[@class="char-count"]'));
|
|
|
|
textarea.sendKeys(constants.loremIpsumTextLong).then(() => {
|
|
|
|
charCount.getAttribute('class').then(charCountClasses => {
|
2019-07-17 14:56:48 -04:00
|
|
|
t.ok(charCountClasses.includes('overmax'));
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-10-24 14:22:28 -04:00
|
|
|
tap.test('checkCharacterCountErrorAppersWhenTooLong', t => {
|
|
|
|
const textarea = driver.findElement(seleniumWebdriver.By.name('useScratch'));
|
|
|
|
const errorMessage = 'Description must be at most 300 characters';
|
|
|
|
const errorMessageXPath = `//span[@class="help-block validation-message" and contains(text(),"${
|
|
|
|
errorMessage}")]`;
|
|
|
|
textarea.sendKeys(constants.loremIpsumTextLong).then(() => {
|
|
|
|
driver.findElements(seleniumWebdriver.By.xpath(errorMessageXPath)).then(validationMessages => {
|
2019-07-17 14:56:48 -04:00
|
|
|
t.equal(validationMessages.length, 1);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|