|
| 1 | +describe('has-widget-or-window-role', function () { |
| 2 | + 'use strict'; |
| 3 | + |
| 4 | + let node; |
| 5 | + const fixture = document.getElementById('fixture'); |
| 6 | + const checkContext = axe.testUtils.MockCheckContext(); |
| 7 | + const evaluate = currentNode => |
| 8 | + axe.testUtils |
| 9 | + .getCheckEvaluate('has-widget-or-window-role') |
| 10 | + .call(checkContext, currentNode); |
| 11 | + const roles = { |
| 12 | + widget: { |
| 13 | + button: true, |
| 14 | + checkbox: true, |
| 15 | + gridcell: true, |
| 16 | + link: true, |
| 17 | + menuitem: true, |
| 18 | + menuitemcheckbox: true, |
| 19 | + menuitemradio: true, |
| 20 | + option: true, |
| 21 | + progressbar: true, |
| 22 | + radio: true, |
| 23 | + scrollbar: true, |
| 24 | + searchbox: true, |
| 25 | + slider: true, |
| 26 | + spinbutton: true, |
| 27 | + switch: true, |
| 28 | + tab: true, |
| 29 | + tabpanel: true, |
| 30 | + textbox: true, |
| 31 | + treeitem: true |
| 32 | + }, |
| 33 | + composite: { |
| 34 | + combobox: true, |
| 35 | + grid: true, |
| 36 | + listbox: true, |
| 37 | + menu: true, |
| 38 | + menubar: true, |
| 39 | + radiogroup: true, |
| 40 | + tablist: true, |
| 41 | + tree: true, |
| 42 | + treegrid: true, |
| 43 | + |
| 44 | + application: false, |
| 45 | + article: false, |
| 46 | + cell: false, |
| 47 | + columnheader: false, |
| 48 | + definition: false, |
| 49 | + directory: false, |
| 50 | + document: false, |
| 51 | + feed: false, |
| 52 | + figure: false, |
| 53 | + group: false, |
| 54 | + heading: false, |
| 55 | + img: false, |
| 56 | + list: false, |
| 57 | + listitem: false, |
| 58 | + math: false, |
| 59 | + none: false, |
| 60 | + note: false, |
| 61 | + presentation: false, |
| 62 | + row: false, |
| 63 | + rowgroup: false, |
| 64 | + rowheader: false, |
| 65 | + table: false, |
| 66 | + term: false, |
| 67 | + toolbar: false |
| 68 | + }, |
| 69 | + window: { |
| 70 | + alertdialog: true, |
| 71 | + dialog: true |
| 72 | + }, |
| 73 | + landmark: { |
| 74 | + banner: false, |
| 75 | + complimentary: false, |
| 76 | + contentinfo: false, |
| 77 | + form: false, |
| 78 | + name: false, |
| 79 | + navigation: false, |
| 80 | + region: false, |
| 81 | + search: false |
| 82 | + } |
| 83 | + }; |
| 84 | + |
| 85 | + afterEach(function () { |
| 86 | + node.innerHTML = ''; |
| 87 | + checkContext._data = null; |
| 88 | + }); |
| 89 | + |
| 90 | + it('should return false for elements with no role', function () { |
| 91 | + node = document.createElement('div'); |
| 92 | + fixture.appendChild(node); |
| 93 | + |
| 94 | + assert.isFalse(evaluate(node)); |
| 95 | + }); |
| 96 | + |
| 97 | + it('should return false for elements with nonsensical roles', function () { |
| 98 | + node = document.createElement('div'); |
| 99 | + node.setAttribute('role', 'buttonbuttonbutton'); |
| 100 | + fixture.appendChild(node); |
| 101 | + |
| 102 | + assert.isFalse(evaluate(node)); |
| 103 | + }); |
| 104 | + |
| 105 | + Object.keys(roles).forEach(category => { |
| 106 | + describe(category, function () { |
| 107 | + Object.keys(roles[category]).forEach(role => { |
| 108 | + it(`should return ${roles[category][role]} for role="${role}"`, function () { |
| 109 | + node = document.createElement('div'); |
| 110 | + node.setAttribute('role', role); |
| 111 | + fixture.appendChild(node); |
| 112 | + |
| 113 | + assert.equal(evaluate(node), roles[category][role]); |
| 114 | + }); |
| 115 | + }); |
| 116 | + }); |
| 117 | + }); |
| 118 | +}); |
0 commit comments