scratch-www/test/integration/search.test.js
2023-10-24 14:03:18 -07:00

58 lines
1.7 KiB
JavaScript

// These tests do not sign in with a user
const SeleniumHelper = require('./selenium-helpers.js');
const {
buildDriver,
clickXpath,
findByXpath,
getKey
} = new SeleniumHelper();
const rootUrl = process.env.ROOT_URL || 'https://scratch.ly';
jest.setTimeout(60000);
let driver;
describe('www-integration search', () => {
beforeAll(async () => {
driver = await buildDriver('www-integration search');
});
beforeEach(async () => {
await driver.get(rootUrl);
});
afterAll(() => driver.quit());
test('search converts spaces', async () => {
const searchBar = await findByXpath('//div[contains(@class, "search-wrapper")]/div/input');
await searchBar.sendKeys(`Test search string${getKey('ENTER')}`);
// check url
const url = await driver.getCurrentUrl();
expect(url).toMatch(/^.*\?q=Test%20search%20string$/);
});
test('Search escapes symbols', async () => {
const searchBar = await findByXpath('//div[contains(@class, "search-wrapper")]/div/input');
await searchBar.sendKeys(`100% pen${getKey('ENTER')}`);
// check url
const url = await driver.getCurrentUrl();
expect(url).toMatch(/^.*\?q=100%25%20pen$/);
});
test('Switching to studios maintains search string', async () => {
const 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
const url = await driver.getCurrentUrl();
expect(url).toMatch(/^.*\?q=100%25%20pen$/);
});
});