Skip to content

Commit

Permalink
Added an e2e test to render all test forms
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiqkhoja committed Apr 5, 2024
1 parent aeb4e24 commit 120ad6d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
53 changes: 51 additions & 2 deletions packages/ui-vue/e2e/vue.spec.ts
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);

});
1 change: 1 addition & 0 deletions packages/ui-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"vue-router": "^4.3.0"
},
"devDependencies": {
"@faker-js/faker": "8.4.1",
"@playwright/test": "^1.42.1",
"@types/ramda": "0.29.11",
"@vitejs/plugin-vue": "^5.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-vue/src/components/OdkForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ initializeForm(props.formXml, {
const handleSubmit = () => {
// TODO/sk: it is not yet decided where engine will return submission data
// following is just a temporary line for personal satisfaction
emit('submit', (odkForm as any).contextNode.outerHTML); // eslint-disable-line
emit('submit', (odkForm as any).value.contextNode.outerHTML); // eslint-disable-line
}
</script>

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 120ad6d

Please sign in to comment.