-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(a11y): Arrow keys navigation for carousel
- Loading branch information
Showing
10 changed files
with
324 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...red/components/carousel/focusable-carousel-item/focusable-carousel-item-directive.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { FocusableCarouselItemDirective } from './focusable-carousel-item.directive'; | ||
import { LoggerService } from '@spartacus/core'; | ||
import { ElementRef } from '@angular/core'; | ||
const createSpy = jasmine.createSpy; | ||
|
||
describe('FocusableCarouselItemDirective', () => { | ||
let directive: FocusableCarouselItemDirective; | ||
let mockLogger: LoggerService; | ||
let mockElementRef: ElementRef; | ||
|
||
beforeEach(() => { | ||
mockLogger = { | ||
warn: createSpy(), | ||
} as unknown as LoggerService; | ||
|
||
mockElementRef = { | ||
nativeElement: document.createElement('div'), | ||
}; | ||
|
||
directive = new FocusableCarouselItemDirective(mockLogger, mockElementRef); | ||
}); | ||
|
||
it('should warn if element cannot receive focus in dev mode', () => { | ||
const element = document.createElement('div'); | ||
mockElementRef.nativeElement = element; | ||
|
||
directive = new FocusableCarouselItemDirective(mockLogger, mockElementRef); | ||
|
||
expect(mockLogger.warn).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should detect if element is focusable', () => { | ||
mockElementRef.nativeElement = document.createElement('input'); | ||
directive = new FocusableCarouselItemDirective(mockLogger, mockElementRef); | ||
|
||
expect(directive['canElementReceiveFocus']()).toBeTruthy(); | ||
}); | ||
|
||
it('should detect if non-focusable element with non-negative tabindex is focusable', () => { | ||
const element = document.createElement('div'); | ||
element.setAttribute('tabindex', '0'); | ||
mockElementRef.nativeElement = element; | ||
|
||
directive = new FocusableCarouselItemDirective(mockLogger, mockElementRef); | ||
|
||
expect(directive['canElementReceiveFocus']()).toBeTruthy(); | ||
}); | ||
|
||
it('should detect disabled element as not focusable', () => { | ||
const element = document.createElement('input'); | ||
element.setAttribute('disabled', ''); | ||
mockElementRef.nativeElement = element; | ||
|
||
directive = new FocusableCarouselItemDirective(mockLogger, mockElementRef); | ||
|
||
expect(directive['canElementReceiveFocus']()).toBeFalsy(); | ||
}); | ||
}); |
Oops, something went wrong.