Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add persistence acceptance tests #1224

Merged
merged 16 commits into from
Jan 7, 2021
50 changes: 44 additions & 6 deletions tests/acceptance/acceptancesuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@ import VerticalPage from './pageobjects/verticalpage';
import { setupServer, shutdownServer } from './server';
import FacetsPage from './pageobjects/facetspage';
import { Selector } from 'testcafe';
import { browserBackButton, browserRefreshPage } from './utils';

const UNIVERSAL_PAGE = 'http://localhost:9999/tests/acceptance/fixtures/html/universal';
const VERTICAL_PAGE = 'http://localhost:9999/tests/acceptance/fixtures/html/vertical';
const FACETS_PAGE = 'http://localhost:9999/tests/acceptance/fixtures/html/facets';

/**
* This file contains acceptance tests for a universal search page.
* Note that before any tests are run, a local HTTP server is spun
* up to serve the search page and the dist directory of Answers.
* This server is closed once all tests have completed.
*/

fixture`Universal search page works as expected`
.before(setupServer)
.after(shutdownServer)
.page`http://localhost:9999/tests/acceptance/fixtures/html/universal`;
.page`${UNIVERSAL_PAGE}`;

test('Basic universal flow', async t => {
const searchComponent = UniversalPage.getSearchComponent();
Expand All @@ -35,7 +41,7 @@ test('Basic universal flow', async t => {
fixture`Vertical search page works as expected`
.before(setupServer)
.after(shutdownServer)
.page`http://localhost:9999/tests/acceptance/fixtures/html/vertical`;
.page`${VERTICAL_PAGE}`;

test('pagination flow', async t => {
const searchComponent = VerticalPage.getSearchComponent();
Expand All @@ -47,10 +53,31 @@ test('pagination flow', async t => {
await t.expect(pageNum).eql('Page 2');
});

test('navigating and refreshing mantains that page number', async t => {
await t.navigateTo(`${VERTICAL_PAGE}?query=Virginia`);

const paginationComponent = VerticalPage.getPaginationComponent();
await paginationComponent.clickNextButton();
await browserRefreshPage();
const pageNum = await paginationComponent.getActivePageLabelAndNumber();
await t.expect(pageNum).eql('Page 2');
});

test('navigating pages and hitting the browser back button lands you on the right page', async t => {
await t.navigateTo(`${VERTICAL_PAGE}?query=Virginia`);

const paginationComponent = VerticalPage.getPaginationComponent();
await paginationComponent.clickNextButton();
await paginationComponent.clickNextButton();
await browserBackButton();
const pageNum = await paginationComponent.getActivePageLabelAndNumber();
await t.expect(pageNum).eql('Page 2');
});

fixture`Facets page`
.before(setupServer)
.after(shutdownServer)
.page`http://localhost:9999/tests/acceptance/fixtures/html/facets`;
.page`${FACETS_PAGE}`;

test(`Facets load on the page, and can affect the search`, async t => {
const searchComponent = FacetsPage.getSearchComponent();
Expand Down Expand Up @@ -107,10 +134,21 @@ test(`Facets load on the page, and can affect the search`, async t => {
await t.expect(actualResultsCount).eql(initialResultsCount);
});

test(`selecting a sort option and refreshing maintains that sort selection`, async t => {
const searchComponent = FacetsPage.getSearchComponent();
await searchComponent.submitQuery();

const thirdSortOption = await Selector('.yxt-SortOptions-optionSelector').nth(2);
await t.click(thirdSortOption);
await browserRefreshPage();

await t.expect(thirdSortOption.checked).ok();
});

fixture`Experience links work as expected`
.before(setupServer)
.after(shutdownServer)
.page`http://localhost:9999/tests/acceptance/fixtures/html/facets`;
.page`${FACETS_PAGE}`;

test('Facets, pagination, and filters do not persist accross experience links', async t => {
const verifyCleanLink = async (link) => {
Expand Down Expand Up @@ -184,7 +222,7 @@ test('Facets, pagination, and filters do not persist accross experience links',
fixture`Performance marks on search`
.before(setupServer)
.after(shutdownServer)
.page`http://localhost:9999/tests/acceptance/fixtures/html/facets`;
.page`${FACETS_PAGE}`;

test('window.performance calls are marked for a normal search', async t => {
const marksToCheck = [
Expand Down Expand Up @@ -218,7 +256,7 @@ test('window.performance calls are marked for a normal search', async t => {
fixture`W3C Accessibility standards are met`
.before(setupServer)
.after(shutdownServer)
.page`http://localhost:9999/tests/acceptance/fixtures/html/facets`;
.page`${FACETS_PAGE}`;

test('Sort options focus state works', async t => {
const searchComponent = FacetsPage.getSearchComponent();
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/fixtures/html/facets.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
{
label: 'Facets',
url: './links',
url: './facets',
isActive: true
},
{
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/fixtures/html/universal.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
{
label: 'Facets',
url: './links',
url: './facets',
},
{
label: 'Vertical',
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/fixtures/html/vertical.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
{
label: 'Facets',
url: './links',
url: './facets',
},
{
label: 'Vertical',
Expand Down
13 changes: 13 additions & 0 deletions tests/acceptance/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ClientFunction } from 'testcafe';

/* global location */

export async function browserRefreshPage () {
await ClientFunction(() => location.reload())();
await new Promise(resolve => setTimeout(resolve, 2500));
}

export async function browserBackButton () {
await ClientFunction(() => window.history.back())();
await new Promise(resolve => setTimeout(resolve, 2500));
}