|
| 1 | +import $ from '@js/core/renderer'; |
| 2 | + |
| 3 | +import { AreaItem } from '../area_item/m_area_item'; |
| 4 | + |
| 5 | +class TestAreaItem extends AreaItem { |
| 6 | + _getAreaName() { |
| 7 | + return 'row'; |
| 8 | + } |
| 9 | +} |
| 10 | + |
| 11 | +const createMockComponent = () => ({ |
| 12 | + option(name: string) { |
| 13 | + const options: Record<string, any> = { |
| 14 | + rtlEnabled: false, |
| 15 | + encodeHtml: true, |
| 16 | + onCellPrepared: null, |
| 17 | + }; |
| 18 | + return options[name]; |
| 19 | + }, |
| 20 | + _eventsStrategy: { |
| 21 | + hasEvent: () => false, |
| 22 | + }, |
| 23 | + _defaultActionArgs: () => ({}), |
| 24 | +}); |
| 25 | + |
| 26 | +describe('PivotGrid expand icon accessibility', () => { |
| 27 | + let $container: any = null; |
| 28 | + |
| 29 | + beforeEach(() => { |
| 30 | + $container = $('<div>').appendTo('body'); |
| 31 | + }); |
| 32 | + |
| 33 | + afterEach(() => { |
| 34 | + $container.remove(); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should set aria-expanded="true" on td when cell is expanded', () => { |
| 38 | + const areaItem = new TestAreaItem(createMockComponent()); |
| 39 | + const tableData = [[{ expanded: true, text: 'Category' }]]; |
| 40 | + |
| 41 | + areaItem.render($container, tableData); |
| 42 | + |
| 43 | + const $td = $container.find('td'); |
| 44 | + expect($td.attr('aria-expanded')).toBe('true'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should set aria-expanded="false" on td when cell is collapsed', () => { |
| 48 | + const areaItem = new TestAreaItem(createMockComponent()); |
| 49 | + const tableData = [[{ expanded: false, text: 'Category' }]]; |
| 50 | + |
| 51 | + areaItem.render($container, tableData); |
| 52 | + |
| 53 | + const $td = $container.find('td'); |
| 54 | + expect($td.attr('aria-expanded')).toBe('false'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should set tabindex="0" on td when cell has expand icon', () => { |
| 58 | + const areaItem = new TestAreaItem(createMockComponent()); |
| 59 | + const tableData = [[{ expanded: true, text: 'Category' }]]; |
| 60 | + |
| 61 | + areaItem.render($container, tableData); |
| 62 | + |
| 63 | + const $td = $container.find('td'); |
| 64 | + expect($td.attr('tabindex')).toBe('0'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should not set tabindex on td when cell has no expand state', () => { |
| 68 | + const areaItem = new TestAreaItem(createMockComponent()); |
| 69 | + const tableData = [[{ text: 'Plain cell' }]]; |
| 70 | + |
| 71 | + areaItem.render($container, tableData); |
| 72 | + |
| 73 | + const $td = $container.find('td'); |
| 74 | + expect($td.attr('tabindex')).toBeUndefined(); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should not set aria-expanded on td when cell has no expand state', () => { |
| 78 | + const areaItem = new TestAreaItem(createMockComponent()); |
| 79 | + const tableData = [[{ text: 'Plain cell' }]]; |
| 80 | + |
| 81 | + areaItem.render($container, tableData); |
| 82 | + |
| 83 | + const $td = $container.find('td'); |
| 84 | + expect($td.attr('aria-expanded')).toBeUndefined(); |
| 85 | + }); |
| 86 | +}); |
0 commit comments