-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VR-295: helper and query response e2e test suite. (#236)
* VR-295: helper and query response e2e test suite. * VR-295: assert home page as well (after success). * VR-295: version bump. * VR-295: unwanted file. * VR-295: typo in assert (should have used env var.
- Loading branch information
Showing
4 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,23 @@ | ||
import 'reflect-metadata' | ||
|
||
import { fetchGet, fetchPost } from '../../helpers/routeHelper.js' | ||
|
||
export const co2QueryContent = { | ||
productId: 'E2E-DC001', | ||
quantity: '100', | ||
} | ||
|
||
export async function withQueryRequest(requesterUrl: string) { | ||
const uuidRegex = /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}/ | ||
const connections = await fetchGet(`${requesterUrl}/connection`) | ||
const html = await connections.text() | ||
const [connectionId] = html.match(uuidRegex) || [] | ||
if (!connectionId) { | ||
throw new Error(`Connection not found ${connectionId}`) | ||
} | ||
|
||
await fetchPost(`${requesterUrl}/queries/new/scope-3-carbon-consumption`, { | ||
connectionId, | ||
...co2QueryContent, | ||
}) | ||
} |
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,73 @@ | ||
import { expect, Page, test } from '@playwright/test' | ||
import { withQueryRequest } from './helpers/query.js' | ||
import { cleanup, CustomBrowserContext, withLoggedInUser, withRegisteredAccount } from './helpers/registerLogIn.js' | ||
import { withConnection } from './helpers/setupConnection.js' | ||
|
||
test.describe('New query response', () => { | ||
const AliceHost = process.env.VERITABLE_ALICE_PUBLIC_URL || 'http://localhost:3000' | ||
const BobHost = process.env.VERITABLE_BOB_PUBLIC_URL || 'http://localhost:3001' | ||
|
||
let context: CustomBrowserContext | ||
let page: Page | ||
|
||
test.beforeEach(async ({ browser }) => { | ||
await cleanup([AliceHost, BobHost]) | ||
context = await browser.newContext() | ||
page = await context.newPage() | ||
await withRegisteredAccount(page, context, AliceHost) | ||
await withLoggedInUser(page, context, AliceHost) | ||
await withConnection(AliceHost, BobHost) | ||
await withQueryRequest(AliceHost) | ||
}) | ||
|
||
test.afterAll(async () => { | ||
await cleanup([AliceHost, BobHost]) | ||
await page.close() | ||
}) | ||
|
||
test('responds to total carbon embodiment query (Bob)', async () => { | ||
await test.step('visits queries page and clicks on "respond to query" (Bob)', async () => { | ||
await page.goto(`${BobHost}/queries`) | ||
await page.getByText('Respond to query').click() | ||
|
||
const topHeading = page.getByRole('heading', { name: 'Select' }) | ||
const formHeading = page.getByRole('heading', { name: 'Total' }) | ||
await expect(topHeading).toContainText('Select Company To Send Your Query To') | ||
await expect(formHeading).toContainText('Total Carbon Embodiment') | ||
expect(page.url()).toContain(`${BobHost}/queries/scope-3-carbon-consumption`) | ||
}) | ||
|
||
await test.step('enters emissions and submits a query response', async () => { | ||
await expect(page.getByRole('heading', { name: 'Carbon' })).toContainText('Total Carbon Embodiment') | ||
await page.fill('#co2-emissions-input', '200') | ||
await expect(page.getByRole('button', { name: 'Submit Response' })).toBeVisible() | ||
await expect(page.getByRole('button', { name: 'Submit Response' })).not.toBeDisabled() | ||
await page.getByRole('button', { name: 'Submit Response' }).click() | ||
}) | ||
|
||
await test.step('updates query status to be resolved', async () => { | ||
const button = page.getByText('Back to Home') | ||
await expect(page.getByRole('heading', { name: 'Thank you for your response' })).toBeVisible() | ||
await expect(button).toBeVisible() | ||
await expect(button).not.toBeDisabled() | ||
await expect(page.getByText('Once all supplier responses are received')).toBeVisible() | ||
await expect(page.getByText('You can check the status')).toBeVisible() | ||
await button.click({ delay: 500 }) | ||
}) | ||
|
||
await test.step('returns to home page', async () => { | ||
expect(page.url()).toContain(BobHost) | ||
await expect(page.getByRole('heading', { name: 'Onboard/Refer' })).toBeVisible() | ||
await expect(page.getByRole('heading', { name: 'Onboard/Refer' })).not.toBeDisabled() | ||
|
||
await expect(page.getByRole('heading', { name: 'Queries' })).toBeVisible() | ||
await expect(page.getByRole('heading', { name: 'Queries' })).not.toBeDisabled() | ||
|
||
await expect(page.getByRole('heading', { name: 'Settings' })).toBeVisible() | ||
await expect(page.getByRole('heading', { name: 'Settings' })).not.toBeDisabled() | ||
|
||
await expect(page.getByRole('heading', { name: 'Credentials' })).toBeVisible() | ||
await expect(page.getByRole('heading', { name: 'Credentials' })).not.toBeDisabled() | ||
}) | ||
}) | ||
}) |