-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d65a470
commit 1298908
Showing
2 changed files
with
66 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { test, expect, Page } from '@playwright/test'; | ||
|
||
test('Chat component e2e test', async ({ page }) => { | ||
async function runTestScenario( | ||
page: Page, | ||
formId: string, | ||
messages: string[], | ||
expected: object, | ||
) { | ||
// Navigate to the specified URL | ||
await page.goto( | ||
'http://localhost:3000/forms/fill/bb16be91-9ba7-40b8-8e3d-ead3cf3184ca' | ||
); | ||
|
||
// List of messages to be inputted | ||
const messages = [ | ||
'John Doe', | ||
'[email protected]', | ||
'Big Tech Co.', | ||
'Software Engineer', | ||
'github.com/jd123456', | ||
'PostHog', | ||
]; | ||
await page.goto(`http://localhost:3000/forms/fill/${formId}`); | ||
|
||
for (const message of messages) { | ||
// Wait for input to be enabled and visible | ||
|
@@ -26,25 +19,69 @@ test('Chat component e2e test', async ({ page }) => { | |
|
||
// Press 'Enter' to submit the message | ||
await page.press(inputSelector, 'Enter'); | ||
|
||
// Optional: Add a delay if needed for smooth simulations | ||
// await page.waitForTimeout(1000); | ||
} | ||
|
||
// Wait for the submission modal | ||
await page.waitForSelector('#submissionBox', { state: 'attached' }); | ||
|
||
// Verify that the submission modal has the expected content | ||
const modalContent = await page.textContent('#submissionBox p'); | ||
|
||
const expected = { | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
company: 'Big Tech Co.', | ||
job_title: 'Software Engineer', | ||
marketing_technologies: 'PostHog', | ||
github: 'github.com/jd123456', | ||
}; | ||
const parsed = JSON.parse(modalContent || ''); | ||
expect(parsed).toEqual(expected); | ||
}); | ||
} | ||
|
||
// Define your list of test scenarios | ||
const testScenarios = [ | ||
{ | ||
name: 'Simple RSVP', | ||
formId: 'bb16be91-9ba7-40b8-8e3d-ead3cf3184ca', | ||
messages: [ | ||
'John Doe', | ||
'[email protected]', | ||
'Big Tech Co.', | ||
'Software Engineer', | ||
'github.com/jd123456', | ||
'PostHog', | ||
], | ||
expected: { | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
company: 'Big Tech Co.', | ||
job_title: 'Software Engineer', | ||
marketing_technologies: 'PostHog', | ||
github: 'jd123456', | ||
}, | ||
}, | ||
{ | ||
name: 'public-facing demo', | ||
formId: '5771953d-a003-4969-9071-fcfff4c5bb10', | ||
messages: [ | ||
'Nick', | ||
'[email protected]', | ||
'big tech co', | ||
'eng manager', | ||
'https://github.com/nsbradford', | ||
'google analytics and Posthog', | ||
], | ||
expected: { | ||
name: 'Nick', | ||
email_address: '[email protected]', | ||
company: 'big tech co', | ||
job_title: 'eng manager', | ||
github_username: 'nsbradford', | ||
technologies_used: 'google analytics, Posthog', | ||
}, | ||
}, | ||
]; | ||
|
||
// Iterate through your scenarios to run the tests | ||
for (const scenario of testScenarios) { | ||
test(`Chat component e2e test: ${scenario.name}`, async ({ page }) => { | ||
await runTestScenario( | ||
page, | ||
scenario.formId, | ||
scenario.messages, | ||
scenario.expected | ||
); | ||
}); | ||
} |