2024-08-17 13:24:31 -05:00
|
|
|
import {expect} from '@playwright/test';
|
2024-09-16 01:33:39 -05:00
|
|
|
import {AxeBuilder} from '@axe-core/playwright';
|
2024-08-17 13:24:31 -05:00
|
|
|
|
|
|
|
export async function validate_form({page}, scope) {
|
|
|
|
scope ??= 'form';
|
2024-08-19 16:35:37 -05:00
|
|
|
const accessibilityScanResults = await new AxeBuilder({page})
|
2024-08-17 17:33:50 -05:00
|
|
|
// disable checking for link style - should be fixed, but not now
|
|
|
|
.disableRules('link-in-text-block')
|
2024-08-19 16:35:37 -05:00
|
|
|
.include(scope)
|
|
|
|
// exclude automated tooltips from accessibility scan, remove when fixed
|
|
|
|
.exclude('span[data-tooltip-content')
|
2024-08-17 17:33:50 -05:00
|
|
|
// exclude weird non-semantic HTML disabled content
|
|
|
|
.exclude('.disabled')
|
2024-08-19 16:35:37 -05:00
|
|
|
.analyze();
|
2024-08-17 13:24:31 -05:00
|
|
|
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');
|
|
|
|
}
|
2024-09-22 14:21:54 -05:00
|
|
|
|
2024-08-17 17:33:50 -05:00
|
|
|
// 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();
|
2024-10-23 09:22:25 -05:00
|
|
|
expect(str.split('\n')[0]).not.toContain(':');
|
2024-08-17 17:33:50 -05:00
|
|
|
}
|
2024-09-22 14:21:54 -05:00
|
|
|
|
|
|
|
// 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
|
2024-10-23 09:22:25 -05:00
|
|
|
expect(boxes[i].x).toBe(boxes[0].x);
|
2024-09-22 14:21:54 -05:00
|
|
|
// help texts don't horizontally intersect each other
|
2024-10-23 09:22:25 -05:00
|
|
|
expect(boxes[i].y + boxes[i].height).toBeGreaterThanOrEqual(boxes[i - 1].y + boxes[i - 1].height);
|
2024-09-22 14:21:54 -05:00
|
|
|
}
|
|
|
|
}
|
2024-08-17 13:24:31 -05:00
|
|
|
}
|