From 3d4f579e3ad2ac80f6bc610558146a6148749772 Mon Sep 17 00:00:00 2001 From: BryceLTaylor Date: Fri, 2 Oct 2020 16:53:52 -0400 Subject: [PATCH 1/3] Move footer integration tests to jest --- .../smoke-testing/test_footer_links.js | 242 ------------------ test/integration/footer-links.test.js | 142 ++++++++++ 2 files changed, 142 insertions(+), 242 deletions(-) delete mode 100644 test/integration-legacy/smoke-testing/test_footer_links.js create mode 100644 test/integration/footer-links.test.js diff --git a/test/integration-legacy/smoke-testing/test_footer_links.js b/test/integration-legacy/smoke-testing/test_footer_links.js deleted file mode 100644 index 753f479ce..000000000 --- a/test/integration-legacy/smoke-testing/test_footer_links.js +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Checks that the links in the footer on the homepage have the right URLs to redirect to - * - * Test cases: https://github.com/LLK/scratch-www/wiki/Most-Important-Workflows - */ - -const SeleniumHelper = require('../selenium-helpers.js'); -const helper = new SeleniumHelper(); - -const tap = require('tap'); - -const webdriver = require('selenium-webdriver'); -const driver = helper.buildDriver('www-smoke test_footer_links'); - -const rootUrl = process.env.ROOT_URL || 'https://scratch.ly'; - -// timeout for each test; timeout for suite set at command line level -const options = {timeout: 30000}; - -tap.tearDown(function () { - // quit the instance of the browser - driver.quit(); -}); - -tap.beforeEach(function () { - // load the page with the driver - return driver.get(rootUrl); -}); - -// Function clicks the link and returns the url of the resulting page - -const clickFooterLinks = function (linkText) { - return driver.wait(webdriver.until.elementLocated(webdriver.By.id('footer'))) - .then(function (element) { - return element.findElement(webdriver.By.linkText(linkText)); - }) - .then(function (element) { - return element.click(); - }) - .then(function () { - return driver.getCurrentUrl(); - }); -}; - -// ==== ABOUT SCRATCH column ==== - -// ABOUT SCRATCH -tap.test('clickAboutScratchLink', options, t => { - const linkText = 'About Scratch'; - const expectedHref = '/about'; - clickFooterLinks(linkText).then(url => { - // the href should be at the end of the URL - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// FOR PARENTS -tap.test('clickForParentsLink', options, t => { - const linkText = 'For Parents'; - const expectedHref = '/parents/'; - clickFooterLinks(linkText).then(url => { - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// FOR EDUCATORS -tap.test('clickForEducatorsLink', options, t => { - const linkText = 'For Educators'; - const expectedHref = '/educators'; - clickFooterLinks(linkText).then(url => { - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// FOR DEVELOPERS -tap.test('clickForDevelopersScratchLink', options, t => { - const linkText = 'For Developers'; - const expectedHref = '/developers'; - clickFooterLinks(linkText).then(url => { - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// CREDITS -tap.test('clickCreditsLink', options, t => { - const linkText = 'Credits'; - const expectedHref = '/credits'; - clickFooterLinks(linkText).then(url => { - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// JOBS -tap.test('clickJobsLink', options, t => { - const linkText = 'Jobs'; - const expectedUrl = 'https://www.scratchfoundation.org/opportunities/'; - clickFooterLinks(linkText).then(url => { - t.equal(url, expectedUrl); - t.end(); - }); -}); - -// PRESS -tap.test('clickPressLink', options, t => { - const linkText = 'Press'; - const expectedUrl = 'https://www.scratchfoundation.org/media-kit/'; - clickFooterLinks(linkText).then(url => { - t.equal(url, expectedUrl); - t.end(); - }); -}); - -// ==== COMMUNITY column ==== - -// COMMUNITY GUIDELINES -tap.test('clickCommunityGuidelinesLink', options, t => { - const linkText = 'Community Guidelines'; - const expectedHref = '/community_guidelines'; - clickFooterLinks(linkText).then(url => { - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// DISCUSSION FORUMS -tap.test('clickDiscussionForumsLink', options, t => { - const linkText = 'Discussion Forums'; - const expectedHref = '/discuss/'; - clickFooterLinks(linkText).then(url => { - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// STATISTICS -tap.test('clickStatisticsLink', options, t => { - const linkText = 'Statistics'; - const expectedHref = '/statistics/'; - clickFooterLinks(linkText).then(url => { - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// ==== SUPPORT column ==== - -// IDEAS PAGE -tap.test('clickIdeasPageLink', options, t => { - const linkText = 'Ideas'; - const expectedHref = '/ideas'; - clickFooterLinks(linkText).then(url => { - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// FAQ -tap.test('clickFAQLink', options, t => { - const linkText = 'FAQ'; - const expectedHref = '/info/faq'; - clickFooterLinks(linkText).then(url => { - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// OFFLINE EDITOR -tap.test('clickOfflineEditorLink', options, t => { - const linkText = 'Offline Editor'; - const expectedHref = '/download'; - clickFooterLinks(linkText).then(url => { - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// CONTACT US -tap.test('clickContactUsLink', options, t => { - const linkText = 'Contact Us'; - const expectedHref = '/contact-us/'; - clickFooterLinks(linkText).then(url => { - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// ==== LEGAL column ==== - -// TERMS OF USE -tap.test('clickTermsOfUseLink', options, t => { - const linkText = 'Terms of Use'; - const expectedHref = '/terms_of_use'; - clickFooterLinks(linkText).then(url => { - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// PRIVACY POLICY -tap.test('clickPrivacyPolicyLink', options, t => { - const linkText = 'Privacy Policy'; - const expectedHref = '/privacy_policy'; - clickFooterLinks(linkText).then(url => { - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// DMCA -tap.test('clickDMCALink', options, t => { - const linkText = 'DMCA'; - const expectedHref = '/DMCA'; - clickFooterLinks(linkText).then(url => { - t.equal(url.substr(-expectedHref.length), expectedHref); - t.end(); - }); -}); - -// ==== SCRATCH FAMILY column ==== -// SCRATCH CONFERENCE -tap.test('clickScratchConferenceLink', options, t => { - const linkText = 'Scratch Conference'; - const expectedHref = '/conference/20'; - clickFooterLinks(linkText).then(url => { - t.match(url.substr(-(expectedHref.length + 2)), expectedHref); - t.end(); - }); -}); -// The following links in are skipped because they are not on scratch.mit.edu - -// SCRATCH STORE -// DONATE -// SCRATCH WIKI -// SCRATCH ED (SCRATCHED) -// SCRATCH JR (SCRATCHJR) -// SCRATCH DAY -// SCRATCH FOUNDATION diff --git a/test/integration/footer-links.test.js b/test/integration/footer-links.test.js new file mode 100644 index 000000000..eb80da3bd --- /dev/null +++ b/test/integration/footer-links.test.js @@ -0,0 +1,142 @@ +const SeleniumHelper = require('./selenium-helpers.js'); + +const { + clickText, + buildDriver +} = new SeleniumHelper(); + +let remote = process.env.SMOKE_REMOTE || false; +let rootUrl = process.env.ROOT_URL || 'https://scratch.ly'; + +if (remote) { + jest.setTimeout(60000); +} else { + jest.setTimeout(10000); +} + +let driver; + +describe('www-integration footer links', () => { + beforeAll(async () => { + driver = await buildDriver('www-integration footer links'); + }); + + beforeEach(async () => { + await driver.get(rootUrl); + }); + + afterAll(async () => await driver.quit()); + + // ==== About Scratch column ==== + + test('click About Scratch link', async () => { + await clickText('About Scratch'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/about\/?$/); + }); + + test('click For Parents link', async () => { + await clickText('For Parents'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/parents\/?$/); + }); + + test('click For Educators link', async () => { + await clickText('For Educators'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/educators\/?$/); + }); + + test('click For Developers link', async () => { + await clickText('For Developers'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/developers\/?$/); + }); + + // ==== COMMUNITY column ==== + + test('click Community Guidelines link', async () => { + await clickText('Community Guidelines'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/community_guidelines\/?$/); + }); + + test('click Discussion Forums link', async () => { + await clickText('Discussion Forums'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/discuss\/?$/); + }); + + test('click Statistics link', async () => { + await clickText('Statistics'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/statistics\/?$/); + }); + + // ==== SUPPORT column ==== + + test('click Ideas link', async () => { + await clickText('Ideas'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/ideas\/?$/); + }); + + test('click FAQ link', async () => { + await clickText('FAQ'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/info\/faq\/?$/); + }); + + test('click Download link', async () => { + await clickText('Download'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/download\/?$/); + }); + + test('click Contact Us link', async () => { + await clickText('Contact Us'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/contact-us\/?$/); + }); + + // ==== LEGAL column ==== + + test('click Terms of Use link', async () => { + await clickText('Terms of Use'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/terms_of_use\/?$/); + }); + + test('click Privacy Policy link', async () => { + await clickText('Privacy Policy'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/privacy_policy\/?$/); + }); + + test('click DMCA link', async () => { + await clickText('DMCA'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/DMCA\/?$/); + }); + + // ==== SCRATCH FAMILY column ==== + + test('click Scratch Conference link', async () => { + await clickText('Scratch Conference'); + let url = await driver.getCurrentUrl(); + expect(url).toMatch(/conference\/2020\/?$/); + }); + +}); + +// The following links in are skipped because they are not on scratch.mit.edu + +// Jobs +// Press +// SCRATCH STORE +// DONATE +// SCRATCH WIKI +// SCRATCH ED (SCRATCHED) +// SCRATCH JR (SCRATCHJR) +// SCRATCH DAY +// SCRATCH FOUNDATION From 8c4303a5b4569c80d7210954a616a6c75dd41f11 Mon Sep 17 00:00:00 2001 From: BryceLTaylor Date: Tue, 6 Oct 2020 15:42:59 -0400 Subject: [PATCH 2/3] match the whole pathname instead of just the end --- test/integration/footer-links.test.js | 43 ++++++++++++++++++--------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/test/integration/footer-links.test.js b/test/integration/footer-links.test.js index eb80da3bd..44d577507 100644 --- a/test/integration/footer-links.test.js +++ b/test/integration/footer-links.test.js @@ -32,25 +32,29 @@ describe('www-integration footer links', () => { test('click About Scratch link', async () => { await clickText('About Scratch'); let url = await driver.getCurrentUrl(); - expect(url).toMatch(/about\/?$/); + let pathname = (new URL(url)).pathname; + expect(pathname).toMatch(/^\/about\/?$/); }); test('click For Parents link', async () => { await clickText('For Parents'); let url = await driver.getCurrentUrl(); - expect(url).toMatch(/parents\/?$/); + let pathname = (new URL(url)).pathname; + expect(pathname).toMatch(/parents\/?$/); }); test('click For Educators link', async () => { await clickText('For Educators'); let url = await driver.getCurrentUrl(); - expect(url).toMatch(/educators\/?$/); + let pathname = (new URL(url)).pathname; + expect(pathname).toMatch(/educators\/?$/); }); test('click For Developers link', async () => { await clickText('For Developers'); let url = await driver.getCurrentUrl(); - expect(url).toMatch(/developers\/?$/); + let pathname = (new URL(url)).pathname; + expect(pathname).toMatch(/developers\/?$/); }); // ==== COMMUNITY column ==== @@ -58,19 +62,22 @@ describe('www-integration footer links', () => { test('click Community Guidelines link', async () => { await clickText('Community Guidelines'); let url = await driver.getCurrentUrl(); - expect(url).toMatch(/community_guidelines\/?$/); + let pathname = (new URL(url)).pathname; + expect(pathname).toMatch(/community_guidelines\/?$/); }); test('click Discussion Forums link', async () => { await clickText('Discussion Forums'); let url = await driver.getCurrentUrl(); + let pathname = (new URL(url)).pathname; expect(url).toMatch(/discuss\/?$/); }); test('click Statistics link', async () => { await clickText('Statistics'); let url = await driver.getCurrentUrl(); - expect(url).toMatch(/statistics\/?$/); + let pathname = (new URL(url)).pathname; + expect(pathname).toMatch(/statistics\/?$/); }); // ==== SUPPORT column ==== @@ -78,25 +85,29 @@ describe('www-integration footer links', () => { test('click Ideas link', async () => { await clickText('Ideas'); let url = await driver.getCurrentUrl(); - expect(url).toMatch(/ideas\/?$/); + let pathname = (new URL(url)).pathname; + expect(pathname).toMatch(/ideas\/?$/); }); test('click FAQ link', async () => { await clickText('FAQ'); let url = await driver.getCurrentUrl(); - expect(url).toMatch(/info\/faq\/?$/); + let pathname = (new URL(url)).pathname; + expect(pathname).toMatch(/info\/faq\/?$/); }); test('click Download link', async () => { await clickText('Download'); let url = await driver.getCurrentUrl(); - expect(url).toMatch(/download\/?$/); + let pathname = (new URL(url)).pathname; + expect(pathname).toMatch(/download\/?$/); }); test('click Contact Us link', async () => { await clickText('Contact Us'); let url = await driver.getCurrentUrl(); - expect(url).toMatch(/contact-us\/?$/); + let pathname = (new URL(url)).pathname; + expect(pathname).toMatch(/contact-us\/?$/); }); // ==== LEGAL column ==== @@ -104,19 +115,22 @@ describe('www-integration footer links', () => { test('click Terms of Use link', async () => { await clickText('Terms of Use'); let url = await driver.getCurrentUrl(); - expect(url).toMatch(/terms_of_use\/?$/); + let pathname = (new URL(url)).pathname; + expect(pathname).toMatch(/terms_of_use\/?$/); }); test('click Privacy Policy link', async () => { await clickText('Privacy Policy'); let url = await driver.getCurrentUrl(); - expect(url).toMatch(/privacy_policy\/?$/); + let pathname = (new URL(url)).pathname; + expect(pathname).toMatch(/privacy_policy\/?$/); }); test('click DMCA link', async () => { await clickText('DMCA'); let url = await driver.getCurrentUrl(); - expect(url).toMatch(/DMCA\/?$/); + let pathname = (new URL(url)).pathname; + expect(pathname).toMatch(/DMCA\/?$/); }); // ==== SCRATCH FAMILY column ==== @@ -124,7 +138,8 @@ describe('www-integration footer links', () => { test('click Scratch Conference link', async () => { await clickText('Scratch Conference'); let url = await driver.getCurrentUrl(); - expect(url).toMatch(/conference\/2020\/?$/); + let pathname = (new URL(url)).pathname; + expect(pathname).toMatch(/conference\/2020\/?$/); }); }); From 530fb1b87cf00c32c330f4de03f58e4d92645ce3 Mon Sep 17 00:00:00 2001 From: BryceLTaylor Date: Tue, 6 Oct 2020 16:42:57 -0400 Subject: [PATCH 3/3] update match in footer integration tests --- test/integration/footer-links.test.js | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/integration/footer-links.test.js b/test/integration/footer-links.test.js index 44d577507..fe5c8eeda 100644 --- a/test/integration/footer-links.test.js +++ b/test/integration/footer-links.test.js @@ -40,21 +40,21 @@ describe('www-integration footer links', () => { await clickText('For Parents'); let url = await driver.getCurrentUrl(); let pathname = (new URL(url)).pathname; - expect(pathname).toMatch(/parents\/?$/); + expect(pathname).toMatch(/^\/parents\/?$/); }); test('click For Educators link', async () => { await clickText('For Educators'); let url = await driver.getCurrentUrl(); let pathname = (new URL(url)).pathname; - expect(pathname).toMatch(/educators\/?$/); + expect(pathname).toMatch(/^\/educators\/?$/); }); test('click For Developers link', async () => { await clickText('For Developers'); let url = await driver.getCurrentUrl(); let pathname = (new URL(url)).pathname; - expect(pathname).toMatch(/developers\/?$/); + expect(pathname).toMatch(/^\/developers\/?$/); }); // ==== COMMUNITY column ==== @@ -63,21 +63,21 @@ describe('www-integration footer links', () => { await clickText('Community Guidelines'); let url = await driver.getCurrentUrl(); let pathname = (new URL(url)).pathname; - expect(pathname).toMatch(/community_guidelines\/?$/); + expect(pathname).toMatch(/^\/community_guidelines\/?$/); }); test('click Discussion Forums link', async () => { await clickText('Discussion Forums'); let url = await driver.getCurrentUrl(); let pathname = (new URL(url)).pathname; - expect(url).toMatch(/discuss\/?$/); + expect(pathname).toMatch(/^\/discuss\/?$/); }); test('click Statistics link', async () => { await clickText('Statistics'); let url = await driver.getCurrentUrl(); let pathname = (new URL(url)).pathname; - expect(pathname).toMatch(/statistics\/?$/); + expect(pathname).toMatch(/^\/statistics\/?$/); }); // ==== SUPPORT column ==== @@ -86,28 +86,28 @@ describe('www-integration footer links', () => { await clickText('Ideas'); let url = await driver.getCurrentUrl(); let pathname = (new URL(url)).pathname; - expect(pathname).toMatch(/ideas\/?$/); + expect(pathname).toMatch(/^\/ideas\/?$/); }); test('click FAQ link', async () => { await clickText('FAQ'); let url = await driver.getCurrentUrl(); let pathname = (new URL(url)).pathname; - expect(pathname).toMatch(/info\/faq\/?$/); + expect(pathname).toMatch(/^\/info\/faq\/?$/); }); test('click Download link', async () => { await clickText('Download'); let url = await driver.getCurrentUrl(); let pathname = (new URL(url)).pathname; - expect(pathname).toMatch(/download\/?$/); + expect(pathname).toMatch(/^\/download\/?$/); }); test('click Contact Us link', async () => { await clickText('Contact Us'); let url = await driver.getCurrentUrl(); let pathname = (new URL(url)).pathname; - expect(pathname).toMatch(/contact-us\/?$/); + expect(pathname).toMatch(/^\/contact-us\/?$/); }); // ==== LEGAL column ==== @@ -116,21 +116,21 @@ describe('www-integration footer links', () => { await clickText('Terms of Use'); let url = await driver.getCurrentUrl(); let pathname = (new URL(url)).pathname; - expect(pathname).toMatch(/terms_of_use\/?$/); + expect(pathname).toMatch(/^\/terms_of_use\/?$/); }); test('click Privacy Policy link', async () => { await clickText('Privacy Policy'); let url = await driver.getCurrentUrl(); let pathname = (new URL(url)).pathname; - expect(pathname).toMatch(/privacy_policy\/?$/); + expect(pathname).toMatch(/^\/privacy_policy\/?$/); }); test('click DMCA link', async () => { await clickText('DMCA'); let url = await driver.getCurrentUrl(); let pathname = (new URL(url)).pathname; - expect(pathname).toMatch(/DMCA\/?$/); + expect(pathname).toMatch(/^\/DMCA\/?$/); }); // ==== SCRATCH FAMILY column ==== @@ -139,7 +139,7 @@ describe('www-integration footer links', () => { await clickText('Scratch Conference'); let url = await driver.getCurrentUrl(); let pathname = (new URL(url)).pathname; - expect(pathname).toMatch(/conference\/2020\/?$/); + expect(pathname).toMatch(/^\/conference\/2020\/?$/); }); });