summaryrefslogtreecommitdiffstats
path: root/tests/e2e/shared/forms.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
commitdd136858f1ea40ad3c94191d647487fa4f31926c (patch)
tree58fec94a7b2a12510c9664b21793f1ed560c6518 /tests/e2e/shared/forms.js
parentInitial commit. (diff)
downloadforgejo-upstream.tar.xz
forgejo-upstream.zip
Adding upstream version 9.0.0.upstream/9.0.0upstreamdebian
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'tests/e2e/shared/forms.js')
-rw-r--r--tests/e2e/shared/forms.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/e2e/shared/forms.js b/tests/e2e/shared/forms.js
new file mode 100644
index 0000000..0ffd6ee
--- /dev/null
+++ b/tests/e2e/shared/forms.js
@@ -0,0 +1,44 @@
+import {expect} from '@playwright/test';
+import {AxeBuilder} from '@axe-core/playwright';
+
+export async function validate_form({page}, scope) {
+ scope ??= 'form';
+ const accessibilityScanResults = await new AxeBuilder({page})
+ // disable checking for link style - should be fixed, but not now
+ .disableRules('link-in-text-block')
+ .include(scope)
+ // exclude automated tooltips from accessibility scan, remove when fixed
+ .exclude('span[data-tooltip-content')
+ // exclude weird non-semantic HTML disabled content
+ .exclude('.disabled')
+ .analyze();
+ expect(accessibilityScanResults.violations).toEqual([]);
+
+ // assert CSS properties that needed to be overriden for forms (ensure they remain active)
+ const boxes = page.getByRole('checkbox').or(page.getByRole('radio'));
+ for (const b of await boxes.all()) {
+ await expect(b).toHaveCSS('margin-left', '0px');
+ await expect(b).toHaveCSS('margin-top', '0px');
+ await expect(b).toHaveCSS('vertical-align', 'baseline');
+ }
+
+ // assert no (trailing) colon is used in labels
+ // might be necessary to adjust in case colons are strictly necessary in help text
+ for (const l of await page.locator('label').all()) {
+ const str = await l.textContent();
+ await expect(str.split('\n')[0]).not.toContain(':');
+ }
+
+ // check that multiple help text are correctly aligned to each other
+ // used for example to separate read/write permissions in team permission matrix
+ for (const l of await page.locator('label:has(.help + .help)').all()) {
+ const helpLabels = await l.locator('.help').all();
+ const boxes = await Promise.all(helpLabels.map((help) => help.boundingBox()));
+ for (let i = 1; i < boxes.length; i++) {
+ // help texts vertically aligned on top of each other
+ await expect(boxes[i].x).toBe(boxes[0].x);
+ // help texts don't horizontally intersect each other
+ await expect(boxes[i].y + boxes[i].height).toBeGreaterThanOrEqual(boxes[i - 1].y + boxes[i - 1].height);
+ }
+ }
+}