Skip to content

Commit dbaff60

Browse files
committed
Clean up.
1 parent fe6ae73 commit dbaff60

4 files changed

Lines changed: 62 additions & 36 deletions

File tree

‎package-lock.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"last 2 Opera versions"
2929
],
3030
"devDependencies": {
31-
"@axe-core/playwright": "4.13.0",
31+
"@axe-core/playwright": "^4.13.0",
3232
"@lodder/grunt-postcss": "^3.1.1",
3333
"@playwright/test": "1.61.1",
3434
"@pmmmwh/react-refresh-webpack-plugin": "0.6.2",

‎src/js/media/views/attachments/browser.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ AttachmentsBrowser = View.extend(/** @lends wp.media.view.AttachmentsBrowser.pro
241241
}).render() );
242242

243243
// DateFilter is a <select>, a label element needs to be rendered before.
244-
this.toolbar.set( 'dateFilterLabel', new wp.media.view.Label({
244+
// Re-introduce the bug fixed in https://core.trac.wordpress.org/changeset/62851 for axe-core testing purposes.
245+
this.toolbar.set( 'dateFilter', new wp.media.view.Label({
245246
value: l10n.filterByDate,
246247
attributes: {
247248
'for': 'media-attachment-date-filters'
Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,63 @@
11
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
22
const AxeBuilder = require( '@axe-core/playwright' ).default;
33

4-
test.describe( 'PHP Page Accessibility Tests', () => {
5-
test( 'should not have any automatically detectable accessibility violations', async ( { admin, page, requestUtils } ) => {
6-
7-
// await requestUtils.login();
8-
// await page.goto( 'http://localhost:8889/wp-admin/edit.php');
9-
await admin.visitAdminPage( '/edit.php' );
10-
11-
// 2. Run the axe scan on the rendered page
12-
const scanResults = await new AxeBuilder({ page }).analyze();
13-
14-
// 3. Format and print violations individually if any are found
15-
if (scanResults.violations.length > 0) {
16-
console.log(`\n❌ Found ${scanResults.violations.length} accessibility violation(s):\n`);
17-
18-
scanResults.violations.forEach((violation, index) => {
19-
console.log(`--- Violation #${index + 1} ---`);
20-
console.log(`Rule ID: ${violation.id}`);
21-
console.log(`Impact: ${violation.impact.toUpperCase()}`);
22-
console.log(`Failure: ${violation.description}`);
23-
console.log(`Help Link: ${violation.helpUrl}`);
24-
25-
// List every specific HTML element failing this rule
26-
console.log('Failing Elements:');
27-
violation.nodes.forEach((node) => {
28-
console.log(` - Target Selector: ${node.target.join(', ')}`);
29-
console.log(` HTML Snippet: ${node.html}`);
30-
});
31-
console.log('\n');
32-
});
4+
test.describe( 'Page Accessibility Tests', () => {
5+
test( 'should not have any automatically detectable accessibility violations', async ( { admin, page } ) => {
6+
7+
// The page to be scanned.
8+
await admin.visitAdminPage( '/upload.php?mode=grid' );
9+
10+
const scanResults = await new AxeBuilder( { page } )
11+
.options(
12+
{
13+
runOnly: [ 'wcag2a', 'wcag2aa' ],
14+
rules: {
15+
// This is only to test how to disable a rule.
16+
'aria-allowed-role': { enabled: false },
17+
}
18+
}
19+
)
20+
.analyze();
21+
22+
const violationsAmount = scanResults.violations.length;
23+
24+
if ( violationsAmount > 0 ) {
25+
console.log(`\nFound ${ violationsAmount } accessibility violation(s):\n`);
26+
27+
/*
28+
* Result Object documentation: https://github.com/dequelabs/axe-core/blob/master/doc/API.md#results-object
29+
* This object has four components:
30+
* - a `passes` array: keeps track of all the passed tests,
31+
* along with detailed information on each one.
32+
* - a `violations` array: keeps track of all the failed tests,
33+
* along with detailed information on each one.
34+
* - an `incomplete` array: indicates which nodes could neither be
35+
* determined to definitively pass or definitively
36+
* fail. They are separated out in order that
37+
* a user interface can display these to the
38+
* user for manual review
39+
* - an `inapplicable` array: lists all the rules for which no matching
40+
* elements were found on the page.
41+
*/
42+
scanResults.violations.forEach( ( violation, index ) => {
43+
console.log( `--- Violation #${ index + 1 } ---` );
44+
console.log( `Rule ID: ${ violation.id }` );
45+
console.log( `Impact: ${ violation.impact.toUpperCase() }` );
46+
console.log( `Failure: ${ violation.description }` );
47+
console.log( `Help: ${ violation.help }` );
48+
console.log( `Help link: ${ violation.helpUrl }` );
49+
50+
// List every specific HTML element failing a failing rule.
51+
console.log( 'Failing elements:' );
52+
violation.nodes.forEach( ( node ) => {
53+
console.log( ` - Target Selector: ${ node.target.join( ', ' ) }` );
54+
console.log( ` - HTML Snippet:\n${ node.html }` );
55+
} );
56+
console.log('\n');
57+
} );
3358
}
3459

35-
// 3. Assert that the violations list is empty
36-
expect(scanResults.violations).toEqual([]);
37-
});
38-
});
60+
// Assert that there are no violations.
61+
expect( violationsAmount ).toEqual( 0 );
62+
} );
63+
} );

0 commit comments

Comments
 (0)