Skip to content

Commit db38bcc

Browse files
committed
push some updates
1 parent 62cd34a commit db38bcc

6 files changed

Lines changed: 42 additions & 24 deletions

File tree

src/platform/packages/shared/kbn-axe-config/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ export const AXE_OPTIONS = {
5050
},
5151
},
5252
};
53+
54+
export const AXE_IMPACT_LEVELS: Array<'minor' | 'moderate' | 'serious' | 'critical'> = [
55+
'critical',
56+
'serious',
57+
];

src/platform/packages/shared/kbn-scout/src/playwright/fixtures/scope/test/scout_page/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import type { Page } from '@playwright/test';
11-
import type { A11yViolation } from '../../../../utils';
11+
import type { RunA11yScanOptions } from '../../../../utils';
1212
import type { PathOptions } from '../../../../../common/services/kibana_url';
1313

1414
/**
@@ -42,9 +42,16 @@ export type ScoutPage = Page & {
4242
*/
4343
keyTo: (selector: string, key: string, maxElementsToTraverse?: number) => Promise<void>;
4444

45-
// @todo
46-
checkA11y: () => Promise<{
47-
violations: A11yViolation[];
45+
/**
46+
* Performs an accessibility (a11y) scan of the current page using axe-core.
47+
* Use this in tests to collect formatted violation summaries (one string per violation).
48+
*
49+
* @param options - Optional accessibility scan configuration (e.g. selectors to exclude, timeout).
50+
* @returns A Promise resolving to an object with a 'violations' array containing
51+
* human-readable formatted strings for each detected violation (empty if none).
52+
*/
53+
checkA11y: (options?: RunA11yScanOptions) => Promise<{
54+
violations: string[];
4855
}>;
4956

5057
/**

src/platform/packages/shared/kbn-scout/src/playwright/fixtures/scope/test/scout_page/single_thread.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { Page } from '@playwright/test';
1212
import { test as base } from '@playwright/test';
1313
import type { ScoutPage } from '.';
1414
import type { PathOptions } from '../../../../../common/services/kibana_url';
15-
import { keyTo, checkA11y } from '../../../../utils';
15+
import { keyTo, checkA11y, type RunA11yScanOptions } from '../../../../utils';
1616
import type { KibanaUrl, ScoutLogger } from '../../worker';
1717

1818
/**
@@ -109,7 +109,7 @@ export function extendPlaywrightPage({
109109
return await keyTo(page, selector, key, maxElementsToTraverse);
110110
};
111111

112-
extendedPage.checkA11y = () => checkA11y(page, kbnUrl);
112+
extendedPage.checkA11y = (options) => checkA11y(page, kbnUrl, options);
113113

114114
// Method to type text with delay character by character
115115
extendedPage.typeWithDelay = (selector: string, text: string, options?: { delay: number }) =>

src/platform/packages/shared/kbn-scout/src/playwright/utils/axe.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import type { Page } from '@playwright/test';
1111
import AxeBuilder from '@axe-core/playwright';
12-
import { AXE_OPTIONS } from '@kbn/axe-config';
12+
import { AXE_OPTIONS, AXE_IMPACT_LEVELS } from '@kbn/axe-config';
1313

1414
import type { KibanaUrl } from '../../..';
1515

@@ -30,8 +30,6 @@ export interface A11yViolation {
3030
export interface RunA11yScanOptions {
3131
/** Optional CSS selectors to exclude from scan */
3232
exclude?: string[];
33-
/** Optional result impact levels to include (e.g. \['critical','serious'\]) */
34-
impactLevels?: Array<'minor' | 'moderate' | 'serious' | 'critical'>;
3533
/** Timeout in ms for the scan (defaults 10000) */
3634
timeoutMs?: number;
3735
}
@@ -42,13 +40,15 @@ export interface RunA11yScanResult {
4240

4341
export const runA11yScan = async (
4442
page: Page,
45-
{ exclude = [], impactLevels, timeoutMs = 10000 }: RunA11yScanOptions = {}
43+
{ exclude = [], timeoutMs = 10000 }: RunA11yScanOptions = {}
4644
): Promise<RunA11yScanResult> => {
4745
const builder = new AxeBuilder({ page });
4846
builder.options(AXE_OPTIONS);
4947

50-
for (const selector of exclude) {
51-
builder.exclude(selector);
48+
if (exclude) {
49+
for (const selector of exclude) {
50+
builder.exclude(selector);
51+
}
5252
}
5353

5454
const analysisPromise = builder.analyze();
@@ -70,10 +70,10 @@ export const runA11yScan = async (
7070

7171
let violations = (result.violations as A11yViolation[]) || [];
7272

73-
if (impactLevels && impactLevels.length) {
74-
const allowed = new Set(impactLevels);
73+
if (AXE_IMPACT_LEVELS?.length) {
74+
const allowed = new Set(AXE_IMPACT_LEVELS);
7575
violations = violations.filter(
76-
(v) => v.impact && allowed.has(v.impact as (typeof impactLevels)[number])
76+
(v) => v.impact && allowed.has(v.impact as (typeof AXE_IMPACT_LEVELS)[number])
7777
);
7878
}
7979

@@ -83,13 +83,19 @@ export const runA11yScan = async (
8383
/**
8484
* Assert helper usable inside tests.
8585
*/
86-
export const checkA11y = async (page: Page, kbnUrl?: KibanaUrl) => {
87-
const { violations } = await runA11yScan(page);
86+
export const checkA11y = async (page: Page, kbnUrl?: KibanaUrl, options?: RunA11yScanOptions) => {
87+
const { violations } = await runA11yScan(page, options);
8888

8989
return {
90-
violations: violations.map((v) => ({
91-
...v,
92-
url: kbnUrl?.toString(),
93-
})),
90+
violations: violations.map(
91+
(v) =>
92+
`Accessibility violation: ${v.id} (${v.impact}): \n
93+
${v.helpUrl}\n
94+
${v.description}\n
95+
${kbnUrl} \n
96+
Nodes:\n${v.nodes
97+
.map((n) => ` ${n.target.join(', ')} -> ${n.failureSummary}`)
98+
.join('\n')}`
99+
),
94100
};
95101
};

src/platform/packages/shared/kbn-scout/src/playwright/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
export { isValidUTCDate, formatTime, getPlaywrightGrepTag, execPromise } from './runner_utils';
1111
export { resolveSelector, type SelectorInput } from './locator_helper';
1212
export { keyTo } from './a11y_utils';
13-
export { checkA11y, type A11yViolation } from './axe';
13+
export { checkA11y, type RunA11yScanOptions } from './axe';

src/platform/packages/shared/kbn-scout/test/scout/ui/tests/utils/axe.spec.ts renamed to src/platform/packages/shared/kbn-scout/test/scout/ui/tests/axe.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
import { test, expect } from '../../../../../src/playwright';
10+
import { test, expect } from '../../../../src/playwright';
1111

12-
test.describe('runA11yScan', () => {
12+
test.describe('runA11yScan', { tag: ['@svlSecurity', '@ess'] }, () => {
1313
test('returns violations array (empty for basic accessible markup)', async ({ page }) => {
1414
await page.setContent(`
1515
<main>

0 commit comments

Comments
 (0)