Skip to content

Commit

Permalink
VR-295: helper and query response e2e test suite. (#236)
Browse files Browse the repository at this point in the history
* 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
n3op2 authored Nov 13, 2024
1 parent ad1ad1f commit cb17dda
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "veritable-ui",
"version": "0.14.13",
"version": "0.14.14",
"description": "UI for Veritable",
"main": "src/index.ts",
"type": "module",
Expand Down
23 changes: 23 additions & 0 deletions test/e2e/helpers/query.ts
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,
})
}
73 changes: 73 additions & 0 deletions test/e2e/new-query-respose.spec.ts
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()
})
})
})

0 comments on commit cb17dda

Please sign in to comment.