-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an e2e test to render all test forms
- Loading branch information
1 parent
aeb4e24
commit 120ad6d
Showing
4 changed files
with
58 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,54 @@ | ||
import { test } from '@playwright/test'; | ||
import { faker } from '@faker-js/faker'; | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test('All forms are rendered and there is no console error', async ({ page }) => { | ||
|
||
let consoleErrors = 0; | ||
|
||
page.on('console', msg => { | ||
if(msg.type() === 'error') { | ||
consoleErrors++; | ||
} | ||
}); | ||
|
||
test('visits the app root url', async ({ page }) => { | ||
await page.goto('/'); | ||
|
||
const forms = await page.getByText('Show').all(); | ||
|
||
for(const form of forms){ | ||
await form.click(); | ||
|
||
// Traverse the form element by element | ||
// if focused element is an editable textbox then fill it | ||
// Exit the loop when focus is on the Send button | ||
// eslint-disable-next-line no-constant-condition | ||
while(true){ | ||
|
||
const onSendButton = await page.evaluate(() => { | ||
const activeElement = document.activeElement; | ||
return activeElement?.tagName === 'BUTTON' && activeElement.textContent === 'Send'; | ||
}); | ||
|
||
if(onSendButton) { | ||
break; | ||
} | ||
|
||
await page.keyboard.press('Tab'); | ||
|
||
const isEditableTextbox = await page.evaluate(() => { | ||
const activeElement = document.activeElement; | ||
return activeElement?.tagName === 'INPUT' && (activeElement as HTMLInputElement).type === 'text' && !activeElement.hasAttribute('readonly'); | ||
}); | ||
|
||
if(isEditableTextbox){ | ||
await page.keyboard.type(faker.internet.displayName()); | ||
} | ||
} | ||
|
||
await page.getByText('Back').click(); | ||
} | ||
|
||
// Assert that there's no console errors | ||
expect(consoleErrors).toBe(0); | ||
|
||
}); |
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 |
---|---|---|
|
@@ -909,6 +909,11 @@ | |
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f" | ||
integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g== | ||
|
||
"@faker-js/[email protected]": | ||
version "8.4.1" | ||
resolved "https://registry.yarnpkg.com/@faker-js/faker/-/faker-8.4.1.tgz#5d5e8aee8fce48f5e189bf730ebd1f758f491451" | ||
integrity sha512-XQ3cU+Q8Uqmrbf2e0cIC/QN43sTBSC8KF12u29Mb47tWrt2hAgBXSgpZMj4Ao8Uk0iJcU99QsOCaIL8934obCg== | ||
|
||
"@fastify/busboy@^2.0.0": | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.0.0.tgz#f22824caff3ae506b18207bad4126dbc6ccdb6b8" | ||
|