|
| 1 | +import { virtual } from "../../src"; |
| 2 | + |
| 3 | +describe("Placeholder Attribute Property", () => { |
| 4 | + afterEach(() => { |
| 5 | + document.body.innerHTML = ""; |
| 6 | + }); |
| 7 | + |
| 8 | + it("should announce a non-empty value on a text input", async () => { |
| 9 | + document.body.innerHTML = ` |
| 10 | + <div id="label">Label</div> |
| 11 | + <input type="text" aria-labelledby="label" id="search1" value="a11y"/> |
| 12 | + `; |
| 13 | + |
| 14 | + await virtual.start({ container: document.body }); |
| 15 | + await virtual.next(); |
| 16 | + await virtual.next(); |
| 17 | + |
| 18 | + expect(await virtual.lastSpokenPhrase()).toBe("textbox, Label, a11y"); |
| 19 | + |
| 20 | + await virtual.stop(); |
| 21 | + }); |
| 22 | + |
| 23 | + it("should not announce an empty value on a text input", async () => { |
| 24 | + document.body.innerHTML = ` |
| 25 | + <div id="label">Label</div> |
| 26 | + <input type="text" aria-labelledby="label" id="search1" value=""/> |
| 27 | + `; |
| 28 | + |
| 29 | + await virtual.start({ container: document.body }); |
| 30 | + await virtual.next(); |
| 31 | + await virtual.next(); |
| 32 | + |
| 33 | + expect(await virtual.lastSpokenPhrase()).toBe("textbox, Label"); |
| 34 | + |
| 35 | + await virtual.stop(); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should not announce a missing value on a text input", async () => { |
| 39 | + document.body.innerHTML = ` |
| 40 | + <div id="label">Label</div> |
| 41 | + <input type="text" aria-labelledby="label" id="search1"/> |
| 42 | + `; |
| 43 | + |
| 44 | + await virtual.start({ container: document.body }); |
| 45 | + await virtual.next(); |
| 46 | + await virtual.next(); |
| 47 | + |
| 48 | + expect(await virtual.lastSpokenPhrase()).toBe("textbox, Label"); |
| 49 | + |
| 50 | + await virtual.stop(); |
| 51 | + }); |
| 52 | + |
| 53 | + it("should not announce a value on a checkbox input", async () => { |
| 54 | + document.body.innerHTML = ` |
| 55 | + <div id="label">Label</div> |
| 56 | + <input type="checkbox" aria-labelledby="label" id="check1" value="forbidden"/> |
| 57 | + `; |
| 58 | + |
| 59 | + await virtual.start({ container: document.body }); |
| 60 | + await virtual.next(); |
| 61 | + await virtual.next(); |
| 62 | + |
| 63 | + expect(await virtual.lastSpokenPhrase()).toBe("checkbox, Label"); |
| 64 | + |
| 65 | + await virtual.stop(); |
| 66 | + }); |
| 67 | + |
| 68 | + it("should not announce a value on a radio input", async () => { |
| 69 | + document.body.innerHTML = ` |
| 70 | + <div id="label">Label</div> |
| 71 | + <input type="radio" aria-labelledby="label" id="radio1" value="forbidden"/> |
| 72 | + `; |
| 73 | + |
| 74 | + await virtual.start({ container: document.body }); |
| 75 | + await virtual.next(); |
| 76 | + await virtual.next(); |
| 77 | + |
| 78 | + expect(await virtual.lastSpokenPhrase()).toBe("radio, Label"); |
| 79 | + |
| 80 | + await virtual.stop(); |
| 81 | + }); |
| 82 | + |
| 83 | + it("should not announce a value on a radio input", async () => { |
| 84 | + document.body.innerHTML = ` |
| 85 | + <div id="label">Label</div> |
| 86 | + <input type="radio" aria-labelledby="label" id="radio1" value="forbidden"/> |
| 87 | + `; |
| 88 | + |
| 89 | + await virtual.start({ container: document.body }); |
| 90 | + await virtual.next(); |
| 91 | + await virtual.next(); |
| 92 | + |
| 93 | + expect(await virtual.lastSpokenPhrase()).toBe("radio, Label"); |
| 94 | + |
| 95 | + await virtual.stop(); |
| 96 | + }); |
| 97 | + |
| 98 | + it("should announce the selected value in a select with options", async () => { |
| 99 | + document.body.innerHTML = ` |
| 100 | + <select> |
| 101 | + <option value="first">First Value</option> |
| 102 | + <option value="second" selected>Second Value</option> |
| 103 | + <option value="third">Third Value</option> |
| 104 | + </select> |
| 105 | + `; |
| 106 | + |
| 107 | + await virtual.start({ container: document.body }); |
| 108 | + await virtual.next(); |
| 109 | + |
| 110 | + expect(await virtual.lastSpokenPhrase()).toBe( |
| 111 | + "combobox, second, not expanded, has popup listbox" |
| 112 | + ); |
| 113 | + |
| 114 | + await virtual.stop(); |
| 115 | + }); |
| 116 | + |
| 117 | + it("should announce the multiple selected values in a multi-select with options", async () => { |
| 118 | + document.body.innerHTML = ` |
| 119 | + <select multiple> |
| 120 | + <option value="first">First Value</option> |
| 121 | + <option value="second" selected>Second Value</option> |
| 122 | + <option value="third" selected>Third Value</option> |
| 123 | + </select> |
| 124 | + `; |
| 125 | + |
| 126 | + await virtual.start({ container: document.body }); |
| 127 | + await virtual.next(); |
| 128 | + |
| 129 | + expect(await virtual.lastSpokenPhrase()).toBe( |
| 130 | + "listbox, second; third, orientated vertically" |
| 131 | + ); |
| 132 | + |
| 133 | + await virtual.stop(); |
| 134 | + }); |
| 135 | + |
| 136 | + it("should not announce empty selected values in a select with options", async () => { |
| 137 | + document.body.innerHTML = ` |
| 138 | + <select> |
| 139 | + <option value="" disabled selected>- Select some value - </option> |
| 140 | + <option value="first">First Value</option> |
| 141 | + <option value="second">Second Value</option> |
| 142 | + <option value="third">Third Value</option> |
| 143 | + </select> |
| 144 | + `; |
| 145 | + |
| 146 | + await virtual.start({ container: document.body }); |
| 147 | + await virtual.next(); |
| 148 | + |
| 149 | + expect(await virtual.lastSpokenPhrase()).toBe( |
| 150 | + "combobox, not expanded, has popup listbox" |
| 151 | + ); |
| 152 | + |
| 153 | + await virtual.stop(); |
| 154 | + }); |
| 155 | +}); |
0 commit comments