mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-23 15:47:53 -05:00
Convert integration tests for statistics page from Tap to Jest
This commit is contained in:
parent
107324aa59
commit
995c01bccf
2 changed files with 66 additions and 68 deletions
|
@ -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());
|
||||
});
|
66
test/integration/statistics.test.js
Normal file
66
test/integration/statistics.test.js
Normal file
|
@ -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);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue