Skip to content

Commit

Permalink
feedback from group review
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenkilbourn committed Feb 16, 2024
1 parent 4ff942c commit 23a7cfa
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 8 deletions.
3 changes: 3 additions & 0 deletions e2e/generateMockTestData.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ const fg = require('fast-glob');
const catalogPaths = fg.globSync('mock/datasets/*.mdx');
const storyPaths = fg.globSync('mock/stories/*.mdx');
const catalogNames = [];
const datasetIds = [];
const storyNames = [];

const linkTestStories = ['Internal Link Test', 'External Link Test'];

for (const catalog of catalogPaths) {
const catalogData = matter.read(catalog).data;
catalogNames.push(catalogData['name']);
datasetIds.push(catalogData['id']);
}

for (const story of storyPaths) {
Expand All @@ -24,6 +26,7 @@ for (const story of storyPaths) {

const testDataJson = {
catalogs: catalogNames,
datasetIds: datasetIds,
stories: storyNames
};

Expand Down
4 changes: 4 additions & 0 deletions e2e/pages/analysisPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export default class AnalysisPage {
readonly generateAnalysisButton: Locator;
readonly datasetOptions: Locator;
readonly datasetCheckbox: Locator;
readonly moreOptionsButton: Locator;
readonly northAmericaOption: Locator;


constructor(page: Page) {
Expand All @@ -18,6 +20,8 @@ export default class AnalysisPage {
this.generateAnalysisButton = this.page.getByRole('link', { name: /Generate analysis/i });
this.datasetOptions = this.page.getByTestId('datasetOptions');
this.datasetCheckbox = this.datasetOptions.getByRole('checkbox');
this.moreOptionsButton = this.page.getByRole('button', {name: /more options/i });
this.northAmericaOption = this.page.getByRole('button', {name: /north america/i });
}

async drawPolygon (polygonCorners: number[][]) {
Expand Down
54 changes: 49 additions & 5 deletions e2e/tests/analysis.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from '../pages/basePage';

test('load /analysis route', async ({
test('generate analysis with polygon', async ({
page,
analysisPage,
analysisResultsPage,
Expand All @@ -22,13 +22,15 @@ test('load /analysis route', async ({
const box = await analysisPage.mapboxCanvas.boundingBox();

// using Non-null Assertion because we know the mapbox is visible, therefore box is not null
const firstCorner = [box!.width / 4, box!.height / 4];
const secondCorner = [box!.width / 3, box!.height / 4];
const thirdCorner = [box!.width / 4, box!.height / 3];
const firstCorner = [box!.width * 0.2, box!.height * 0.2];
const secondCorner = [box!.width * 0.8, box!.height * 0.2];
const thirdCorner = [box!.width * 0.8, box!.height * 0.8];
const fourthCorner = [box!.width * 0.2, box!.height * 0.8];


await analysisPage.mapboxCanvas.click();

await analysisPage.drawPolygon([firstCorner, secondCorner, thirdCorner])
await analysisPage.drawPolygon([firstCorner, secondCorner, thirdCorner, fourthCorner])

await analysisPage.clickDatasetOption(1);

Expand All @@ -41,5 +43,47 @@ test('load /analysis route', async ({

await expect(analysisResultsPage.analysisCards.first(), 'at least one analysis results is visible' ).toBeVisible();

// scroll page to bottom
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));

expect(pageErrorCalled, 'no javascript exceptions thrown on page').toBe(false);

});


test('generate analysis with region select', async ({
page,
analysisPage,
analysisResultsPage,
}) => {
let pageErrorCalled = false;
// Log all uncaught errors to the terminal to be visible in trace
page.on('pageerror', exception => {
console.log(`Uncaught exception: "${JSON.stringify(exception)}"`);
pageErrorCalled = true;
});

const mapboxResponsePromise = page.waitForResponse(/api\.mapbox.com\/v4\/mapbox\.mapbox-streets-v8/i);
await page.goto('/analysis');
await expect(analysisPage.header, `analysis page should load`).toBeVisible();
const mapboxResponse = await mapboxResponsePromise;
expect(mapboxResponse.ok(), 'mapbox request should be successful').toBeTruthy();
await expect(analysisPage.mapboxCanvas, 'mapbox canvas should be visible').toBeVisible();

await analysisPage.moreOptionsButton.click();
await analysisPage.northAmericaOption.click();

await analysisPage.clickDatasetOption(1);

const searchResponsePromise = page.waitForResponse(/\/search/i);
await analysisPage.generateAnalysisButton.click({force: true });


const searchResponse = await searchResponsePromise;
expect(searchResponse.ok(), 'request to GET /search should be successful').toBeTruthy();

await expect(analysisResultsPage.analysisCards.first(), 'at least one analysis results is visible' ).toBeVisible();

expect(pageErrorCalled, 'no javascript exceptions thrown on page').toBe(false);

});
38 changes: 38 additions & 0 deletions e2e/tests/exploreDatasets.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import fs from 'fs';
import { test, expect } from '../pages/basePage';

const datasetIds = JSON.parse(fs.readFileSync('e2e/playwrightTestData.json', 'utf8')).datasetIds;

test.describe('catalog card routing', () => {
for (const dataset of datasetIds) {
test.only(`${dataset} routes to dataset details page`, async({
page,
catalogPage,
datasetPage,
}) => {
let pageErrorCalled = false;
// Log all uncaught errors to the terminal to be visible in trace
page.on('pageerror', exception => {
console.log(`Uncaught exception: "${JSON.stringify(exception)}"`);
pageErrorCalled = true;
});

//mosaic isn't hit on all datasets
const collectionsResponsePromise = page.waitForResponse(response =>
response.url().includes('collections') && response.status() === 200
);

await page.goto(`data-catalog/${dataset}/explore`);
await expect(page.getByText('Layers')).toBeVisible();

const mosaicResponse = await collectionsResponsePromise;
expect(mosaicResponse.ok(), 'mapbox request should be successful').toBeTruthy();

// scroll page to bottom
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));

expect(pageErrorCalled, 'no javascript exceptions thrown on page').toBe(false);
});
}

});
3 changes: 3 additions & 0 deletions e2e/tests/storiesRouting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ test.describe('stories card routing', () => {
await storyCard.scrollIntoViewIfNeeded();
await storyCard.click({force: true});
await expect(datasetPage.header.filter({ hasText: item}), `${item} page should load`).toBeVisible();

// scroll page to bottom
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
expect(pageErrorCalled, 'no javascript exceptions thrown on page').toBe(false);
});
}
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
"ts-check": "yarn tsc --noEmit --skipLibCheck",
"test": "jest",
"pretest:e2e": "node e2e/generateMockTestData.js",
"test:e2e": "yarn playwright test",
"pretest:config": "node e2e/generateTestData.js",
"test:config": "yarn playwright test"
"test:e2e": "yarn playwright test"
},
"engines": {
"node": "16.x"
Expand Down

0 comments on commit 23a7cfa

Please sign in to comment.