Skip to content

Commit

Permalink
Tests: Added tests for ariaLabel option in addMenuToDropdown and role…
Browse files Browse the repository at this point in the history
… of DropdownMenuNestedMenuView.
  • Loading branch information
oleq committed Aug 14, 2024
1 parent f589ed6 commit 1dea3c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/ckeditor5-ui/src/dropdown/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export function createDropdown(
* @param dropdownView A dropdown instance to which the menu component will be added.
* @param body Body collection to which floating menu panels will be added.
* @param definition The menu component definition.
* @param options.ariaLabel Label used by assistive technologies to describe the top-level menu.
*/
export function addMenuToDropdown(
dropdownView: DropdownView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ describe( 'DropdownMenuNestedMenuView', () => {
it( 'should have CSS classes', () => {
expect( menuView.template.attributes.class ).to.include.members( [ 'ck', 'ck-dropdown-menu-list__nested-menu' ] );
} );

it( 'should have a presentation role to keep the a11y tree clean', () => {
expect( menuView.template.attributes.role ).to.include.members( [ 'presentation' ] );
} );
} );
} );

Expand Down
18 changes: 18 additions & 0 deletions packages/ckeditor5-ui/tests/dropdown/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,24 @@ describe( 'utils', () => {
expect( dropdownView.menuView ).to.be.instanceof( DropdownMenuRootListView );
} );

it( 'should set a default aria-label for #menuView', () => {
addMenuToDropdown( dropdownView, body, definition );

dropdownView.isOpen = true;

expect( dropdownView.menuView.ariaLabel ).to.equal( 'Dropdown menu' );
} );

it( 'should allow for configuring a custom aria-label for #menuView', () => {
addMenuToDropdown( dropdownView, body, definition, {
ariaLabel: 'Custom menu dropdown'
} );

dropdownView.isOpen = true;

expect( dropdownView.menuView.ariaLabel ).to.equal( 'Custom menu dropdown' );
} );

it( 'should not do anything before the dropdown is opened for the first time', () => {
addMenuToDropdown( dropdownView, body, definition );

Expand Down

0 comments on commit 1dea3c4

Please sign in to comment.