From 995c01bccfb5732c9f34e351dbf5f39797a9cf63 Mon Sep 17 00:00:00 2001 From: BryceLTaylor Date: Wed, 10 Nov 2021 10:54:38 -0500 Subject: [PATCH 1/2] Convert integration tests for statistics page from Tap to Jest --- .../smoke-testing/test_statistics_page.js | 68 ------------------- test/integration/statistics.test.js | 66 ++++++++++++++++++ 2 files changed, 66 insertions(+), 68 deletions(-) delete mode 100644 test/integration-legacy/smoke-testing/test_statistics_page.js create mode 100644 test/integration/statistics.test.js diff --git a/test/integration-legacy/smoke-testing/test_statistics_page.js b/test/integration-legacy/smoke-testing/test_statistics_page.js deleted file mode 100644 index 9a8f9596c..000000000 --- a/test/integration-legacy/smoke-testing/test_statistics_page.js +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Tests stats page according to smoke-tests at: - * - * https://github.com/LLK/scratchr2/wiki/Smoke-Testing-Test-Cases - * - */ - -const SeleniumHelper = require('../selenium-helpers.js'); -const helper = new SeleniumHelper(); - -var tap = require('tap'); -const test = tap.test; - -const driver = helper.buildDriver('www-smoke test_statistics_page'); - -const { - clickText, - findByXpath, - findByCss -} = helper; - -tap.plan(2); - -tap.tearDown(function () { - driver.quit(); -}); - -tap.beforeEach(function () { - /* - * load the page with the driver - * note that for now this is not testable on Staging, - * so I left it pointing to Production - - * we can at least use it post-deploy. - * - * var stagingURL = 'https://scratch.ly/statistics'; - */ - var productionURL = 'https://scratch.mit.edu/statistics'; - return driver.get(productionURL); -}); - -test('check that Monthly Activity Trends title is present & correct', t => { - var chartTitle = 'Monthly Activity Trends'; - findByCss('div.box-head h3') - .then((element) => element.getText('h3')) - .then((text) => t.equal(text, chartTitle, 'chart title should be Monthly Activity Trends')) - .then(() => t.end()); -}); - -test('check that Monthly Activity Trends chart > New Projects label is toggleable', t => { - var classXpath = `(//div[@id="activity_chart"]/*[name()='svg']/*[name()='g']/*[name()='g']/*` + - `[name()='g'])[4]/*[name()='g']/*[name()='g']/*[name()='g']`; - findByXpath(classXpath) - .then((element) => element.getAttribute('class')) - .then((classtext) => t.equal(classtext, 'nv-series', 'by default, New Projects should be enabled')) - .then(() => clickText('New Projects')) - .then(() => findByXpath(classXpath)) - .then((element) => element.getAttribute('class')) - .then((classtext) => t.equal( - classtext, - 'nv-series nv-disabled', - 'when clicked, New Projects should be disabled' - )) - .then(() => clickText('New Projects')) - .then(() => findByXpath(classXpath)) - .then((element) => element.getAttribute('class')) - .then((classtext) => t.equal(classtext, 'nv-series', 'when clicked again, New Projects should be enabled')) - .then(() => t.end()); -}); diff --git a/test/integration/statistics.test.js b/test/integration/statistics.test.js new file mode 100644 index 000000000..1963e49e7 --- /dev/null +++ b/test/integration/statistics.test.js @@ -0,0 +1,66 @@ +// these tests do not sign in as a user + +const SeleniumHelper = require('./selenium-helpers.js'); + +const { + buildDriver, + clickText, + containsClass, + findByXpath +} = new SeleniumHelper(); + +let remote = process.env.SMOKE_REMOTE || false; +let rootUrl = process.env.ROOT_URL || 'https://scratch.ly'; +let statisticsPage = rootUrl + '/statistics'; + +if (remote) { + jest.setTimeout(60000); +} else { + jest.setTimeout(10000); +} + +let driver; + +describe('www-integration statistics page', async () => { + beforeAll(async () => { + driver = await buildDriver('www-integration statistics page'); + }); + + beforeEach(async () => { + await driver.get(statisticsPage); + }); + + afterAll(async () => await driver.quit()); + + test('check Monthly Activity Trends title', async () => { + let chartTitle = await findByXpath('//div[contains(@class, "box0")]//h3'); + let chartTitleText = await chartTitle.getText(); + await expect(chartTitleText).toBe('Monthly Activity Trends'); + }); + + test('New Projects label on first chart defaults to selected', async () => { + let toggleXpath = `(//div[@id="activity_chart"]/*[name()='svg']/*[name()='g']/*[name()='g']/*` + + `[name()='g'])[4]/*[name()='g']/*[name()='g']/*[name()='g']`; + let newProjectsToggle = await findByXpath(toggleXpath); + let toggleState = await containsClass(newProjectsToggle, 'nv-series'); + await expect(toggleState).toBe(true); + + + }); + + test('New Projects label on first chart can be toggled', async () => { + let toggleXpath = `(//div[@id="activity_chart"]/*[name()='svg']/*[name()='g']/*[name()='g']/*` + + `[name()='g'])[4]/*[name()='g']/*[name()='g']/*[name()='g']`; + let newProjectsToggle = await findByXpath(toggleXpath); + + // toggle off New Projects + await clickText('New Projects'); + let toggleState = await containsClass(newProjectsToggle, 'nv-disabled'); + await expect(toggleState).toBe(true); + + // toggle New Projects on again + await clickText('New Projects'); + toggleState = await containsClass(newProjectsToggle, 'nv-disabled'); + await expect(toggleState).toBe(false); + }); +}); From bd61b24407de6146867688faee68718ec2b67e4a Mon Sep 17 00:00:00 2001 From: BryceLTaylor Date: Mon, 15 Nov 2021 10:35:11 -0500 Subject: [PATCH 2/2] fix statistics test to check if disabled is false --- test/integration/statistics.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/statistics.test.js b/test/integration/statistics.test.js index 1963e49e7..8d0981f90 100644 --- a/test/integration/statistics.test.js +++ b/test/integration/statistics.test.js @@ -42,8 +42,8 @@ describe('www-integration statistics page', async () => { let toggleXpath = `(//div[@id="activity_chart"]/*[name()='svg']/*[name()='g']/*[name()='g']/*` + `[name()='g'])[4]/*[name()='g']/*[name()='g']/*[name()='g']`; let newProjectsToggle = await findByXpath(toggleXpath); - let toggleState = await containsClass(newProjectsToggle, 'nv-series'); - await expect(toggleState).toBe(true); + let toggleState = await containsClass(newProjectsToggle, 'nv-disabled'); + await expect(toggleState).toBe(false); });