Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 1 | function matchTableFactory () { |
| 2 | var table = document.createElement('div'); |
| 3 | table.className = 'matchtable'; |
| 4 | table.innerHTML = |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 5 | " <table>" + |
| 6 | " <thead>" + |
| 7 | " <tr>" + |
| 8 | " <th>Foundry</th>" + |
| 9 | " <th>Layer</th>" + |
| 10 | " <th>Der</th>" + |
| 11 | " <th>älteste</th>" + |
| 12 | " <th>lebende</th>" + |
| 13 | " <th>Baum</th>" + |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 14 | " <th>hier</th>" + |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 15 | " </tr>" + |
| 16 | " </thead>" + |
| 17 | " <tbody>" + |
| 18 | " <tr tabindex=\"0\">" + |
| 19 | " <th>corenlp</th>" + |
| 20 | " <th>p</th>" + |
| 21 | " <td>ART</td>" + |
| 22 | " <td>ADJA</td>" + |
| 23 | " <td>ADJA<br>ADJD</td>" + |
| 24 | " <td>NN</td>" + |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 25 | " <td>ADV</td>" + |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 26 | " </tr>" + |
| 27 | " <tr tabindex=\"0\">" + |
| 28 | " <th>opennlp</th>" + |
| 29 | " <th>p</th>" + |
| 30 | " <td>ART</td>" + |
| 31 | " <td>ADJA</td>" + |
| 32 | " <td></td>" + |
| 33 | " <td>NN</td>" + |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 34 | " <td>ADV</td>" + |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 35 | " </tr>" + |
| 36 | " </tbody>" + |
| 37 | " </table>" + |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 38 | " </div>"; |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 39 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 40 | var info = document.createElement('div'); |
| 41 | info.appendChild(table); |
| 42 | return table; |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 43 | }; |
| 44 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 45 | function matchTableComplexFactory () { |
| 46 | var table = document.createElement('div'); |
| 47 | table.className = 'matchtable'; |
| 48 | table.innerHTML = |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 49 | " <table>" + |
| 50 | " <thead>" + |
| 51 | " <tr>" + |
| 52 | " <th>Foundry</th>" + |
| 53 | " <th>Layer</th>" + |
| 54 | " <th>Der</th>" + |
| 55 | " <th>älteste</th>" + |
| 56 | " <th>lebende</th>" + |
| 57 | " <th>Baum</th>" + |
| 58 | " </tr>" + |
| 59 | " </thead>" + |
| 60 | " <tbody>" + |
| 61 | " <tr tabindex=\"0\">" + |
| 62 | " <th>corenlp</th>" + |
| 63 | " <th>p</th>" + |
| 64 | " <td>ART</td>" + |
| 65 | " <td>ADJA</td>" + |
| 66 | " <td>ADJA<br>ADJD</td>" + |
| 67 | " <td class=\"matchkeyvalues\">" + |
| 68 | " <div>case:nom</div>" + |
| 69 | " <div>gender:masc<br/>gender:fem</div>" + |
| 70 | " <div>number:sg</div>" + |
| 71 | " </td>" + |
| 72 | " </tr>" + |
| 73 | " <tr tabindex=\"0\">" + |
| 74 | " <th>opennlp</th>" + |
| 75 | " <th>p</th>" + |
| 76 | " <td class=\"matchkeyvalues\">" + |
| 77 | " <div>case:nom</div>" + |
| 78 | " <div>gender:masc</div>" + |
| 79 | " <div>number:sg</div>" + |
| 80 | " </td>" + |
| 81 | " <td>ADJA</td>" + |
| 82 | " <td></td>" + |
| 83 | " <td>NN</td>" + |
| 84 | " </tr>" + |
| 85 | " </tbody>" + |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 86 | " </table>"; |
| 87 | var info = document.createElement('div'); |
| 88 | info.appendChild(table); |
| 89 | return table; |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 90 | }; |
| 91 | |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 92 | |
| 93 | define(['match/querycreator'], function (qcClass) { |
| 94 | |
| 95 | describe('KorAP.QueryCreator', function () { |
| 96 | |
| 97 | it('should be initializable', function () { |
| 98 | expect( |
| 99 | function() { |
| 100 | qcClass.create() |
| 101 | } |
| 102 | ).toThrow(new Error("Missing parameters")); |
| 103 | |
| 104 | expect( |
| 105 | function() { |
| 106 | qcClass.create("Test") |
| 107 | } |
| 108 | ).toThrow(new Error("Requires element")); |
| 109 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 110 | expect(qcClass.create(matchTableFactory()).toString()).toEqual(""); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 111 | }); |
| 112 | |
| 113 | it('should listen to click events', function () { |
| 114 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 115 | var matchTable = matchTableFactory(); |
| 116 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 117 | |
| 118 | // Nothing to show |
| 119 | expect(qc.toString()).toEqual(""); |
| 120 | expect(qc.shown()).toBe(false); |
| 121 | qc.show(); |
| 122 | expect(qc.shown()).toBe(false); |
| 123 | expect(qc.element().className).toEqual("queryfragment"); |
| 124 | |
| 125 | // Click on cell 0:0 "Foundry" |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 126 | var cell = matchTable.querySelector("thead > tr > th:first-child"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 127 | expect(cell.innerText).toEqual("Foundry"); |
| 128 | cell.click(); |
| 129 | expect(cell.classList.contains("chosen")).toBe(false); |
| 130 | expect(qc.toString()).toEqual(""); |
| 131 | expect(qc.shown()).toBe(false); |
| 132 | |
| 133 | // Click on cell 0:2 "Der" |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 134 | cell = matchTable.querySelector("thead > tr > th:nth-child(3)") |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 135 | expect(cell.innerText).toEqual("Der"); |
| 136 | cell.click(); |
| 137 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 138 | expect(qc.toString()).toEqual("[orth=Der]"); |
| 139 | expect(qc.shown()).toBeTruthy(); |
| 140 | |
| 141 | // Click on cell 0:2 "Der" again - to hide |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 142 | cell = matchTable.querySelector("thead > tr > th:nth-child(3)") |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 143 | expect(cell.innerText).toEqual("Der"); |
| 144 | cell.click(); |
| 145 | expect(cell.classList.contains("chosen")).toBe(false); |
| 146 | expect(qc.toString()).toEqual(""); |
| 147 | expect(qc.shown()).toBe(false); |
| 148 | }); |
| 149 | |
| 150 | it('should create tokens in arbitrary order', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 151 | var matchTable = matchTableFactory(); |
| 152 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 153 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 154 | var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 155 | expect(cell.innerText).toEqual("ADJA"); |
| 156 | cell.click(); |
| 157 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 158 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 159 | cell = matchTable.querySelector("thead > tr > th:nth-child(4)"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 160 | expect(cell.innerText).toEqual("älteste"); |
| 161 | cell.click(); |
| 162 | expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]"); |
| 163 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 164 | cell = matchTable.querySelector("tbody > tr > td:nth-child(4)"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 165 | expect(cell.innerText).toEqual("ADJA"); |
| 166 | cell.click(); |
| 167 | expect(qc.toString()).toEqual("[corenlp/p=ADJA & opennlp/p=ADJA & orth=älteste]"); |
| 168 | }); |
| 169 | |
| 170 | it('should create token sequences in arbitrary order', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 171 | var matchTable = matchTableFactory(); |
| 172 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 173 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 174 | var cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 175 | expect(cell.innerText).toEqual("lebende"); |
| 176 | cell.click(); |
| 177 | expect(qc.toString()).toEqual("[orth=lebende]"); |
| 178 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 179 | cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(3)"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 180 | expect(cell.innerText).toEqual("ART"); |
| 181 | cell.click(); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 182 | expect(qc.toString()).toEqual("[opennlp/p=ART][][orth=lebende]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 183 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 184 | cell = matchTable.querySelector("tbody > tr > td:nth-child(4)"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 185 | expect(cell.innerText).toEqual("ADJA"); |
| 186 | cell.click(); |
| 187 | expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA][orth=lebende]"); |
| 188 | }); |
| 189 | |
| 190 | it('should remove chosen elements again', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 191 | var matchTable = matchTableFactory(); |
| 192 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 193 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 194 | var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 195 | expect(cell.innerText).toEqual("ADJA"); |
| 196 | cell.click(); |
| 197 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 198 | var cell1 = cell; |
| 199 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 200 | cell = matchTable.querySelector("thead > tr > th:nth-child(4)"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 201 | expect(cell.innerText).toEqual("älteste"); |
| 202 | cell.click(); |
| 203 | expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]"); |
| 204 | var cell2 = cell; |
| 205 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 206 | cell = matchTable.querySelector("tbody > tr > td:nth-child(3)"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 207 | expect(cell.innerText).toEqual("ART"); |
| 208 | cell.click(); |
| 209 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste]"); |
| 210 | var cell3 = cell; |
| 211 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 212 | cell = matchTable.querySelector("thead > tr > th:nth-child(6)"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 213 | expect(cell.innerText).toEqual("Baum"); |
| 214 | cell.click(); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 215 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 216 | var cell4 = cell; |
| 217 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 218 | cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 219 | expect(cell.innerText).toEqual("lebende"); |
| 220 | cell.click(); |
| 221 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][orth=lebende][orth=Baum]"); |
| 222 | var cell5 = cell; |
| 223 | |
| 224 | |
| 225 | // Remove annotations again |
| 226 | expect(cell5.classList.contains("chosen")).toBeTruthy(); |
| 227 | cell5.click() |
| 228 | expect(cell5.classList.contains("chosen")).toBe(false); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 229 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][][orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 230 | |
| 231 | expect(cell2.classList.contains("chosen")).toBeTruthy(); |
| 232 | cell2.click() |
| 233 | expect(cell2.classList.contains("chosen")).toBe(false); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 234 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 235 | |
| 236 | expect(cell1.classList.contains("chosen")).toBeTruthy(); |
| 237 | cell1.click() |
| 238 | expect(cell1.classList.contains("chosen")).toBe(false); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 239 | expect(qc.toString()).toEqual("[corenlp/p=ART][]{2}[orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 240 | |
| 241 | // Re-add first cell at the same position |
| 242 | expect(cell1.classList.contains("chosen")).toBe(false); |
| 243 | cell1.click() |
| 244 | expect(cell1.classList.contains("chosen")).toBeTruthy(); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 245 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][][orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 246 | |
| 247 | expect(cell3.classList.contains("chosen")).toBeTruthy(); |
| 248 | cell3.click() |
| 249 | expect(cell3.classList.contains("chosen")).toBe(false); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 250 | expect(qc.toString()).toEqual("[opennlp/p=ADJA][][orth=Baum]"); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 251 | |
| 252 | expect(cell4.classList.contains("chosen")).toBeTruthy(); |
| 253 | cell4.click() |
| 254 | expect(cell4.classList.contains("chosen")).toBe(false); |
| 255 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 256 | |
| 257 | // Remove last token |
| 258 | expect(qc.shown()).toBeTruthy(); |
| 259 | expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[opennlp/p=ADJA]</span>"); |
| 260 | expect(cell1.classList.contains("chosen")).toBeTruthy(); |
| 261 | cell1.click() |
| 262 | expect(cell1.classList.contains("chosen")).toBe(false); |
| 263 | expect(qc.toString()).toEqual(""); |
| 264 | expect(qc.shown()).toBe(false); |
| 265 | |
| 266 | // Re-add token |
| 267 | expect(cell4.classList.contains("chosen")).toBe(false); |
| 268 | cell4.click() |
| 269 | expect(cell4.classList.contains("chosen")).toBeTruthy(); |
| 270 | expect(qc.toString()).toEqual("[orth=Baum]"); |
| 271 | expect(qc.shown()).toBeTruthy(); |
| 272 | expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[orth=Baum]</span>"); |
| 273 | }); |
| 274 | |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 275 | it('should ignore empty terms', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 276 | var matchTable = matchTableFactory(); |
| 277 | var qc = qcClass.create(matchTable); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 278 | |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 279 | // Nothing to show |
| 280 | expect(qc.toString()).toEqual(""); |
| 281 | expect(qc.shown()).toBe(false); |
| 282 | qc.show(); |
| 283 | expect(qc.shown()).toBe(false); |
| 284 | expect(qc.element().className).toEqual("queryfragment"); |
| 285 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 286 | var cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 287 | expect(cell.innerText).toEqual("ADJA"); |
| 288 | expect(cell.classList.contains("chosen")).toBe(false); |
| 289 | cell.click(); |
| 290 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 291 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 292 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 293 | cell = matchTable.querySelector("tbody > tr:nth-child(2) > td:nth-child(5)"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 294 | expect(cell.innerText).toEqual(""); |
| 295 | expect(cell.classList.contains("chosen")).toBe(false); |
| 296 | cell.click(); |
| 297 | expect(cell.classList.contains("chosen")).toBe(false); |
| 298 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 299 | |
| 300 | }); |
| 301 | |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 302 | it('should create or-groups for alternative terms', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 303 | var matchTable = matchTableFactory(); |
| 304 | var qc = qcClass.create(matchTable); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 305 | |
| 306 | // Nothing to show |
| 307 | expect(qc.toString()).toEqual(""); |
| 308 | expect(qc.shown()).toBe(false); |
| 309 | qc.show(); |
| 310 | expect(qc.shown()).toBe(false); |
| 311 | expect(qc.element().className).toEqual("queryfragment"); |
| 312 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 313 | var cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 314 | expect(cell.innerText).toEqual("lebende"); |
| 315 | expect(cell.classList.contains("chosen")).toBe(false); |
| 316 | cell.click(); |
| 317 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 318 | expect(qc.toString()).toEqual("[orth=lebende]"); |
| 319 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 320 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(5)"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 321 | expect(cell.innerText).toEqual("ADJAADJD"); |
| 322 | expect(cell.classList.contains("chosen")).toBe(false); |
| 323 | cell.click(); |
| 324 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 325 | expect(qc.toString()).toEqual("[(corenlp/p=ADJA | corenlp/p=ADJD) & orth=lebende]"); |
| 326 | |
| 327 | // Remove or group again |
| 328 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 329 | cell.click(); |
| 330 | expect(cell.classList.contains("chosen")).toBe(false); |
| 331 | expect(qc.toString()).toEqual("[orth=lebende]"); |
| 332 | }); |
| 333 | |
| 334 | |
| 335 | it('should add whole rows', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 336 | var matchTable = matchTableFactory(); |
| 337 | var qc = qcClass.create(matchTable); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 338 | |
| 339 | // Nothing to show |
| 340 | expect(qc.toString()).toEqual(""); |
| 341 | expect(qc.shown()).toBe(false); |
| 342 | qc.show(); |
| 343 | expect(qc.shown()).toBe(false); |
| 344 | expect(qc.element().className).toEqual("queryfragment"); |
| 345 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 346 | var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 347 | |
| 348 | var cell = corenlpRow.querySelector("td:nth-child(4)"); |
| 349 | expect(cell.innerText).toEqual("ADJA"); |
| 350 | expect(cell.classList.contains("chosen")).toBe(false); |
| 351 | cell.click(); |
| 352 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 353 | |
| 354 | // Activate another cell in another row |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 355 | cell = matchTable.querySelector("tbody > tr:nth-child(2) td:nth-child(3)"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 356 | expect(cell.innerText).toEqual("ART"); |
| 357 | expect(cell.classList.contains("chosen")).toBe(false); |
| 358 | cell.click(); |
| 359 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 360 | |
| 361 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull(); |
| 362 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 363 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull(); |
| 364 | expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeNull(); |
| 365 | |
| 366 | expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA]"); |
| 367 | |
| 368 | // Mark all corenlp lists |
| 369 | cell = corenlpRow.querySelector("th:nth-child(1)"); |
| 370 | expect(cell.innerText).toEqual("corenlp"); |
| 371 | expect(cell.classList.contains("chosen")).toBe(false); |
| 372 | cell.click(); |
| 373 | expect(cell.classList.contains("chosen")).toBe(false); |
| 374 | |
| 375 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy(); |
| 376 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 377 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy(); |
| 378 | expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy(); |
| 379 | |
| 380 | // Replay the choice without any effect |
| 381 | cell = corenlpRow.querySelector("th:nth-child(1)"); |
| 382 | expect(cell.innerText).toEqual("corenlp"); |
| 383 | expect(cell.classList.contains("chosen")).toBe(false); |
| 384 | cell.click(); |
| 385 | expect(cell.classList.contains("chosen")).toBe(false); |
| 386 | |
| 387 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy(); |
| 388 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 389 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy(); |
| 390 | expect(corenlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy(); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 391 | expect(corenlpRow.querySelector("td:nth-child(7).chosen")).toBeTruthy(); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 392 | |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 393 | expect(qc.toString()).toEqual("[corenlp/p=ART & opennlp/p=ART][corenlp/p=ADJA][(corenlp/p=ADJA | corenlp/p=ADJD)][corenlp/p=NN][corenlp/p=ADV]"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 394 | |
| 395 | // Remove one of the cells again |
| 396 | cell = corenlpRow.querySelector("td:nth-child(5).chosen"); |
| 397 | expect(cell.innerText).toEqual("ADJAADJD"); |
| 398 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 399 | cell.click(); |
| 400 | expect(cell.classList.contains("chosen")).toBe(false); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 401 | expect(qc.toString()).toEqual("[corenlp/p=ART & opennlp/p=ART][corenlp/p=ADJA][][corenlp/p=NN][corenlp/p=ADV]"); |
Akron | c8461bf | 2017-06-29 15:05:24 +0200 | [diff] [blame] | 402 | |
| 403 | }); |
Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 404 | |
| 405 | it('should ignore empty terms in whole rows', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 406 | var matchTable = matchTableFactory(); |
| 407 | var qc = qcClass.create(matchTable); |
Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 408 | expect(qc.toString()).toEqual(""); |
| 409 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 410 | var opennlpRow = matchTable.querySelector("tbody > tr:nth-child(2)"); |
Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 411 | |
| 412 | expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeNull(); |
| 413 | expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeNull(); |
| 414 | expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull(); |
| 415 | expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeNull(); |
| 416 | |
| 417 | expect(qc.toString()).toEqual(""); |
| 418 | |
| 419 | // Mark all opennlp lists |
| 420 | cell = opennlpRow.querySelector("th:nth-child(1)"); |
| 421 | expect(cell.innerText).toEqual("opennlp"); |
| 422 | expect(cell.classList.contains("chosen")).toBe(false); |
| 423 | cell.click(); |
| 424 | expect(cell.classList.contains("chosen")).toBe(false); |
| 425 | |
| 426 | expect(opennlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy(); |
| 427 | expect(opennlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 428 | expect(opennlpRow.querySelector("td:nth-child(5).chosen")).toBeNull(); |
| 429 | expect(opennlpRow.querySelector("td:nth-child(6).chosen")).toBeTruthy(); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 430 | |
| 431 | expect(qc.toString()).toEqual("[opennlp/p=ART][opennlp/p=ADJA][][opennlp/p=NN][opennlp/p=ADV]"); |
Akron | 8084cb5 | 2017-06-29 17:11:14 +0200 | [diff] [blame] | 432 | }); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 433 | |
| 434 | it('should support multiple distances', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 435 | var matchTable = matchTableFactory(); |
| 436 | var qc = qcClass.create(matchTable); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 437 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 438 | var cell = matchTable.querySelector("thead > tr > th:nth-child(3)"); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 439 | expect(cell.innerText).toEqual("Der"); |
| 440 | cell.click(); |
| 441 | expect(qc.toString()).toEqual("[orth=Der]"); |
| 442 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 443 | cell = matchTable.querySelector("thead > tr > th:nth-child(7)"); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 444 | expect(cell.innerText).toEqual("hier"); |
| 445 | cell.click(); |
| 446 | expect(qc.toString()).toEqual("[orth=Der][]{3}[orth=hier]"); |
| 447 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 448 | cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | e9be11d | 2017-06-29 20:10:58 +0200 | [diff] [blame] | 449 | expect(cell.innerText).toEqual("lebende"); |
| 450 | cell.click(); |
| 451 | expect(qc.toString()).toEqual("[orth=Der][][orth=lebende][][orth=hier]"); |
| 452 | }); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 453 | |
| 454 | it('should create and-groups for key-value terms', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 455 | var matchTable = matchTableComplexFactory(); |
| 456 | var qc = qcClass.create(matchTable); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 457 | |
| 458 | // Nothing to show |
| 459 | expect(qc.toString()).toEqual(""); |
| 460 | expect(qc.shown()).toBe(false); |
| 461 | qc.show(); |
| 462 | expect(qc.shown()).toBe(false); |
| 463 | expect(qc.element().className).toEqual("queryfragment"); |
| 464 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 465 | var cell = matchTable.querySelector("thead > tr > th:nth-child(5)"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 466 | expect(cell.innerText).toEqual("lebende"); |
| 467 | expect(cell.classList.contains("chosen")).toBe(false); |
| 468 | cell.click(); |
| 469 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 470 | expect(qc.toString()).toEqual("[orth=lebende]"); |
| 471 | |
| 472 | // Check complex cell |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 473 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6)"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 474 | expect(cell.innerText).toMatch(/case:nom/); |
| 475 | expect(cell.classList.contains("chosen")).toBe(false); |
| 476 | cell.click(); |
| 477 | expect(cell.classList.contains("chosen")).toBe(false); |
| 478 | expect(qc.toString()).toEqual("[orth=lebende]"); |
| 479 | |
| 480 | // Check complex cell div |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 481 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(1)"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 482 | expect(cell.innerText).toEqual('case:nom'); |
| 483 | expect(cell.classList.contains("chosen")).toBe(false); |
| 484 | cell.click(); |
| 485 | expect(cell.classList.contains("chosen")).toBe(true); |
| 486 | expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom]"); |
| 487 | var cell = cell; |
| 488 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 489 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(3)"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 490 | expect(cell.innerText).toEqual('number:sg'); |
| 491 | expect(cell.classList.contains("chosen")).toBe(false); |
| 492 | cell.click(); |
| 493 | expect(cell.classList.contains("chosen")).toBe(true); |
| 494 | expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom & corenlp/p=number:sg]"); |
| 495 | var cell2 = cell; |
| 496 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 497 | cell = matchTable.querySelector("tbody > tr:nth-child(1) > td:nth-child(6) > div:nth-child(2)"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 498 | expect(cell.innerText).toEqual('gender:mascgender:fem'); |
| 499 | expect(cell.classList.contains("chosen")).toBe(false); |
| 500 | cell.click(); |
| 501 | expect(cell.classList.contains("chosen")).toBe(true); |
| 502 | expect(qc.toString()).toEqual("[orth=lebende][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]"); |
| 503 | var cell3 = cell; |
| 504 | |
| 505 | // Remove cell again |
| 506 | cell = cell2; |
| 507 | expect(cell.innerText).toEqual('number:sg'); |
| 508 | expect(cell.classList.contains("chosen")).toBe(true); |
| 509 | cell.click(); |
| 510 | expect(cell.classList.contains("chosen")).toBe(false); |
| 511 | expect(qc.toString()).toEqual("[orth=lebende][(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom]"); |
| 512 | |
| 513 | // Remove cell again |
| 514 | cell = cell3; |
| 515 | expect(cell.innerText).toEqual('gender:mascgender:fem'); |
| 516 | expect(cell.classList.contains("chosen")).toBe(true); |
| 517 | cell.click(); |
| 518 | expect(cell.classList.contains("chosen")).toBe(false); |
| 519 | expect(qc.toString()).toEqual("[orth=lebende][corenlp/p=case:nom]"); |
| 520 | }); |
| 521 | |
| 522 | |
| 523 | it('should create rows including key-value terms', function () { |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 524 | var matchTable = matchTableComplexFactory(); |
| 525 | var qc = qcClass.create(matchTable); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 526 | expect(qc.toString()).toEqual(""); |
| 527 | |
Akron | 70903c4 | 2018-02-05 12:31:10 +0100 | [diff] [blame] | 528 | var corenlpRow = matchTable.querySelector("tbody > tr:nth-child(1)"); |
Akron | 7cf33fd | 2017-07-03 17:33:39 +0200 | [diff] [blame] | 529 | |
| 530 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeNull(); |
| 531 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeNull(); |
| 532 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeNull(); |
| 533 | expect(corenlpRow.querySelector("td:nth-child(6) *.chosen")).toBeNull(); |
| 534 | |
| 535 | expect(qc.toString()).toEqual(""); |
| 536 | |
| 537 | // Mark all opennlp lists |
| 538 | cell = corenlpRow.querySelector("th:nth-child(1)"); |
| 539 | expect(cell.innerText).toEqual("corenlp"); |
| 540 | expect(cell.classList.contains("chosen")).toBe(false); |
| 541 | cell.click(); |
| 542 | expect(cell.classList.contains("chosen")).toBe(false); |
| 543 | |
| 544 | expect(corenlpRow.querySelector("td:nth-child(3).chosen")).toBeTruthy(); |
| 545 | expect(corenlpRow.querySelector("td:nth-child(4).chosen")).toBeTruthy(); |
| 546 | expect(corenlpRow.querySelector("td:nth-child(5).chosen")).toBeTruthy(); |
| 547 | expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(1).chosen")).toBeTruthy(); |
| 548 | expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(2).chosen")).toBeTruthy(); |
| 549 | expect(corenlpRow.querySelector("td:nth-child(6) div:nth-child(3).chosen")).toBeTruthy(); |
| 550 | |
| 551 | expect(qc.toString()).toEqual( |
| 552 | "[corenlp/p=ART]"+ |
| 553 | "[corenlp/p=ADJA]"+ |
| 554 | "[(corenlp/p=ADJA | corenlp/p=ADJD)]"+ |
| 555 | "[(corenlp/p=gender:fem | corenlp/p=gender:masc) & corenlp/p=case:nom & corenlp/p=number:sg]" |
| 556 | ); |
| 557 | }); |
Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame] | 558 | }); |
| 559 | }); |