Akron | b46d8e3 | 2017-06-29 14:26:14 +0200 | [diff] [blame^] | 1 | function matchInfoFactory () { |
| 2 | var info = document.createElement('div'); |
| 3 | info.className = 'matchinfo'; |
| 4 | info.innerHTML = |
| 5 | " <div class=\"matchtable\">" + |
| 6 | " <table>" + |
| 7 | " <thead>" + |
| 8 | " <tr>" + |
| 9 | " <th>Foundry</th>" + |
| 10 | " <th>Layer</th>" + |
| 11 | " <th>Der</th>" + |
| 12 | " <th>älteste</th>" + |
| 13 | " <th>lebende</th>" + |
| 14 | " <th>Baum</th>" + |
| 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>" + |
| 25 | " </tr>" + |
| 26 | " <tr tabindex=\"0\">" + |
| 27 | " <th>opennlp</th>" + |
| 28 | " <th>p</th>" + |
| 29 | " <td>ART</td>" + |
| 30 | " <td>ADJA</td>" + |
| 31 | " <td></td>" + |
| 32 | " <td>NN</td>" + |
| 33 | " </tr>" + |
| 34 | " </tbody>" + |
| 35 | " </table>" + |
| 36 | " </div>" + |
| 37 | "</div>"; |
| 38 | |
| 39 | return info; |
| 40 | }; |
| 41 | |
| 42 | |
| 43 | define(['match/querycreator'], function (qcClass) { |
| 44 | |
| 45 | describe('KorAP.QueryCreator', function () { |
| 46 | |
| 47 | it('should be initializable', function () { |
| 48 | expect( |
| 49 | function() { |
| 50 | qcClass.create() |
| 51 | } |
| 52 | ).toThrow(new Error("Missing parameters")); |
| 53 | |
| 54 | expect( |
| 55 | function() { |
| 56 | qcClass.create("Test") |
| 57 | } |
| 58 | ).toThrow(new Error("Requires element")); |
| 59 | |
| 60 | expect( |
| 61 | function() { |
| 62 | var minfo = document.createElement('div'); |
| 63 | qcClass.create(minfo); |
| 64 | } |
| 65 | ).toThrow(new Error("Element contains no match table")); |
| 66 | |
| 67 | expect(qcClass.create(matchInfoFactory()).toString()).toEqual(""); |
| 68 | }); |
| 69 | |
| 70 | it('should listen to click events', function () { |
| 71 | |
| 72 | var matchInfo = matchInfoFactory(); |
| 73 | var qc = qcClass.create(matchInfo); |
| 74 | |
| 75 | // Nothing to show |
| 76 | expect(qc.toString()).toEqual(""); |
| 77 | expect(qc.shown()).toBe(false); |
| 78 | qc.show(); |
| 79 | expect(qc.shown()).toBe(false); |
| 80 | expect(qc.element().className).toEqual("queryfragment"); |
| 81 | |
| 82 | // Click on cell 0:0 "Foundry" |
| 83 | var cell = matchInfo.querySelector("thead > tr > th:first-child"); |
| 84 | expect(cell.innerText).toEqual("Foundry"); |
| 85 | cell.click(); |
| 86 | expect(cell.classList.contains("chosen")).toBe(false); |
| 87 | expect(qc.toString()).toEqual(""); |
| 88 | expect(qc.shown()).toBe(false); |
| 89 | |
| 90 | // Click on cell 0:2 "Der" |
| 91 | cell = matchInfo.querySelector("thead > tr > th:nth-child(3)") |
| 92 | expect(cell.innerText).toEqual("Der"); |
| 93 | cell.click(); |
| 94 | expect(cell.classList.contains("chosen")).toBeTruthy(); |
| 95 | expect(qc.toString()).toEqual("[orth=Der]"); |
| 96 | expect(qc.shown()).toBeTruthy(); |
| 97 | |
| 98 | // Click on cell 0:2 "Der" again - to hide |
| 99 | cell = matchInfo.querySelector("thead > tr > th:nth-child(3)") |
| 100 | expect(cell.innerText).toEqual("Der"); |
| 101 | cell.click(); |
| 102 | expect(cell.classList.contains("chosen")).toBe(false); |
| 103 | expect(qc.toString()).toEqual(""); |
| 104 | expect(qc.shown()).toBe(false); |
| 105 | }); |
| 106 | |
| 107 | it('should create tokens in arbitrary order', function () { |
| 108 | var matchInfo = matchInfoFactory(); |
| 109 | var qc = qcClass.create(matchInfo); |
| 110 | |
| 111 | var cell = matchInfo.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)"); |
| 112 | expect(cell.innerText).toEqual("ADJA"); |
| 113 | cell.click(); |
| 114 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 115 | |
| 116 | cell = matchInfo.querySelector("thead > tr > th:nth-child(4)"); |
| 117 | expect(cell.innerText).toEqual("älteste"); |
| 118 | cell.click(); |
| 119 | expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]"); |
| 120 | |
| 121 | cell = matchInfo.querySelector("tbody > tr > td:nth-child(4)"); |
| 122 | expect(cell.innerText).toEqual("ADJA"); |
| 123 | cell.click(); |
| 124 | expect(qc.toString()).toEqual("[corenlp/p=ADJA & opennlp/p=ADJA & orth=älteste]"); |
| 125 | }); |
| 126 | |
| 127 | it('should create token sequences in arbitrary order', function () { |
| 128 | var matchInfo = matchInfoFactory(); |
| 129 | var qc = qcClass.create(matchInfo); |
| 130 | |
| 131 | var cell = matchInfo.querySelector("thead > tr > th:nth-child(5)"); |
| 132 | expect(cell.innerText).toEqual("lebende"); |
| 133 | cell.click(); |
| 134 | expect(qc.toString()).toEqual("[orth=lebende]"); |
| 135 | |
| 136 | cell = matchInfo.querySelector("tbody > tr:nth-child(2) > td:nth-child(3)"); |
| 137 | expect(cell.innerText).toEqual("ART"); |
| 138 | cell.click(); |
| 139 | expect(qc.toString()).toEqual("[opennlp/p=ART][orth=lebende]"); |
| 140 | |
| 141 | cell = matchInfo.querySelector("tbody > tr > td:nth-child(4)"); |
| 142 | expect(cell.innerText).toEqual("ADJA"); |
| 143 | cell.click(); |
| 144 | expect(qc.toString()).toEqual("[opennlp/p=ART][corenlp/p=ADJA][orth=lebende]"); |
| 145 | }); |
| 146 | |
| 147 | it('should remove chosen elements again', function () { |
| 148 | var matchInfo = matchInfoFactory(); |
| 149 | var qc = qcClass.create(matchInfo); |
| 150 | |
| 151 | var cell = matchInfo.querySelector("tbody > tr:nth-child(2) > td:nth-child(4)"); |
| 152 | expect(cell.innerText).toEqual("ADJA"); |
| 153 | cell.click(); |
| 154 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 155 | var cell1 = cell; |
| 156 | |
| 157 | cell = matchInfo.querySelector("thead > tr > th:nth-child(4)"); |
| 158 | expect(cell.innerText).toEqual("älteste"); |
| 159 | cell.click(); |
| 160 | expect(qc.toString()).toEqual("[opennlp/p=ADJA & orth=älteste]"); |
| 161 | var cell2 = cell; |
| 162 | |
| 163 | cell = matchInfo.querySelector("tbody > tr > td:nth-child(3)"); |
| 164 | expect(cell.innerText).toEqual("ART"); |
| 165 | cell.click(); |
| 166 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste]"); |
| 167 | var cell3 = cell; |
| 168 | |
| 169 | cell = matchInfo.querySelector("thead > tr > th:nth-child(6)"); |
| 170 | expect(cell.innerText).toEqual("Baum"); |
| 171 | cell.click(); |
| 172 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][orth=Baum]"); |
| 173 | var cell4 = cell; |
| 174 | |
| 175 | cell = matchInfo.querySelector("thead > tr > th:nth-child(5)"); |
| 176 | expect(cell.innerText).toEqual("lebende"); |
| 177 | cell.click(); |
| 178 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][orth=lebende][orth=Baum]"); |
| 179 | var cell5 = cell; |
| 180 | |
| 181 | |
| 182 | // Remove annotations again |
| 183 | expect(cell5.classList.contains("chosen")).toBeTruthy(); |
| 184 | cell5.click() |
| 185 | expect(cell5.classList.contains("chosen")).toBe(false); |
| 186 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA & orth=älteste][orth=Baum]"); |
| 187 | |
| 188 | expect(cell2.classList.contains("chosen")).toBeTruthy(); |
| 189 | cell2.click() |
| 190 | expect(cell2.classList.contains("chosen")).toBe(false); |
| 191 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][orth=Baum]"); |
| 192 | |
| 193 | expect(cell1.classList.contains("chosen")).toBeTruthy(); |
| 194 | cell1.click() |
| 195 | expect(cell1.classList.contains("chosen")).toBe(false); |
| 196 | expect(qc.toString()).toEqual("[corenlp/p=ART][orth=Baum]"); |
| 197 | |
| 198 | // Re-add first cell at the same position |
| 199 | expect(cell1.classList.contains("chosen")).toBe(false); |
| 200 | cell1.click() |
| 201 | expect(cell1.classList.contains("chosen")).toBeTruthy(); |
| 202 | expect(qc.toString()).toEqual("[corenlp/p=ART][opennlp/p=ADJA][orth=Baum]"); |
| 203 | |
| 204 | expect(cell3.classList.contains("chosen")).toBeTruthy(); |
| 205 | cell3.click() |
| 206 | expect(cell3.classList.contains("chosen")).toBe(false); |
| 207 | expect(qc.toString()).toEqual("[opennlp/p=ADJA][orth=Baum]"); |
| 208 | |
| 209 | expect(cell4.classList.contains("chosen")).toBeTruthy(); |
| 210 | cell4.click() |
| 211 | expect(cell4.classList.contains("chosen")).toBe(false); |
| 212 | expect(qc.toString()).toEqual("[opennlp/p=ADJA]"); |
| 213 | |
| 214 | // Remove last token |
| 215 | expect(qc.shown()).toBeTruthy(); |
| 216 | expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[opennlp/p=ADJA]</span>"); |
| 217 | expect(cell1.classList.contains("chosen")).toBeTruthy(); |
| 218 | cell1.click() |
| 219 | expect(cell1.classList.contains("chosen")).toBe(false); |
| 220 | expect(qc.toString()).toEqual(""); |
| 221 | expect(qc.shown()).toBe(false); |
| 222 | |
| 223 | // Re-add token |
| 224 | expect(cell4.classList.contains("chosen")).toBe(false); |
| 225 | cell4.click() |
| 226 | expect(cell4.classList.contains("chosen")).toBeTruthy(); |
| 227 | expect(qc.toString()).toEqual("[orth=Baum]"); |
| 228 | expect(qc.shown()).toBeTruthy(); |
| 229 | expect(qc.element().innerHTML).toEqual("<span>New Query:</span><span>[orth=Baum]</span>"); |
| 230 | }); |
| 231 | |
| 232 | it('should ignore empty terms'); |
| 233 | it('should create groups for multiple terms'); |
| 234 | it('should add whole rows'); |
| 235 | |
| 236 | }); |
| 237 | }); |