-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "move tests into ui submodule"
This reverts commit 258e7fc.
- Loading branch information
1 parent
258e7fc
commit 2f6b1a6
Showing
20 changed files
with
500 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Locator, Page } from '@playwright/test'; | ||
|
||
export default class AboutPage { | ||
readonly page: Page; | ||
readonly mainContent: Locator; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.mainContent = this.page.getByRole('main'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Locator, Page, test } from '@playwright/test'; | ||
|
||
export default class AnalysisPage { | ||
readonly page: Page; | ||
readonly mainContent: Locator; | ||
readonly header: Locator; | ||
readonly mapboxCanvas: Locator; | ||
readonly generateAnalysisButton: Locator; | ||
readonly datasetOptions: Locator; | ||
readonly datasetCheckbox: Locator; | ||
|
||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.mainContent = this.page.getByRole('main'); | ||
this.header = this.mainContent.getByRole('heading', {level: 1, name: /analysis/i }); | ||
this.mapboxCanvas = this.page.getByLabel('Map', { exact: true }); | ||
this.generateAnalysisButton = this.page.getByRole('link', { name: /Generate analysis/i }); | ||
this.datasetOptions = this.page.getByTestId('datasetOptions'); | ||
this.datasetCheckbox = this.datasetOptions.getByRole('checkbox'); | ||
} | ||
|
||
async drawPolygon (polygonCorners: number[][]) { | ||
await test.step('draw polygon on mapbox canvas box', async () => { | ||
if(polygonCorners.length < 3) { | ||
throw new Error('polygon in drawPolygon must have >=3 corners') | ||
} | ||
// mutating corners array to have all but the final corner | ||
const finalCorner = polygonCorners.pop()|| []; | ||
|
||
// single click each remaining corner | ||
for (const corner of polygonCorners) { | ||
await this.mapboxCanvas.click({ | ||
position: { | ||
x: corner[0], | ||
y: corner[1] | ||
} | ||
}); | ||
} | ||
// double click on final corner | ||
await this.mapboxCanvas.dblclick({ | ||
position: { | ||
x: finalCorner[0], | ||
y: finalCorner[1] | ||
} | ||
}); | ||
}) | ||
} | ||
|
||
async clickDatasetOption (index: number) { | ||
test.step(`clicking dataset number ${index}`, async () => { | ||
this.datasetCheckbox.nth(index).locator('..').click(); | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Locator, Page } from '@playwright/test'; | ||
|
||
export default class AnalysisResultsPage { | ||
readonly page: Page; | ||
readonly analysisCards: Locator; | ||
|
||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.analysisCards = this.page.getByTestId('analysisCards'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { test as base } from '@playwright/test'; | ||
import AboutPage from './aboutPage'; | ||
import AnalysisPage from './analysisPage'; | ||
import AnalysisResultsPage from './analysisResultsPage'; | ||
import HomePage from './homePage'; | ||
import FooterComponent from './footerComponent'; | ||
import HeaderComponent from './headerComponent'; | ||
import CatalogPage from './catalogPage'; | ||
import DatasetPage from './datasetPage'; | ||
import StoryPage from './storyPage'; | ||
|
||
export const test = base.extend<{ | ||
aboutPage: AboutPage; | ||
analysisPage: AnalysisPage; | ||
analysisResultsPage: AnalysisResultsPage; | ||
footerComponent: FooterComponent; | ||
headerComponent: HeaderComponent; | ||
homePage: HomePage; | ||
catalogPage: CatalogPage; | ||
datasetPage: DatasetPage; | ||
storyPage: StoryPage | ||
}> ({ | ||
aboutPage: async ({page}, use) => { | ||
await use(new AboutPage(page)); | ||
}, | ||
analysisPage: async ({page}, use) => { | ||
await use(new AnalysisPage(page)); | ||
}, | ||
analysisResultsPage: async ({page}, use) => { | ||
await use(new AnalysisResultsPage(page)); | ||
}, | ||
catalogPage: async ({page}, use) => { | ||
await use(new CatalogPage(page)); | ||
}, | ||
datasetPage: async ({page}, use) => { | ||
await use(new DatasetPage(page)); | ||
}, | ||
homePage: async ({page}, use) => { | ||
await use(new HomePage(page)); | ||
}, | ||
storyPage: async ({page}, use) => { | ||
await use(new StoryPage(page)); | ||
}, | ||
headerComponent: async ({page}, use) => { | ||
await use(new HeaderComponent(page)); | ||
}, | ||
footerComponent: async ({page}, use) => { | ||
await use(new FooterComponent(page)); | ||
}, | ||
}); | ||
|
||
export const expect = test.expect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Locator, Page } from '@playwright/test'; | ||
|
||
export default class CatalogPage { | ||
readonly page: Page; | ||
readonly mainContent: Locator; | ||
readonly header: Locator; | ||
|
||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.mainContent = this.page.getByRole('main'); | ||
this.header = this.mainContent.getByRole('heading', {level: 1}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Locator, Page } from '@playwright/test'; | ||
|
||
export default class DatasetPage { | ||
readonly page: Page; | ||
readonly mainContent: Locator; | ||
readonly header: Locator; | ||
readonly exploreDataButton: Locator; | ||
readonly analyzeDataButton: Locator; | ||
|
||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.mainContent = this.page.getByRole('main'); | ||
this.header = this.mainContent.getByRole('heading', { level: 1 }) | ||
this.exploreDataButton = this.page.getByRole('link', {name: /explore data/i} ); | ||
this.analyzeDataButton = this.page.getByRole('button', {name: /analyze data/i} ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Locator, Page } from '@playwright/test'; | ||
|
||
export default class FooterComponent { | ||
readonly page: Page; | ||
readonly footer: Locator; | ||
readonly partners: Locator; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.footer = this.page.locator('footer'); | ||
this.partners = this.footer.locator('div'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Locator, Page } from '@playwright/test'; | ||
|
||
export default class HeaderComponent { | ||
readonly page: Page; | ||
readonly header: Locator; | ||
readonly welcomeLink: Locator; | ||
readonly dataCatalogLink: Locator; | ||
readonly analysisLink: Locator; | ||
readonly dataInsightsLink: Locator; | ||
readonly aboutLink: Locator; | ||
readonly feedbackLink: Locator; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.header = this.page.getByRole('navigation'); | ||
this.welcomeLink = this.header.getByRole('link', {name: /welcome/i}); | ||
this.dataCatalogLink = this.header.getByRole('link', {name: / data catalog/i}); | ||
this.analysisLink = this.header.getByRole('link', {name: /analysis/i}); | ||
this.dataInsightsLink = this.header.getByRole('link', {name: /data insights/i}); | ||
this.aboutLink = this.header.getByRole('link', {name: /about/i}); | ||
this.feedbackLink = this.header.getByRole('link', {name: /feedback/i}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Locator, Page } from '@playwright/test'; | ||
|
||
export default class HomePage { | ||
readonly page: Page; | ||
readonly mainContent: Locator; | ||
readonly headingContainer: Locator; | ||
|
||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.mainContent = this.page.getByRole('main'); | ||
this.headingContainer = this.mainContent.locator('div').filter({ hasText: 'U.S. Greenhouse Gas CenterUniting Data and Technology to Empower Tomorrow\'s' }).nth(2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Locator, Page } from '@playwright/test'; | ||
|
||
export default class StoryPage { | ||
readonly page: Page; | ||
readonly mainContent: Locator; | ||
readonly header: Locator; | ||
|
||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.mainContent = this.page.getByRole('main'); | ||
this.header = this.mainContent.getByRole('heading', {level: 1}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { test, expect } from '../pages/basePage'; | ||
|
||
test('load /analysis route', async ({ | ||
page, | ||
analysisPage, | ||
analysisResultsPage, | ||
}) => { | ||
let pageErrorCalled = false; | ||
// Log all uncaught errors to the terminal | ||
page.on('pageerror', exception => { | ||
console.log(`Uncaught exception: "${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(); | ||
|
||
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]; | ||
|
||
await analysisPage.mapboxCanvas.click(); | ||
|
||
await analysisPage.drawPolygon([firstCorner, secondCorner, thirdCorner]) | ||
|
||
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(); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { test, expect } from '../pages/basePage'; | ||
|
||
const catalogs = JSON.parse(require('fs').readFileSync('e2e/playwrightTestData.json', 'utf8'))['catalogs']; | ||
|
||
test('load catalogs on /data-catalog route', async ({ | ||
page, | ||
catalogPage, | ||
}) => { | ||
let pageErrorCalled = false; | ||
// Log all uncaught errors to the terminal | ||
page.on('pageerror', exception => { | ||
console.log(`Uncaught exception: "${exception}"`); | ||
pageErrorCalled = true; | ||
}); | ||
|
||
await page.goto('/data-catalog'); | ||
await expect(catalogPage.header, `catalog page should load`).toHaveText(/data catalog/i); | ||
|
||
for (const item of catalogs) { | ||
const catalogCard = catalogPage.mainContent.getByRole('article').getByRole('heading', { level: 3, name: item, exact: true}).last(); | ||
await catalogCard.scrollIntoViewIfNeeded(); | ||
await expect(catalogCard, `${item} catalog card should load`).toBeVisible(); | ||
}; | ||
|
||
expect(pageErrorCalled, 'no javascript exceptions thrown on page').toBe(false) | ||
|
||
}); |
Oops, something went wrong.