mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-23 07:38:07 -05:00
de78abbea2
* automated tests for footer links * renamed navbar test file and removed footer links to separate file * run with make smoke * added tests for join scratch and sign in in navbar * fix linter errors & update www links * addressed some of ray's comments * fix failing test - projects row link * maybe fix error? * continue switching to click, convert so it runs with disabled selenium promise manager, and refactor to be less location dependent * finish switching off of implicit reliance on selenium promise manager
131 lines
4.5 KiB
JavaScript
131 lines
4.5 KiB
JavaScript
/*
|
|
* 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
|
|
seleniumWebdriver.SELENIUM_PROMISE_MANAGER=0;
|
|
|
|
//Set test url through environment variable
|
|
var rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
|
|
|
|
//chrome driver
|
|
var driver = new seleniumWebdriver.Builder().withCapabilities(seleniumWebdriver.Capabilities.chrome()).build();
|
|
|
|
//number of tests in the plan
|
|
tap.plan(8);
|
|
|
|
tap.tearDown(function () {
|
|
//quit the instance of the browser
|
|
driver.quit();
|
|
});
|
|
|
|
tap.beforeEach(function () {
|
|
//load the page with the driver
|
|
return driver.get(rootUrl);
|
|
});
|
|
|
|
// ==== Links in navbar ====
|
|
|
|
//the create link changes depending on whether the user is signed in or not (tips window opens)
|
|
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))
|
|
.then( function (element) {
|
|
return element.getAttribute('href');})
|
|
.then( function (url) {
|
|
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))
|
|
.then( function (element) {
|
|
return element.getAttribute('href');})
|
|
.then( function (url) {
|
|
t.equal(url.substr(-expectedHref.length), expectedHref);
|
|
t.end();
|
|
});
|
|
});
|
|
|
|
tap.test('checkDiscussLinkWhenSignedOut', function (t) {
|
|
var xPathLink = '//li[contains(@class, "link") and contains(@class, "discuss")]/a';
|
|
var expectedHref = '/discuss';
|
|
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
|
|
.then( function (element) {
|
|
return element.getAttribute('href');})
|
|
.then( function (url) {
|
|
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))
|
|
.then( function (element) {
|
|
return element.getAttribute('href');})
|
|
.then( function (url) {
|
|
t.equal(url.substr(-expectedHref.length), expectedHref);
|
|
t.end();
|
|
});
|
|
});
|
|
|
|
tap.test('checkHelpLinkWhenSignedOut', function (t) {
|
|
var xPathLink = '//li[contains(@class, "link") and contains(@class, "help")]/a';
|
|
var expectedHref = '/help';
|
|
driver.findElement(seleniumWebdriver.By.xpath(xPathLink))
|
|
.then( function (element) {
|
|
return element.getAttribute('href');})
|
|
.then( function (url) {
|
|
t.equal(url.substr(-expectedHref.length), expectedHref);
|
|
t.end();
|
|
});
|
|
});
|
|
|
|
// ==== Search bar ====
|
|
|
|
tap.test('checkSearchBar', function (t) {
|
|
var xPathLink = '//input[@id="frc-q-1088"]';
|
|
// search bar should exist
|
|
driver.findElement(seleniumWebdriver.By.xpath(xPathLink)).then( function (element) {
|
|
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))
|
|
.then( function (element) {
|
|
return element.getText('a');})
|
|
.then( function (text) {
|
|
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))
|
|
.then( function (element) {
|
|
return element.getText('a');})
|
|
.then( function (text) {
|
|
t.equal(text, expectedText);
|
|
t.end();
|
|
});
|
|
});
|