|
| 1 | +import test from 'tape'; |
| 2 | + |
| 3 | +import JSXAttributeMock from '../../../../__mocks__/JSXAttributeMock'; |
| 4 | +import getImplicitRoleForSelect from '../../../../src/util/implicitRoles/select'; |
| 5 | + |
| 6 | +test('isAbstractRole', (t) => { |
| 7 | + t.test('works for combobox', (st) => { |
| 8 | + st.equal( |
| 9 | + getImplicitRoleForSelect([]), |
| 10 | + 'combobox', |
| 11 | + 'defaults to combobox', |
| 12 | + ); |
| 13 | + |
| 14 | + st.equal( |
| 15 | + getImplicitRoleForSelect([JSXAttributeMock('multiple', null)]), |
| 16 | + 'combobox', |
| 17 | + 'is combobox when multiple attribute is set to not be present', |
| 18 | + ); |
| 19 | + |
| 20 | + st.equal( |
| 21 | + getImplicitRoleForSelect([JSXAttributeMock('multiple', undefined)]), |
| 22 | + 'combobox', |
| 23 | + 'is combobox when multiple attribute is set to not be present', |
| 24 | + ); |
| 25 | + |
| 26 | + st.equal( |
| 27 | + getImplicitRoleForSelect([JSXAttributeMock('multiple', false)]), |
| 28 | + 'combobox', |
| 29 | + 'is combobox when multiple attribute is set to boolean false', |
| 30 | + ); |
| 31 | + |
| 32 | + st.equal( |
| 33 | + getImplicitRoleForSelect([JSXAttributeMock('multiple', '')]), |
| 34 | + 'combobox', |
| 35 | + 'is listbox when multiple attribute is falsey (empty string)', |
| 36 | + ); |
| 37 | + |
| 38 | + st.equal( |
| 39 | + getImplicitRoleForSelect([JSXAttributeMock('size', '1')]), |
| 40 | + 'combobox', |
| 41 | + 'is combobox when size is not greater than 1', |
| 42 | + ); |
| 43 | + |
| 44 | + st.equal( |
| 45 | + getImplicitRoleForSelect([JSXAttributeMock('size', 1)]), |
| 46 | + 'combobox', |
| 47 | + 'is combobox when size is not greater than 1', |
| 48 | + ); |
| 49 | + |
| 50 | + st.equal( |
| 51 | + getImplicitRoleForSelect([JSXAttributeMock('size', 0)]), |
| 52 | + 'combobox', |
| 53 | + 'is combobox when size is not greater than 1', |
| 54 | + ); |
| 55 | + |
| 56 | + st.equal( |
| 57 | + getImplicitRoleForSelect([JSXAttributeMock('size', '0')]), |
| 58 | + 'combobox', |
| 59 | + 'is combobox when size is not greater than 1', |
| 60 | + ); |
| 61 | + |
| 62 | + st.equal( |
| 63 | + getImplicitRoleForSelect([JSXAttributeMock('size', '-1')]), |
| 64 | + 'combobox', |
| 65 | + 'is combobox when size is not greater than 1', |
| 66 | + ); |
| 67 | + |
| 68 | + st.equal( |
| 69 | + getImplicitRoleForSelect([JSXAttributeMock('size', '')]), |
| 70 | + 'combobox', |
| 71 | + 'is combobox when size is a valid number', |
| 72 | + ); |
| 73 | + |
| 74 | + st.equal( |
| 75 | + getImplicitRoleForSelect([JSXAttributeMock('size', 'true')]), |
| 76 | + 'combobox', |
| 77 | + 'is combobox when size is a valid number', |
| 78 | + ); |
| 79 | + |
| 80 | + st.equal( |
| 81 | + getImplicitRoleForSelect([JSXAttributeMock('size', true)]), |
| 82 | + 'combobox', |
| 83 | + 'is combobox when size is a valid number', |
| 84 | + ); |
| 85 | + |
| 86 | + st.equal( |
| 87 | + getImplicitRoleForSelect([JSXAttributeMock('size', NaN)]), |
| 88 | + 'combobox', |
| 89 | + 'is combobox when size is a valid number', |
| 90 | + ); |
| 91 | + |
| 92 | + st.equal( |
| 93 | + getImplicitRoleForSelect([JSXAttributeMock('size', '')]), |
| 94 | + 'combobox', |
| 95 | + 'is combobox when size is a valid number', |
| 96 | + ); |
| 97 | + |
| 98 | + st.equal( |
| 99 | + getImplicitRoleForSelect([JSXAttributeMock('size', undefined)]), |
| 100 | + 'combobox', |
| 101 | + 'is combobox when size is a valid number', |
| 102 | + ); |
| 103 | + |
| 104 | + st.equal( |
| 105 | + getImplicitRoleForSelect([JSXAttributeMock('size', false)]), |
| 106 | + 'combobox', |
| 107 | + 'is combobox when size is a valid number', |
| 108 | + ); |
| 109 | + |
| 110 | + st.end(); |
| 111 | + }); |
| 112 | + |
| 113 | + t.test('works for listbox based on multiple attribute', (st) => { |
| 114 | + st.equal( |
| 115 | + getImplicitRoleForSelect([JSXAttributeMock('multiple', true)]), |
| 116 | + 'listbox', |
| 117 | + 'is listbox when multiple is boolean true', |
| 118 | + ); |
| 119 | + |
| 120 | + st.equal( |
| 121 | + getImplicitRoleForSelect([JSXAttributeMock('multiple', 'multiple')]), |
| 122 | + 'listbox', |
| 123 | + 'is listbox when multiple is truthy (string)', |
| 124 | + ); |
| 125 | + |
| 126 | + st.equal( |
| 127 | + getImplicitRoleForSelect([JSXAttributeMock('multiple', 'true')]), |
| 128 | + 'listbox', |
| 129 | + 'is listbox when multiple is truthy (string) - React will warn about this', |
| 130 | + ); |
| 131 | + |
| 132 | + st.end(); |
| 133 | + }); |
| 134 | + |
| 135 | + t.test('works for listbox based on size attribute', (st) => { |
| 136 | + st.equal( |
| 137 | + getImplicitRoleForSelect([JSXAttributeMock('size', 2)]), |
| 138 | + 'listbox', |
| 139 | + 'is listbox when size is greater than 1', |
| 140 | + ); |
| 141 | + |
| 142 | + st.equal( |
| 143 | + getImplicitRoleForSelect([JSXAttributeMock('size', '3')]), |
| 144 | + 'listbox', |
| 145 | + 'is listbox when size is greater than 1', |
| 146 | + ); |
| 147 | + |
| 148 | + st.equal( |
| 149 | + getImplicitRoleForSelect([JSXAttributeMock('size', 40)]), |
| 150 | + 'listbox', |
| 151 | + 'is listbox when size is greater than 1', |
| 152 | + ); |
| 153 | + |
| 154 | + st.end(); |
| 155 | + }); |
| 156 | + |
| 157 | + t.end(); |
| 158 | +}); |
0 commit comments