2017-04-19 17:14:02 -04:00
|
|
|
/*
|
|
|
|
* Checks that the links in the navbar on the homepage have the right URLs to redirect to
|
|
|
|
*
|
|
|
|
* Test cases: https://github.com/LLK/scratch-www/wiki/Most-Important-Workflows
|
|
|
|
*/
|
|
|
|
|
|
|
|
require('chromedriver');
|
|
|
|
var seleniumWebdriver = require('selenium-webdriver');
|
|
|
|
var tap = require('tap');
|
|
|
|
|
|
|
|
// Selenium's promise driver will be deprecated, so we should not rely on it
|
2018-01-30 11:53:12 -05:00
|
|
|
seleniumWebdriver.SELENIUM_PROMISE_MANAGER = 0;
|
2017-04-19 17:14:02 -04:00
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
// Set test url through environment variable
|
2017-04-19 17:14:02 -04:00
|
|
|
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
// number of tests in the plan
|
2017-07-19 12:58:14 -04:00
|
|
|
tap.plan(7);
|
2017-04-19 17:14:02 -04:00
|
|
|
|
|
|
|
tap.tearDown(function () {
|
2018-01-30 11:53:12 -05:00
|
|
|
// quit the instance of the browser
|
2017-04-19 17:14:02 -04:00
|
|
|
driver.quit();
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.beforeEach(function () {
|
2018-01-30 11:53:12 -05:00
|
|
|
// load the page with the driver
|
2017-04-19 17:14:02 -04:00
|
|
|
return driver.get(rootUrl);
|
|
|
|
});
|
|
|
|
|
|
|
|
// ==== Links in navbar ====
|
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
// the create link changes depending on whether the user is signed in or not (tips window opens)
|
2017-04-19 17:14:02 -04:00
|
|
|
tap.test('checkCreateLinkWhenSignedOut', function (t) {
|
|
|
|
var xPathLink = '//li[contains(@class, "link") and contains(@class, "create")]/a';
|
|
|
|
var expectedHref = '/projects/editor/?tip_bar=home';
|
|
|
|
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
|
2018-01-30 11:53:12 -05:00
|
|
|
.then(function (element) {
|
|
|
|
return element.getAttribute('href');
|
|
|
|
})
|
|
|
|
.then(function (url) {
|
2017-04-19 17:14:02 -04:00
|
|
|
t.equal(url.substr(-expectedHref.length), expectedHref);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('checkExploreLinkWhenSignedOut', function (t) {
|
|
|
|
var xPathLink = '//li[contains(@class, "link") and contains(@class, "explore")]/a';
|
|
|
|
var expectedHref = '/explore/projects/all';
|
|
|
|
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
|
2018-01-30 11:53:12 -05:00
|
|
|
.then(function (element) {
|
|
|
|
return element.getAttribute('href');
|
|
|
|
})
|
|
|
|
.then(function (url) {
|
2017-04-19 17:14:02 -04:00
|
|
|
t.equal(url.substr(-expectedHref.length), expectedHref);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-07-19 12:58:14 -04:00
|
|
|
tap.test('checkTipsLinkWhenSignedOut', function (t) {
|
|
|
|
var xPathLink = '//li[contains(@class, "link") and contains(@class, "tips")]/a';
|
|
|
|
var expectedHref = '/tips';
|
2017-04-19 17:14:02 -04:00
|
|
|
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
|
2018-01-30 11:53:12 -05:00
|
|
|
.then(function (element) {
|
|
|
|
return element.getAttribute('href');
|
|
|
|
})
|
|
|
|
.then(function (url) {
|
2017-04-19 17:14:02 -04:00
|
|
|
t.equal(url.substr(-expectedHref.length), expectedHref);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('checkAboutLinkWhenSignedOut', function (t) {
|
|
|
|
var xPathLink = '//li[contains(@class, "link") and contains(@class, "about")]/a';
|
|
|
|
var expectedHref = '/about';
|
|
|
|
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
|
2018-01-30 11:53:12 -05:00
|
|
|
.then(function (element) {
|
|
|
|
return element.getAttribute('href');
|
|
|
|
})
|
|
|
|
.then(function (url) {
|
|
|
|
t.equal(url.substr(-expectedHref.length), expectedHref);
|
|
|
|
t.end();
|
|
|
|
});
|
2017-04-19 17:14:02 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// ==== Search bar ====
|
|
|
|
|
|
|
|
tap.test('checkSearchBar', function (t) {
|
|
|
|
var xPathLink = '//input[@id="frc-q-1088"]';
|
|
|
|
// search bar should exist
|
2018-01-30 11:53:12 -05:00
|
|
|
driver.findElement(seleniumWebdriver.By.xpath(xPathLink)).then(function (element) {
|
2017-04-19 17:14:02 -04:00
|
|
|
t.ok(element);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// ==== Join Scratch & Sign In ====
|
|
|
|
|
|
|
|
tap.test('checkJoinScratchLinkWhenSignedOut', function (t) {
|
|
|
|
var xPathLink = '//li[contains(@class, "link") and contains(@class, "right") and contains(@class, "join")]/a';
|
|
|
|
var expectedText = 'Join Scratch';
|
|
|
|
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
|
2018-01-30 11:53:12 -05:00
|
|
|
.then(function (element) {
|
|
|
|
return element.getText('a');
|
|
|
|
})
|
|
|
|
.then(function (text) {
|
2017-04-19 17:14:02 -04:00
|
|
|
t.equal(text, expectedText);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('checkSignInLinkWhenSignedOut', function (t) {
|
|
|
|
var xPathLink = '//li[contains(@class, "link") and contains(@class, "right") and contains(@class, "login-item")]/a';
|
|
|
|
var expectedText = 'Sign in';
|
|
|
|
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
|
2018-01-30 11:53:12 -05:00
|
|
|
.then(function (element) {
|
|
|
|
return element.getText('a');
|
|
|
|
})
|
|
|
|
.then(function (text) {
|
2017-04-19 17:14:02 -04:00
|
|
|
t.equal(text, expectedText);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
});
|