Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 4 additions & 39 deletions .github/workflows/testcafe_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
timeout-minutes: 6
outputs:
should-run: ${{ steps.check.outputs.should-run }}
styles-changed: ${{ steps.changes.outputs.styles }}
has-quarantined-tests: ${{ steps.quarantined-tests.outputs.has-tests }}
steps:
- uses: actions/checkout@v6
Expand All @@ -47,18 +46,6 @@ jobs:
echo "has-tests=false" >> $GITHUB_OUTPUT
fi

- uses: dorny/paths-filter@v4
id: changes
with:
filters: |
styles:
- 'packages/devextreme-scss/scss/**'
- 'packages/devextreme-scss/icons/**'
- 'packages/devextreme-scss/images/**'
- 'packages/devextreme-scss/fonts/**'
- 'packages/devextreme/js/**/themes/**'
- 'e2e/testcafe-devextreme/helpers/accessibility/**'

build:
name: Build DevExtreme
needs: check-should-run
Expand Down Expand Up @@ -241,14 +228,7 @@ jobs:
- name: Build matrix
id: matrix
run: |
base_matrix_start=$(cat <<'JSON'
[
{ "componentFolder": "accessibility", "name": "accessibility", "concurrency": 6 }
]
JSON
)

base_matrix_end=$(cat <<'JSON'
base_matrix=$(cat <<'JSON'
[
{ "componentFolder": "common", "name": "common", "concurrency": 3 },

Expand All @@ -268,26 +248,11 @@ jobs:
JSON
)

style_dependent_matrix=$(cat <<'JSON'
[
{ "componentFolder": "accessibility", "name": "accessibility - fluent.dark", "theme": "fluent.blue.dark", "concurrency": 6 },
{ "componentFolder": "accessibility", "name": "accessibility - fluent-next.dark", "theme": "fluent-next.blue.dark", "concurrency": 6 },
{ "componentFolder": "accessibility", "name": "accessibility - material.light", "theme": "material.blue.light", "concurrency": 6 },
{ "componentFolder": "accessibility", "name": "accessibility - material.dark", "theme": "material.blue.dark", "concurrency": 6 }
]
JSON
)

matrix=$(jq -c -n \
--argjson baseStart "$base_matrix_start" \
--argjson baseEnd "$base_matrix_end" \
--argjson styleDependent "$style_dependent_matrix" \
--arg stylesChanged "${{ needs.check-should-run.outputs.styles-changed }}" \
--argjson base "$base_matrix" \
'{ include: (
$baseStart
+ (if $stylesChanged == "true" then $styleDependent else [] end)
+ $baseEnd
+ (($baseStart + $baseEnd) | map(
$base
+ ($base | map(
select(.theme == null)
| . + { name: (.name + " - fluent-next"), theme: "fluent-next.blue.light" }
))
Expand Down
129 changes: 129 additions & 0 deletions e2e/playwright/helpers/accessibility/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import type { Page } from '@playwright/test';
import { test as base } from '../../fixtures';
import type { WidgetName } from '../../models/types';
import { DEFAULT_SELECTOR } from '../const';
import { createWidget } from '../createWidget';
import { generateOptionMatrix, type Options } from '../generateOptionMatrix';
import { getThemeName } from '../themeUtils';
import {
a11yCheck, applyViewportEnvironment, type A11yCheckOptions, type A11yContext,
} from './utils';

export const test = base.extend<{ a11yEnvironment: undefined }>({
a11yEnvironment: [async ({ page }, use) => {
await applyViewportEnvironment(page);
await use(undefined);
}, { auto: true }],
});

export { expect } from '../../fixtures';

export interface Configuration<TComponentOptions = unknown> {
component: WidgetName;
// Tells apart the tests of one component when a file declares several configurations.
name?: string;
options?: Options<TComponentOptions>;
a11yCheckConfig?: A11yCheckOptions | ((theme: string) => A11yCheckOptions);
selector?: A11yContext;
created?: (page: Page, optionConfiguration: TComponentOptions) => Promise<void>;
}

export const defaultSelector = DEFAULT_SELECTOR;

export const getDefaultA11yCheckConfig = (theme: string): A11yCheckOptions => (
getThemeName(theme) === 'fluent' ? {} : { runOnly: 'color-contrast' }
);

const FUNCTION_KEY = '__a11yFunction';

// "page.evaluate" drops functions, so templates and callbacks travel as source text and are
// rebuilt in the page. Like a TestCafe ClientFunction dependency, they must not use closures.
const serializeFunctions = (value: unknown): unknown => {
if (typeof value === 'function') {
return { [FUNCTION_KEY]: value.toString() };
}

if (Array.isArray(value)) {
return value.map(serializeFunctions);
}

if (value && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype) {
return Object.fromEntries(
Object.entries(value).map(([key, item]) => [key, serializeFunctions(item)]),
);
}

return value;
};

const restoreFunctions = (serialized: unknown): any => {
const key = '__a11yFunction';

const restore = (value: unknown): unknown => {
if (Array.isArray(value)) {
return value.map(restore);
}

if (value && typeof value === 'object' && !(value instanceof Date)) {
const source = (value as Record<string, unknown>)[key];

if (typeof source === 'string') {
const expression = /^(async\s+)?(function\b|\(|[\w$]+\s*=>)/.test(source)
? source
: `function ${source}`;

// eslint-disable-next-line @typescript-eslint/no-implied-eval
return new Function(`return (${expression});`)();
}

return Object.fromEntries(
Object.entries(value).map(([name, item]) => [name, restore(item)]),
);
}

return value;
};

return restore(serialized);
};

const getOptionConfigurations = <TComponentOptions>(
options: Options<TComponentOptions> | undefined,
): TComponentOptions[] => {
if (!(options && Object.keys(options).length)) {
return [{} as TComponentOptions];
}

return generateOptionMatrix(options);
};

export const testAccessibility = <TComponentOptions = unknown>(
configuration: Configuration<TComponentOptions>,
): void => {
const {
component,
name,
options,
selector = defaultSelector,
a11yCheckConfig,
created,
} = configuration;

getOptionConfigurations(options).forEach((optionConfiguration, index) => {
const title = `${component}${name ? ` ${name}` : ''}: test with axe #${index}`;

test(title, async ({ page, theme }) => {
await createWidget(page, component, restoreFunctions as any, DEFAULT_SELECTOR, {
arg: serializeFunctions(optionConfiguration),
});

await created?.(page, optionConfiguration);

const checkConfig = typeof a11yCheckConfig === 'function'
? a11yCheckConfig(theme)
: a11yCheckConfig ?? getDefaultA11yCheckConfig(theme);

await a11yCheck(page, checkConfig, selector, optionConfiguration);
});
});
};
85 changes: 85 additions & 0 deletions e2e/playwright/helpers/accessibility/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* eslint-disable spellcheck/spell-checker */
import AxeBuilder from '@axe-core/playwright';
import { expect } from '@playwright/test';
import type { Page } from '@playwright/test';
import type { Result, RunOptions } from 'axe-core';
import { getCurrentTheme } from '../testPageUtils';
import { getThemeName } from '../themeUtils';

export interface A11yCheckOptions extends RunOptions {
runOnly?: any;
}

export type A11yContext = string | { include: string[][] };

const COLOR_CONTRAST_RULE = 'color-contrast';

// The TestCafe runner checked accessibility on a "dx-viewport" body, not the "dx-surface" one the
// other tests use: it is where overlays render and what the theme styles as the page background.
export async function applyViewportEnvironment(page: Page): Promise<void> {
await page.evaluate(() => {
const { body } = document;

body.classList.remove('dx-surface');
body.classList.add('dx-viewport');

(window as any).DevExpress.viewPort('.dx-viewport');
});
}

const isColorContrastChecked = (options: A11yCheckOptions): boolean => {
if (options.rules?.[COLOR_CONTRAST_RULE]?.enabled === false) {
return false;
}

return options.runOnly === undefined || options.runOnly === COLOR_CONTRAST_RULE;
};

const formatViolations = (violations: Result[], configuration: unknown): string => {
const lines = violations.flatMap(({
id, impact, help, helpUrl, nodes,
}) => [
`${id} (${impact}): ${help}`,
` ${helpUrl}`,
...nodes.map(({ target, failureSummary }) => ` ${target.join(' ')}\n ${failureSummary?.replace(/\n/g, '\n ')}`),
]);

return [
`${violations.length} accessibility violation(s):`,
...lines,
...(configuration ? [JSON.stringify(configuration)] : []),
].join('\n');
};

export const a11yCheck = async (
page: Page,
options: A11yCheckOptions = {},
selector?: A11yContext,
configuration: unknown = {},
): Promise<void> => {
const isColorContrastOnly = getThemeName(await getCurrentTheme(page)) === 'fluent-next';

if (isColorContrastOnly && !isColorContrastChecked(options)) {
throw new Error(
'a11yCheck was called on fluent-next with a configuration that excludes color-contrast, '
+ 'the only rule this theme runs, so nothing would be checked. Leave color-contrast '
+ 'enabled, or do not declare the test for this theme.',
);
}

const effectiveOptions: A11yCheckOptions = isColorContrastOnly
? { ...options, runOnly: COLOR_CONTRAST_RULE }
: options;

const builder = new AxeBuilder({ page }).options({ rules: {}, ...effectiveOptions });

if (typeof selector === 'string') {
builder.include(selector);
} else if (selector) {
selector.include.forEach((frameSelector) => builder.include(frameSelector));
}

const { violations } = await builder.analyze();

expect(violations.length, formatViolations(violations, configuration)).toBe(0);
};
22 changes: 22 additions & 0 deletions e2e/playwright/models/cardView/card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Locator } from '@playwright/test';

export const CLASS = {
header: 'dx-cardview-card-header',
toolbarItem: 'dx-toolbar-item',
};

export default class Card {
public readonly element: Locator;

constructor(element: Locator) {
this.element = element;
}

public getHeader(): Locator {
return this.element.locator(`.${CLASS.header}`);
}

public getToolbarItem(index: number): Locator {
return this.getHeader().locator(`.${CLASS.toolbarItem}`).nth(index);
}
}
17 changes: 17 additions & 0 deletions e2e/playwright/models/cardView/headerItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Locator } from '@playwright/test';

const CLASS = {
filterIcon: 'dx-header-filter-icon',
};

export default class HeaderItem {
public readonly element: Locator;

constructor(element: Locator) {
this.element = element;
}

public getFilterIcon(): Locator {
return this.element.locator(`.${CLASS.filterIcon}`);
}
}
29 changes: 29 additions & 0 deletions e2e/playwright/models/cardView/headerPanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Locator } from '@playwright/test';
import Widget from '../internal/widget';
import HeaderItem from './headerItem';

const CLASS = {
headerItem: 'header-item',
link: 'link',
};

export default class HeaderPanel {
public readonly element: Locator;

public readonly widgetName: string;

constructor(element: Locator, widgetName: string) {
this.element = element;
this.widgetName = widgetName;
}

public getHeaderItem(idx = 0): HeaderItem {
const itemSelector = `.${Widget.addClassPrefix(this.widgetName, CLASS.headerItem)}`;

return new HeaderItem(this.element.locator(itemSelector).nth(idx));
}

public getColumnChooserLink(): Locator {
return this.element.locator(`.dx-${CLASS.link}`);
}
}
25 changes: 25 additions & 0 deletions e2e/playwright/models/cardView/headers/headers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Locator } from '@playwright/test';
import FocusableElement from '../../internal/focusable';
import Widget from '../../internal/widget';
import HeaderItem from './item';

const CLASS = {
headerItem: 'header-item',
};

export default class HeadersElement extends FocusableElement {
public readonly widgetName: string;

constructor(element: Locator, widgetName: string) {
super(element);
this.widgetName = widgetName;
}

public getHeaderItemNth(nth: number): HeaderItem {
const selector = this.element
.locator(`.${Widget.addClassPrefix(this.widgetName, CLASS.headerItem)}`)
.nth(nth);

return new HeaderItem(selector, this.widgetName);
}
}
11 changes: 11 additions & 0 deletions e2e/playwright/models/cardView/headers/item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Locator } from '@playwright/test';
import FocusableElement from '../../internal/focusable';

export default class HeaderItem extends FocusableElement {
public readonly widgetName: string;

constructor(element: Locator, widgetName: string) {
super(element);
this.widgetName = widgetName;
}
}
Loading
Loading