Move Search integration tests from Tap to Jest

This commit is contained in:
BryceLTaylor 2021-11-09 15:33:08 -05:00
parent 86ea825867
commit 621169137d
2 changed files with 63 additions and 58 deletions
test
integration-legacy/smoke-testing
integration

View file

@ -1,58 +0,0 @@
/*
* Checks the behavior of the search interface
*/
require('chromedriver');
const seleniumWebdriver = require('selenium-webdriver');
const SeleniumHelper = require('../selenium-helpers.js');
const helper = new SeleniumHelper();
const {
urlMatches
} = helper;
const tap = require('tap');
const test = tap.test;
// Set test url through environment variable
const rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
const searchBaseUrl = `${rootUrl}/search/`;
// chrome driver
const driver = helper.buildDriver('www-search test_search');
tap.plan(3);
tap.tearDown(function () {
driver.quit();
});
tap.beforeEach(function () {
return driver.get(searchBaseUrl);
});
test('Search escapes spaces', function (t) {
const searchInput = driver.findElement(seleniumWebdriver.By.name('q'));
searchInput.sendKeys('Test search string', helper.getKey('ENTER')).then(function () {
urlMatches(/^.*\?q=Test%20search%20string$/)
.then(() => t.end());
});
});
test('Search escapes symbols', function (t) {
const searchInput = driver.findElement(seleniumWebdriver.By.name('q'));
searchInput.sendKeys('100% pen', helper.getKey('ENTER')).then(function () {
urlMatches(/^.*\?q=100%25%20pen$/)
.then(() => t.end());
});
});
test('Switching to studios maintains search string', function (t) {
const searchInput = driver.findElement(seleniumWebdriver.By.name('q'));
searchInput.sendKeys('100% pen', helper.getKey('ENTER')).then(function () {
const studiosTab = driver.findElement(seleniumWebdriver.By.xpath(
'//a/li/span[contains(text(),"Studios")]'));
studiosTab.click().then(function () {
urlMatches(/^.*\?q=100%25%20pen$/)
.then(() => t.end());
});
});
});

View file

@ -0,0 +1,63 @@
// These tests do not sign in with a user
const SeleniumHelper = require('./selenium-helpers.js');
const {
buildDriver,
clickXpath,
findByXpath,
getKey
} = 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(20000);
}
let driver;
describe('www-integration search', () => {
beforeAll(async () => {
driver = await buildDriver('www-integration search');
});
beforeEach(async () => {
await driver.get(rootUrl);
});
afterAll(async () => await driver.quit());
test('search converts spaces', async () => {
let searchBar = await findByXpath('//div[contains(@class, "search-wrapper")]/div/input');
await searchBar.sendKeys('Test search string' + getKey('ENTER'));
// check url
let url = await driver.getCurrentUrl();
await expect(url).toMatch(/^.*\?q=Test%20search%20string$/);
});
test('Search escapes symbols', async () => {
let searchBar = await findByXpath('//div[contains(@class, "search-wrapper")]/div/input');
await searchBar.sendKeys('100% pen' + getKey('ENTER'));
// check url
let url = await driver.getCurrentUrl();
await expect(url).toMatch(/^.*\?q=100%25%20pen$/);
});
test('Switching to studios maintains search string', async () => {
let searchBar = await findByXpath('//div[contains(@class, "search-wrapper")]/div/input');
await searchBar.sendKeys('100% pen' + getKey('ENTER'));
// switch to studios tab
clickXpath('//a/li/span[contains(text(),"Studios")]');
// check url
let url = await driver.getCurrentUrl();
await expect(url).toMatch(/^.*\?q=100%25%20pen$/);
});
});