Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1 | // Regarding async: |
| 2 | // http://stackoverflow.com/questions/16423156/getting-requirejs-to-work-with-jasmine |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 3 | define(['match', |
| 4 | 'view/match/tokentable', |
| 5 | 'view/match/relations', |
| 6 | 'panel/match', |
| 7 | 'match/meta', |
| 8 | 'match/infolayer', |
| 9 | 'match/treeitem', |
| 10 | 'match/treearc', |
Akron | 3bdac53 | 2019-03-04 13:24:43 +0100 | [diff] [blame] | 11 | 'match/treehierarchy', |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 12 | 'buttongroup/menu', |
Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 13 | 'match/attachement', |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 14 | 'hint/foundries/cnx', |
| 15 | 'hint/foundries/mate'], function ( |
| 16 | matchClass, |
| 17 | tableClass, |
| 18 | relClass, |
| 19 | panelClass, |
| 20 | metaClass, |
| 21 | infoClass, |
| 22 | matchTreeItemClass, |
| 23 | matchRelClass, |
Akron | 3bdac53 | 2019-03-04 13:24:43 +0100 | [diff] [blame] | 24 | matchHierClass, |
Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 25 | matchTreeMenuClass, |
| 26 | attachementClass) { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 27 | |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 28 | var available = [ |
| 29 | 'base/s=spans', |
| 30 | 'corenlp/c=spans', |
| 31 | 'corenlp/ne=tokens', |
| 32 | 'corenlp/p=tokens', |
| 33 | 'corenlp/s=spans', |
| 34 | 'glemm/l=tokens', |
| 35 | 'mate/l=tokens', |
| 36 | 'mate/m=tokens', |
| 37 | 'mate/p=tokens', |
| 38 | 'opennlp/p=tokens', |
| 39 | 'opennlp/s=spans', |
| 40 | 'tt/l=tokens', |
| 41 | 'tt/p=tokens', |
| 42 | 'tt/s=spans' |
| 43 | ]; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 44 | |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 45 | var match = { |
| 46 | 'corpusID' : 'WPD', |
| 47 | 'docID' : 'UUU', |
| 48 | 'textID' : '01912', |
| 49 | 'matchID' : 'p121-122', |
| 50 | 'textSigle' : 'WPD/UUU/01912', |
| 51 | 'available' : available |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 52 | }; |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 53 | |
| 54 | |
| 55 | var fields = [ |
| 56 | { |
| 57 | "@type": "koral:field", |
| 58 | "key": "author", |
| 59 | "type": "type:text", |
| 60 | "value": "Sprachpfleger, u.a." |
| 61 | }, |
| 62 | { |
| 63 | "@type": "koral:field", |
| 64 | "key": "textClass", |
Akron | d45a170 | 2018-11-19 18:15:17 +0100 | [diff] [blame] | 65 | "type": "type:keywords", // May not be necessary |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 66 | "value": ["kultur", "film"] |
| 67 | }, |
| 68 | { |
| 69 | "@type":"koral:field", |
| 70 | "key":"foundries", |
| 71 | "type":"type:string", |
| 72 | "value":[ |
| 73 | "corenlp", |
| 74 | "corenlp\/constituency", |
| 75 | "corenlp\/morpho", |
| 76 | "corenlp\/sentences", |
| 77 | "dereko", |
| 78 | "dereko\/structure", |
| 79 | "dereko\/structure\/base-sentences-paragraphs-pagebreaks", |
| 80 | "opennlp", |
| 81 | "opennlp\/morpho", |
| 82 | "opennlp\/sentences" |
| 83 | ] |
Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 84 | }, |
| 85 | { |
| 86 | "@type": "koral:field", |
| 87 | "key": "xlink", |
| 88 | "type": "type:attachement", |
| 89 | "value": "data:application/x.korap-link;title=Cool,https://de.wikipedia.org/wiki/Beispiel" |
| 90 | }, |
Akron | d3bb85b | 2019-02-08 10:15:13 +0100 | [diff] [blame] | 91 | { |
| 92 | "@type": "koral:field", |
| 93 | "key": "z-reference", |
| 94 | "type": "type:attachement", |
| 95 | "value": "data:,This is a reference" |
| 96 | } |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 97 | ]; |
| 98 | |
| 99 | |
Akron | 5dc3117 | 2019-05-15 18:43:48 +0200 | [diff] [blame] | 100 | var snippet = "<span class=\"context-left\"><\/span>"+ |
| 101 | "<span class=\"match\">" + |
| 102 | "<span title=\"cnx/l:meist\">" + |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 103 | " <span title=\"cnx/p:ADV\">" + |
| 104 | " <span title=\"cnx/syn:@PREMOD\">" + |
| 105 | " <span title=\"mate/l:meist\">" + |
| 106 | " <span title=\"mate/l:meist\">" + |
| 107 | " <span title=\"mate/p:ADV\">" + |
| 108 | " <span title=\"opennlp/p:ADV\">meist</span>" + |
| 109 | " </span>" + |
| 110 | " </span>" + |
| 111 | " </span>" + |
| 112 | " </span>" + |
| 113 | " </span>" + |
| 114 | "</span>" + |
Akron | ad1e46a | 2018-09-19 15:55:40 +0200 | [diff] [blame] | 115 | "<mark>" + |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 116 | "<span title=\"cnx/l:deutlich\">" + |
| 117 | " <span title=\"cnx/p:A\">" + |
| 118 | " <span title=\"cnx/syn:@PREMOD\">" + |
| 119 | " <span title=\"mate/l:deutlich\">" + |
| 120 | " <span title=\"mate/m:degree:pos\">" + |
| 121 | " <span title=\"mate/p:ADJD\">" + |
| 122 | " <span title=\"opennlp/p:ADJD\">deutlich</span>" + |
| 123 | " </span>" + |
| 124 | " </span>" + |
| 125 | " </span>" + |
| 126 | " </span>" + |
| 127 | " </span>" + |
| 128 | "</span>" + |
Akron | ad1e46a | 2018-09-19 15:55:40 +0200 | [diff] [blame] | 129 | "</mark>" + |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 130 | "<span title=\"cnx/l:fähig\">" + |
| 131 | " <span title=\"cnx/l:leistung\">" + |
| 132 | " <span title=\"cnx/p:A\">" + |
| 133 | " <span title=\"cnx/p:ADJA\">" + |
| 134 | " <span title=\"cnx/syn:@NH\">" + |
| 135 | " <span title=\"mate/l:leistungsfähig\">" + |
| 136 | " <span title=\"mate/m:degree:comp\">" + |
| 137 | " <span title=\"mate/p:ADJD\">" + |
| 138 | " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" + |
| 139 | " </span>" + |
| 140 | " </span>" + |
| 141 | " </span>" + |
| 142 | " </span>" + |
| 143 | " </span>" + |
| 144 | " </span>" + |
| 145 | " </span>" + |
Akron | 5dc3117 | 2019-05-15 18:43:48 +0200 | [diff] [blame] | 146 | "</span>" + |
| 147 | " und robust sind auch die anderen Traktoren, die hier der Übersicht wegen keine Erwähnung finden können." + |
| 148 | "<span class=\"cutted\"><\/span>" + |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 149 | "</span>"; |
| 150 | |
| 151 | var treeSnippet = |
| 152 | "<span class=\"context-left\"></span>" + |
| 153 | "<span class=\"match\">" + |
| 154 | " <span title=\"xip/c:MC\">" + |
| 155 | " <span title=\"xip/c:TOP\">" + |
| 156 | " <span title=\"xip/c:PP\">" + |
| 157 | " <span title=\"xip/c:PREP\">Mit</span>" + |
| 158 | " <span title=\"xip/c:NP\">" + |
| 159 | " <span title=\"xip/c:DET\">dieser</span>" + |
| 160 | " <span title=\"xip/c:NPA\">" + |
| 161 | " <span title=\"xip/c:NOUN\">Methode</span>" + |
| 162 | " </span>" + |
| 163 | " </span>" + |
| 164 | " </span>" + |
| 165 | " <span title=\"xip/c:VERB\">ist</span>" + |
| 166 | " <mark>" + |
| 167 | " <span title=\"xip/c:NP\">" + |
| 168 | " <span title=\"xip/c:PRON\">es</span>" + |
| 169 | " </span>" + |
| 170 | " <span title=\"xip/c:AP\">" + |
| 171 | " <span title=\"xip/c:ADV\">nun</span>" + |
| 172 | " <span title=\"xip/c:ADJ\">möglich</span>" + |
| 173 | " </span>" + |
| 174 | " </mark>" + |
| 175 | " <span title=\"xip/c:ADV\">z. B.</span>" + |
| 176 | " <span title=\"xip/c:NPA\">" + |
| 177 | " <span title=\"xip/c:NP\">" + |
| 178 | " <span title=\"xip/c:NOUN\">Voice</span>" + |
| 179 | " </span>" + |
| 180 | " </span>" + "(" + |
| 181 | " <span title=\"xip/c:INS\">" + |
| 182 | " <span title=\"xip/c:NPA\">" + |
| 183 | " <span title=\"xip/c:NP\">" + |
| 184 | " <span title=\"xip/c:NOUN\">Sprache</span>" + |
| 185 | " </span>" + |
| 186 | " </span>" + |
| 187 | " </span>" + ")" + |
| 188 | " <span title=\"xip/c:VERB\">bevorzugt</span>" + |
| 189 | " <span title=\"xip/c:PP\">" + |
| 190 | " <span title=\"xip/c:PREP\">in</span>" + |
| 191 | " <span title=\"xip/c:NP\">" + |
| 192 | " <span title=\"xip/c:PRON\">der</span>" + |
| 193 | " </span>" + |
| 194 | " <span title=\"xip/c:NPA\">" + |
| 195 | " <span title=\"xip/c:NP\">" + |
| 196 | " <span title=\"xip/c:NOUN\">Bridge</span>" + |
| 197 | " </span>" + |
| 198 | " </span>" + |
| 199 | " </span>" + |
| 200 | " <span title=\"xip/c:INFC\">" + |
| 201 | " <span title=\"xip/c:INS\">" + |
| 202 | " <span title=\"xip/c:VERB\">weiterzugeben</span>" + |
| 203 | " </span>" + |
| 204 | " </span>" + |
| 205 | " </span>" + |
| 206 | " </span>" + |
| 207 | "</span>" + |
| 208 | "<span class=\"context-right\"></span>"; |
| 209 | |
Akron | 3bdac53 | 2019-03-04 13:24:43 +0100 | [diff] [blame] | 210 | var treeSnippetHierarchy = |
| 211 | "<span class=\"context-left\"><\/span><span class=\"match\"><span title=\"corenlp\/c:MPN\">Leonard Maltin<\/span> schrieb: „<span title=\"corenlp\/c:S\"><span title=\"corenlp\/c:NP\">Plot <span title=\"corenlp\/c:MPN\">contrivance isn‘<mark>t<\/mark> handled badly<\/span><\/span> <span title=\"corenlp\/c:PP\">in above-average programmer<\/span><\/span>“.<<span title=\"corenlp\/c:S\"><span title=\"corenlp\/c:ROOT\"><span title=\"corenlp\/c:NP\">ref>''<span title=\"corenlp\/c:NP\"><span title=\"corenlp\/c:CNP\">Movie &amp; Video<\/span> Guide<\/span><\/span>'', <span title=\"corenlp\/c:VP\">1996 edition, <span title=\"corenlp\/c:NP\"><span title=\"corenlp\/c:CNP\">S. 210<\/span><\/span><\/span>.<\/span><\/span><\/span><span class=\"context-right\"><\/span>"; |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 212 | |
Akron | 3bdac53 | 2019-03-04 13:24:43 +0100 | [diff] [blame] | 213 | function matchElementFactory () { |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 214 | var me = document.createElement('li'); |
| 215 | |
| 216 | me.setAttribute( |
| 217 | 'data-available-info', |
| 218 | 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' + |
| 219 | ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' + |
| 220 | ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' + |
| 221 | ' tt/p=tokens tt/s=spans'); |
| 222 | |
| 223 | me.setAttribute('data-corpus-id', 'WPD'); |
| 224 | me.setAttribute('data-doc-id', 'FFF'); |
| 225 | me.setAttribute('data-text-id', '01460'); |
| 226 | me.setAttribute('data-text-sigle', 'WPD/FFF/01460'); |
| 227 | me.setAttribute('data-match-id', 'p119-120'); |
| 228 | me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>'; |
| 229 | return me; |
| 230 | }; |
| 231 | |
| 232 | function matchElementReal () { |
| 233 | var me = document.createElement('em'); |
| 234 | me.innerHTML = |
| 235 | '<li data-match-id="p85183-85184"' + |
| 236 | ' data-text-sigle="GOE/AGI/00000"' + |
| 237 | ' data-available-info="base/s=spans corenlp/c=spans corenlp/p=tokens corenlp/s=spans dereko/s=spans malt/d=rels opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans"' + |
| 238 | ' data-info="{"UID":0,"author":"Goethe, Johann Wolfgang von","corpusID":null,"corpusSigle":"GOE","docID":null,"docSigle":"GOE\/AGI","layerInfos":"base\/s=spans corenlp\/c=spans corenlp\/p=tokens corenlp\/s=spans dereko\/s=spans malt\/d=rels opennlp\/p=tokens opennlp\/s=spans tt\/l=tokens tt\/p=tokens tt\/s=spans","matchID":"match-GOE\/AGI\/00000-p85183-85184","pubDate":"1982","pubPlace":"München","subTitle":"Auch ich in Arkadien!","textID":null,"textSigle":"GOE\/AGI\/00000","title":"Italienische Reise"}"' + |
| 239 | ' id="GOE/AGI/00000#p85183-85184">' + |
| 240 | '<div>' + |
| 241 | '<div class="flag"></div>' + |
| 242 | '<div class="snippet startMore endMore"><span class="context-left"><span class="more"></span>keine großen Flächen, aber sanft gegeneinander laufende Berg- und Hügelrücken, durchgängig mit Weizen und Gerste bestellt, die eine ununterbrochene Masse von Fruchtbarkeit dem Auge darbieten. der diesen Pflanzen geeignete Boden wird so genutzt und so geschont, daß man nirgends einen </span><span class="match"><mark>Baum</mark></span><span class="context-right"> sieht, ja, alle die kleinen Ortschaften und Wohnungen liegen auf Rücken der Hügel, wo eine hinstreichende Reihe Kalkfelsen den Boden ohnehin unbrauchbar macht. dort wohnen die Weiber das ganze Jahr, mit Spinnen und Weben beschäftigt, die Männer hingegen bringen zur<span class="more"></span></span></div>' + |
| 243 | '</div>' + |
| 244 | '<p class="ref"><strong>Italienische Reise</strong> von Goethe, Johann Wolfgang von (<time datetime="1982">1982</time>) <span class="sigle">[GOE/AGI/00000]</span> </p>' + |
| 245 | '</li>'; |
| 246 | return me.firstChild; |
| 247 | }; |
| 248 | |
| 249 | var beforeAllFunc = function () { |
| 250 | // Override getMatchInfo API call |
| 251 | KorAP.API.getMatchInfo = function (x, param, cb) { |
| 252 | if (param['spans'] === undefined || param['spans'] === false) |
| 253 | cb({ "snippet": snippet }); |
| 254 | else |
| 255 | cb({ "snippet": treeSnippet }); |
| 256 | }; |
| 257 | }; |
| 258 | |
| 259 | var afterAllFunc = function () { |
| 260 | KorAP.API.getMatchInfo = undefined; |
| 261 | // KorAP.annotationHelper = undefined; |
| 262 | var body = document.body; |
| 263 | for (var i in body.children) { |
| 264 | if (body.children[i].nodeType && body.children[i].nodeType === 1) { |
| 265 | if (!body.children[i].classList.contains("jasmine_html-reporter")) { |
| 266 | body.removeChild(body.children[i]); |
| 267 | }; |
| 268 | }; |
| 269 | }; |
| 270 | }; |
| 271 | |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 272 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 273 | describe('KorAP.InfoLayer', function () { |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 274 | beforeAll(beforeAllFunc); |
| 275 | afterAll(afterAllFunc); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 276 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 277 | it('should be initializable', function () { |
| 278 | expect( |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 279 | function() { infoClass.create() } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 280 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 281 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 282 | expect( |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 283 | function() { infoClass.create("base") } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 284 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 285 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 286 | var layer = infoClass.create("base", "s"); |
| 287 | expect(layer).toBeTruthy(); |
| 288 | expect(layer.foundry).toEqual("base"); |
| 289 | expect(layer.layer).toEqual("s"); |
| 290 | expect(layer.type).toEqual("tokens"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 291 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 292 | layer = infoClass.create("cnx", "syn", "spans"); |
| 293 | expect(layer).toBeTruthy(); |
| 294 | expect(layer.foundry).toEqual("cnx"); |
| 295 | expect(layer.layer).toEqual("syn"); |
| 296 | expect(layer.type).toEqual("spans"); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 297 | }); |
| 298 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 299 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 300 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 301 | describe('KorAP.Match', function () { |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 302 | beforeAll(beforeAllFunc); |
| 303 | afterAll(afterAllFunc); |
| 304 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 305 | var match = { |
| 306 | 'corpusID' : 'WPD', |
| 307 | 'docID' : 'UUU', |
| 308 | 'textID' : '01912', |
| 309 | 'matchID' : 'p121-122', |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 310 | 'textSigle' : 'WPD/UUU/01912', |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 311 | 'available' : available |
| 312 | }; |
| 313 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 314 | it('should be initializable by Object', function () { |
| 315 | expect(function() { |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 316 | matchClass.create() |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 317 | }).toThrow(new Error('Missing parameters')); |
| 318 | |
| 319 | expect(matchClass.create(match)).toBeTruthy(); |
| 320 | |
| 321 | var m = matchClass.create(match); |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 322 | expect(m.textSigle).toEqual("WPD/UUU/01912"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 323 | expect(m.matchID).toEqual("p121-122"); |
| 324 | |
| 325 | // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=* |
| 326 | var m = matchClass.create(match); |
| 327 | |
| 328 | // Spans: |
| 329 | var spans = m.getSpans(); |
| 330 | expect(spans[0].foundry).toEqual("base"); |
| 331 | expect(spans[0].layer).toEqual("s"); |
| 332 | |
| 333 | expect(spans[1].foundry).toEqual("corenlp"); |
| 334 | expect(spans[1].layer).toEqual("c"); |
| 335 | |
| 336 | expect(spans[2].foundry).toEqual("corenlp"); |
| 337 | expect(spans[2].layer).toEqual("s"); |
| 338 | |
| 339 | expect(spans[spans.length-1].foundry).toEqual("tt"); |
| 340 | expect(spans[spans.length-1].layer).toEqual("s"); |
| 341 | |
| 342 | // Tokens: |
| 343 | var tokens = m.getTokens(); |
| 344 | expect(tokens[0].foundry).toEqual("corenlp"); |
| 345 | expect(tokens[0].layer).toEqual("ne"); |
| 346 | |
| 347 | expect(tokens[1].foundry).toEqual("corenlp"); |
| 348 | expect(tokens[1].layer).toEqual("p"); |
| 349 | |
| 350 | expect(tokens[tokens.length-1].foundry).toEqual("tt"); |
| 351 | expect(tokens[tokens.length-1].layer).toEqual("p"); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 352 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 353 | |
| 354 | |
Akron | cdb0baa | 2016-11-07 01:52:11 +0100 | [diff] [blame] | 355 | it('should be initializable by Node 1', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 356 | var m = matchClass.create(matchElementFactory()); |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 357 | expect(m.textSigle).toEqual("WPD/FFF/01460"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 358 | expect(m.matchID).toEqual("p119-120"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 359 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 360 | // Spans: |
| 361 | var spans = m.getSpans(); |
| 362 | expect(spans[0].foundry).toEqual("base"); |
| 363 | expect(spans[0].layer).toEqual("s"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 364 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 365 | expect(spans[1].foundry).toEqual("corenlp"); |
| 366 | expect(spans[1].layer).toEqual("c"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 367 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 368 | expect(spans[2].foundry).toEqual("corenlp"); |
| 369 | expect(spans[2].layer).toEqual("s"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 370 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 371 | expect(spans[spans.length-1].foundry).toEqual("tt"); |
| 372 | expect(spans[spans.length-1].layer).toEqual("s"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 373 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 374 | // Tokens: |
| 375 | var tokens = m.getTokens(); |
| 376 | expect(tokens[0].foundry).toEqual("corenlp"); |
| 377 | expect(tokens[0].layer).toEqual("ne"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 378 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 379 | expect(tokens[1].foundry).toEqual("corenlp"); |
| 380 | expect(tokens[1].layer).toEqual("p"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 381 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 382 | expect(tokens[tokens.length-1].foundry).toEqual("tt"); |
| 383 | expect(tokens[tokens.length-1].layer).toEqual("p"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 384 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 385 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 386 | |
Akron | cdb0baa | 2016-11-07 01:52:11 +0100 | [diff] [blame] | 387 | it('should be initializable by Node 2', function () { |
| 388 | var ele = matchElementReal(); |
| 389 | var m = matchClass.create(ele); |
| 390 | expect(m.textSigle).toEqual("GOE/AGI/00000"); |
| 391 | expect(m.matchID).toEqual("p85183-85184"); |
| 392 | }); |
| 393 | |
| 394 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 395 | it('should react to gui actions', function () { |
| 396 | var e = matchElementFactory(); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 397 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 398 | expect(e.classList.contains('active')).toBe(false); |
| 399 | expect(e["_match"]).toBe(undefined); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 400 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 401 | var m = matchClass.create(e); |
| 402 | |
| 403 | expect(e.classList.contains('active')).toBe(false); |
| 404 | expect(e["_match"]).not.toBe(undefined); |
| 405 | |
| 406 | // Open the match |
| 407 | m.open(); |
| 408 | |
| 409 | expect(e.classList.contains('active')).toBe(true); |
| 410 | expect(e["_match"]).not.toBe(undefined); |
| 411 | |
Akron | bfe912c | 2018-07-17 19:30:52 +0200 | [diff] [blame] | 412 | actions = e.querySelector("p.ref > div.action.button-group").children; |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 413 | |
Akron | bfe912c | 2018-07-17 19:30:52 +0200 | [diff] [blame] | 414 | expect(actions[0].getAttribute("class")).toEqual("metatable"); |
Akron | c296ca2 | 2018-04-24 16:35:26 +0200 | [diff] [blame] | 415 | expect(actions[1].getAttribute("class")).toEqual("info"); |
| 416 | expect(actions[2].getAttribute("class")).toEqual("tree"); |
| 417 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 418 | // Close the match |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 419 | m.minimize(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 420 | expect(e.classList.contains('active')).toBe(false); |
| 421 | expect(e["_match"]).not.toBe(undefined); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 422 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 423 | |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 424 | it('should open tree menu', function () { |
Akron | c296ca2 | 2018-04-24 16:35:26 +0200 | [diff] [blame] | 425 | var e = matchElementFactory(); |
| 426 | var m = matchClass.create(e); |
| 427 | m.open(); |
Akron | bfe912c | 2018-07-17 19:30:52 +0200 | [diff] [blame] | 428 | var relation = e.querySelector("p.ref > div.action.button-group > span:nth-of-type(3)"); |
Akron | c296ca2 | 2018-04-24 16:35:26 +0200 | [diff] [blame] | 429 | expect(relation.getAttribute("class")).toEqual("tree"); |
Akron | 52ed22d | 2018-07-11 17:05:19 +0200 | [diff] [blame] | 430 | expect(document.getElementsByClassName("button-group-list").length).toEqual(0); |
Akron | c296ca2 | 2018-04-24 16:35:26 +0200 | [diff] [blame] | 431 | |
| 432 | expect(document.activeElement.tagName).toEqual("BODY"); |
| 433 | |
| 434 | // Show menu |
| 435 | relation.click(); |
Akron | 52ed22d | 2018-07-11 17:05:19 +0200 | [diff] [blame] | 436 | expect(document.getElementsByClassName("button-group-list").length).toEqual(1); |
Akron | c296ca2 | 2018-04-24 16:35:26 +0200 | [diff] [blame] | 437 | |
| 438 | expect(document.activeElement.tagName).toEqual("UL"); |
| 439 | |
| 440 | // Choose first tree |
Akron | 52ed22d | 2018-07-11 17:05:19 +0200 | [diff] [blame] | 441 | document.getElementsByClassName("button-group-list")[0].getElementsByTagName("li")[1].click(); |
Akron | c296ca2 | 2018-04-24 16:35:26 +0200 | [diff] [blame] | 442 | expect(e.querySelector("div.matchinfo div.matchtree h6 span").innerText).toEqual("corenlp"); |
| 443 | |
| 444 | // This should blur the focus |
| 445 | expect(document.activeElement.tagName).toEqual("BODY"); |
| 446 | }); |
| 447 | |
| 448 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 449 | |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 450 | describe('KorAP.TableView', function () { |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 451 | beforeAll(beforeAllFunc); |
| 452 | afterAll(afterAllFunc); |
Akron | 5dc3117 | 2019-05-15 18:43:48 +0200 | [diff] [blame] | 453 | |
| 454 | let longString = " und robust sind auch die anderen Traktoren, die hier der Übersicht wegen keine Erwähnung finden können."; |
| 455 | |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 456 | var table; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 457 | |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 458 | var matchObj = matchClass.create(match); |
| 459 | var tableObj = tableClass.create(matchObj); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 460 | |
| 461 | var table1, table2; |
| 462 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 463 | it('should fail to load a table async', function (done) { |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 464 | expect(tableObj).toBeTruthy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 465 | |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 466 | tableObj.getData([], function (tablen) { |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 467 | table1 = tablen; |
| 468 | done(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 469 | }); |
| 470 | }); |
| 471 | |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 472 | |
Akron | aeeb825 | 2018-09-19 18:51:00 +0200 | [diff] [blame] | 473 | xit('should\'nt be parsable (async)', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 474 | expect(table1).not.toBeTruthy(); |
| 475 | }); |
| 476 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 477 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 478 | it('should be retrieved async', function (done) { |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 479 | expect(tableObj).toBeTruthy(); |
| 480 | tableObj.getData(undefined, function (x) { |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 481 | table = x; |
| 482 | done(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 483 | }); |
| 484 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 485 | |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 486 | it('should parse into a table (async)', function () { |
| 487 | expect(table).toBeTruthy(); |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 488 | |
Akron | 083ec57 | 2019-05-16 18:30:40 +0200 | [diff] [blame^] | 489 | expect(table.length()).toBe(5); |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 490 | |
| 491 | expect(table.getToken(0)).toBe("meist"); |
| 492 | expect(table.getToken(1)).toBe("deutlich"); |
| 493 | expect(table.getToken(2)).toBe("leistungsfähiger"); |
Akron | 5dc3117 | 2019-05-15 18:43:48 +0200 | [diff] [blame] | 494 | expect(table.getToken(3)).toBe(longString); |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 495 | |
| 496 | expect(table.getValue(0, "cnx", "p")[0]).toBe("ADV"); |
| 497 | expect(table.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD"); |
| 498 | expect(table.getValue(0, "mate", "l")[0]).toBe("meist"); |
| 499 | expect(table.getValue(0, "mate", "l")[1]).toBeUndefined(); |
| 500 | |
| 501 | expect(table.getValue(2, "cnx", "l")[0]).toBe("fähig"); |
| 502 | expect(table.getValue(2, "cnx", "l")[1]).toBe("leistung"); |
| 503 | }); |
| 504 | |
| 505 | it('should be rendered async', function () { |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 506 | var e = table.element().firstChild; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 507 | expect(e.nodeName).toBe('TABLE'); |
| 508 | expect(e.children[0].nodeName).toBe('THEAD'); |
| 509 | var tr = e.children[0].children[0]; |
| 510 | expect(tr.nodeName).toBe('TR'); |
| 511 | expect(tr.children[0].nodeName).toBe('TH'); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 512 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 513 | expect(tr.children[0].firstChild.nodeValue).toBe('Foundry'); |
| 514 | expect(tr.children[1].firstChild.nodeValue).toBe('Layer'); |
| 515 | expect(tr.children[2].firstChild.nodeValue).toBe('meist'); |
Akron | ad1e46a | 2018-09-19 15:55:40 +0200 | [diff] [blame] | 516 | expect(tr.children[2].classList.contains('mark')).toBeFalsy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 517 | expect(tr.children[3].firstChild.nodeValue).toBe('deutlich'); |
Akron | ad1e46a | 2018-09-19 15:55:40 +0200 | [diff] [blame] | 518 | expect(tr.children[3].classList.contains('mark')).toBeTruthy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 519 | expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger'); |
Akron | ad1e46a | 2018-09-19 15:55:40 +0200 | [diff] [blame] | 520 | expect(tr.children[4].classList.contains('mark')).toBeFalsy(); |
Akron | 083ec57 | 2019-05-16 18:30:40 +0200 | [diff] [blame^] | 521 | expect(tr.children[4].hasAttribute("title")).toBeFalsy(); |
Akron | 5dc3117 | 2019-05-15 18:43:48 +0200 | [diff] [blame] | 522 | expect(tr.children[5].firstChild.nodeValue).toBe(longString); |
| 523 | expect(tr.children[5].getAttribute("title")).toBe(longString); |
Akron | 083ec57 | 2019-05-16 18:30:40 +0200 | [diff] [blame^] | 524 | expect(tr.children[6].classList.contains('cutted')).toBeTruthy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 525 | |
| 526 | // first row |
| 527 | tr = e.children[1].children[0]; |
| 528 | expect(tr.nodeName).toBe('TR'); |
| 529 | expect(tr.getAttribute('tabindex')).toEqual('0'); |
| 530 | expect(tr.children[0].nodeName).toBe('TH'); |
| 531 | expect(tr.children[0].firstChild.nodeValue).toEqual('cnx'); |
| 532 | expect(tr.children[1].firstChild.nodeValue).toEqual('l'); |
| 533 | expect(tr.children[2].firstChild.nodeValue).toEqual('meist'); |
| 534 | expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich'); |
Akron | 47774c4 | 2017-07-03 20:14:55 +0200 | [diff] [blame] | 535 | expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('fähig'); |
| 536 | expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('leistung'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 537 | |
| 538 | // second row |
| 539 | tr = e.children[1].children[1]; |
| 540 | expect(tr.nodeName).toBe('TR'); |
| 541 | expect(tr.getAttribute('tabindex')).toEqual('0'); |
| 542 | expect(tr.children[0].nodeName).toBe('TH'); |
| 543 | expect(tr.children[0].firstChild.nodeValue).toEqual('cnx'); |
| 544 | expect(tr.children[1].firstChild.nodeValue).toEqual('p'); |
| 545 | expect(tr.children[2].firstChild.nodeValue).toEqual('ADV'); |
| 546 | expect(tr.children[3].firstChild.nodeValue).toEqual('A'); |
Akron | 47774c4 | 2017-07-03 20:14:55 +0200 | [diff] [blame] | 547 | expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('A'); |
| 548 | expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('ADJA'); |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 549 | |
| 550 | expect(tr.children[4].firstChild.getAttribute("title")).toEqual('Adjective'); |
| 551 | expect(tr.children[2].getAttribute("title")).toEqual('Adverb'); |
| 552 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 553 | }); |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 554 | |
| 555 | |
| 556 | it('should parse into a table view (sync)', function () { |
| 557 | var matchElement = matchElementFactory(); |
| 558 | expect(matchElement.tagName).toEqual('LI'); |
| 559 | |
| 560 | // Match |
| 561 | expect(matchElement.children[0].tagName).toEqual('DIV'); |
| 562 | |
| 563 | // snippet |
| 564 | expect(matchElement.children[0].children[0].tagName).toEqual('DIV'); |
| 565 | expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy(); |
| 566 | expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check'); |
| 567 | |
| 568 | // reference |
| 569 | expect(matchElement.children[1].classList.contains('ref')).toBeTruthy(); |
| 570 | expect(matchElement.children[1].firstChild.nodeValue).toEqual('me'); |
| 571 | |
| 572 | // not yet |
| 573 | expect(matchElement.children[0].children[1]).toBe(undefined); |
| 574 | |
| 575 | /* |
| 576 | var info = matchClass.create(matchElement).info(); |
| 577 | info.showTable(); |
| 578 | */ |
| 579 | var matchObj = matchClass.create(matchElement); |
| 580 | matchObj.open(); |
| 581 | |
| 582 | // Match |
| 583 | expect(matchElement.children[0].tagName).toEqual('DIV'); |
| 584 | |
| 585 | // snippet |
| 586 | expect(matchElement.children[0].children[0].tagName).toEqual('DIV'); |
| 587 | |
| 588 | expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy(); |
| 589 | |
| 590 | expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check'); |
| 591 | |
| 592 | // reference |
| 593 | |
| 594 | expect(matchElement.children[2].classList.contains('ref')).toBeTruthy(); |
| 595 | expect(matchElement.children[2].childNodes[1].nodeValue).toEqual('me'); |
| 596 | |
| 597 | // Add table |
| 598 | matchObj.panel.addTable(); |
| 599 | |
| 600 | // now |
| 601 | var infotable = matchElement.children[1]; |
| 602 | expect(infotable.tagName).toEqual('DIV'); |
| 603 | |
| 604 | expect(infotable.classList.contains('matchinfo')).toBeTruthy(); |
| 605 | |
| 606 | expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy(); |
| 607 | |
| 608 | // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy(); |
| 609 | }); |
| 610 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 611 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 612 | |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 613 | describe('KorAP.RelationsView', function () { |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 614 | beforeAll(beforeAllFunc); |
| 615 | afterAll(afterAllFunc); |
| 616 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 617 | var tree; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 618 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 619 | it('should be rendered async 1', function (done) { |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 620 | var matchObj = matchClass.create(match); |
| 621 | var relObj = relClass.create(matchObj); |
| 622 | expect(relObj).toBeTruthy(); |
| 623 | relObj.getData(undefined, undefined, "spans", function (y) { |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 624 | tree = y; |
| 625 | done(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 626 | }); |
| 627 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 628 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 629 | it('should be rendered async 2', function () { |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 630 | expect(tree).toBeTruthy(); |
| 631 | expect(tree.nodes()).toEqual(49); |
| 632 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 633 | var e = tree.element(); |
| 634 | expect(e.nodeName).toEqual('svg'); |
| 635 | expect(e.getElementsByTagName('g').length).toEqual(48); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 636 | }); |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 637 | |
| 638 | |
| 639 | it('should add a tree view async 2', function () { |
| 640 | var matchElement = matchElementFactory(); |
| 641 | var matchObj = matchClass.create(matchElement); |
| 642 | matchObj.open(); |
| 643 | matchObj.panel.addTree('mate', 'beebop', 'spans', function () { |
| 644 | done(); |
| 645 | }); |
| 646 | |
| 647 | // With added tree |
| 648 | var tree = matchElement.children[1].firstChild.firstChild.firstChild; |
| 649 | expect(tree.tagName).toEqual('DIV'); |
| 650 | expect(tree.classList.contains('matchtree')).toBeTruthy(); |
| 651 | expect(tree.children[0].tagName).toEqual('H6'); |
| 652 | expect(tree.children[0].children[0].tagName).toEqual('SPAN'); |
| 653 | expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate'); |
| 654 | expect(tree.children[0].children[1].tagName).toEqual('SPAN'); |
| 655 | expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop'); |
| 656 | |
| 657 | expect(tree.children[1].tagName).toEqual('DIV'); |
| 658 | }); |
| 659 | |
Akron | 3bdac53 | 2019-03-04 13:24:43 +0100 | [diff] [blame] | 660 | it('should make the tree downloadable', function () { |
| 661 | var treeClass = matchHierClass.create(treeSnippetHierarchy); |
| 662 | var treeElement = treeClass.element(); |
| 663 | expect(treeElement.tagName).toEqual("svg"); |
| 664 | |
| 665 | var base64 = treeClass.toBase64(); |
| 666 | var str = atob(base64); |
| 667 | expect(str).toMatch(new RegExp('<defs><style>path')); |
| 668 | expect(str).not.toMatch(new RegExp(' ')); |
| 669 | expect(str).toMatch(new RegExp('&')); |
| 670 | }); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 671 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 672 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 673 | |
| 674 | describe('KorAP.MatchTreeItem', function () { |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 675 | beforeAll(beforeAllFunc); |
| 676 | afterAll(afterAllFunc); |
| 677 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 678 | it('should be initializable', function () { |
| 679 | var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c']) |
| 680 | expect(mi.element().firstChild.nodeValue).toEqual('cnx/c'); |
| 681 | expect(mi.lcField()).toEqual(' cnx/c'); |
| 682 | expect(mi.foundry()).toEqual('cnx'); |
| 683 | expect(mi.layer()).toEqual('c'); |
| 684 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 685 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 686 | |
| 687 | |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 688 | describe('KorAP.MatchRelation', function () { |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 689 | beforeAll(beforeAllFunc); |
| 690 | afterAll(afterAllFunc); |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 691 | |
| 692 | var relExample = "<span class=\"context-left\"></span>" + |
| 693 | "<span class=\"match\">" + |
| 694 | " <span xml:id=\"token-GOE/AGA/01784-p199\">" + |
| 695 | " <span xlink:title=\"malt/d:ADV\" " + |
| 696 | " xlink:type=\"simple\" " + |
| 697 | " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" + |
| 698 | " </span>" + |
| 699 | " zog " + |
| 700 | " <span xlink:title=\"malt/d:SUBJ\" " + |
| 701 | " xlink:type=\"simple\" " + |
| 702 | " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" + |
| 703 | " <span xml:id=\"token-GOE/AGA/01784-p202\">" + |
| 704 | " <span xlink:title=\"malt/d:OBJA\" " + |
| 705 | " xlink:type=\"simple\" " + |
| 706 | " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" + |
| 707 | " </span>" + |
| 708 | "</span>" + |
| 709 | "<span class=\"context-right\"></span>"; |
| 710 | |
| 711 | |
| 712 | it('should be initializable', function () { |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 713 | var tree = matchRelClass.create(); |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 714 | expect(tree.size()).toBe(0); |
| 715 | }); |
| 716 | |
| 717 | it('should be parse string data', function () { |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 718 | var tree = matchRelClass.create(relExample); |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 719 | expect(tree.size()).toBe(4); |
| 720 | }); |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 721 | }); |
| 722 | |
| 723 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 724 | describe('KorAP.MatchTreeMenu', function () { |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 725 | beforeAll(beforeAllFunc); |
| 726 | afterAll(afterAllFunc); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 727 | |
| 728 | it('should be initializable', function () { |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 729 | var menu = matchTreeMenuClass.create([ |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 730 | ['cnx/c', 'cnx', 'c'], |
| 731 | ['xip/c', 'xip', 'c'] |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 732 | ], matchTreeItemClass); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 733 | |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 734 | expect(menu.itemClass()).toEqual(matchTreeItemClass); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 735 | expect(menu.element().nodeName).toEqual('UL'); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 736 | expect(menu.element().classList.contains('visible')).toBeFalsy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 737 | expect(menu.limit()).toEqual(6); |
| 738 | menu.show(); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 739 | expect(menu.element().classList.contains('visible')).toBeTruthy(); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 740 | expect(menu.item(0).active()).toBe(false); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 741 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 742 | }); |
hebasta | 999d6c1 | 2018-04-23 12:44:59 +0200 | [diff] [blame] | 743 | |
| 744 | //Test display and sorting of meta information |
| 745 | describe('KorAP.Meta', function(){ |
Akron | d8692de | 2018-07-26 13:06:01 +0200 | [diff] [blame] | 746 | beforeAll(beforeAllFunc); |
| 747 | afterAll(afterAllFunc); |
| 748 | |
| 749 | var met = metaClass.create(match, fields); |
hebasta | 999d6c1 | 2018-04-23 12:44:59 +0200 | [diff] [blame] | 750 | var mel = met.element(); |
| 751 | |
| 752 | // Meta information should be parsed into a list |
| 753 | it('should parse in a meta view', function(){ |
Akron | fa32c9d | 2018-11-20 15:39:18 +0100 | [diff] [blame] | 754 | expect(mel.tagName).toEqual('DL'); |
| 755 | expect(mel.children[0].tagName).toEqual('DIV'); |
| 756 | expect(mel.children[0].children[0].tagName).toEqual('DT'); |
| 757 | expect(mel.children[0].children[0].attributes[0].name).toEqual('title'); |
| 758 | expect(mel.children[0].children[1].tagName).toEqual('DD'); |
| 759 | expect(mel.children[0].children[1].getAttribute('data-type')).toEqual('type:text') |
hebasta | 999d6c1 | 2018-04-23 12:44:59 +0200 | [diff] [blame] | 760 | |
Akron | fa32c9d | 2018-11-20 15:39:18 +0100 | [diff] [blame] | 761 | expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author'); |
| 762 | expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.'); |
| 763 | expect(mel.children[0].children[0].attributes[0].value).toEqual('author'); |
hebasta | 999d6c1 | 2018-04-23 12:44:59 +0200 | [diff] [blame] | 764 | }); |
| 765 | |
| 766 | |
Akron | fa32c9d | 2018-11-20 15:39:18 +0100 | [diff] [blame] | 767 | /* The keywords in the meta information list should be formatted to be able |
| 768 | to chose each keyword separately in the corpusByMatch assistant. */ |
| 769 | it('keywords should be formatted', function(){ |
hebasta | 999d6c1 | 2018-04-23 12:44:59 +0200 | [diff] [blame] | 770 | |
Akron | fa32c9d | 2018-11-20 15:39:18 +0100 | [diff] [blame] | 771 | //type:string or type:keyword should b not relevant |
| 772 | expect(mel.children[1].children[1].getAttribute('data-type')).toEqual('type:string') |
| 773 | expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy; |
| 774 | expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV'); |
| 775 | expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp'); |
| 776 | expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV'); |
| 777 | expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency'); |
| 778 | |
| 779 | expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy; |
| 780 | expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV'); |
| 781 | expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur'); |
| 782 | expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV'); |
| 783 | expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film'); |
hebasta | 999d6c1 | 2018-04-23 12:44:59 +0200 | [diff] [blame] | 784 | }); |
Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 785 | |
| 786 | it('attachements should be formatted', function(){ |
Akron | d3bb85b | 2019-02-08 10:15:13 +0100 | [diff] [blame] | 787 | //type:attachement with a link |
Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 788 | expect(mel.children[3].children[1].getAttribute('data-type')).toEqual('type:attachement') |
| 789 | expect(mel.children[3].children[1].classList.contains('metakeyvalues')).toBeFalsy; |
| 790 | expect(mel.children[3].children[0].firstChild.nodeValue).toEqual('xlink'); |
| 791 | expect(mel.children[3].children[1].firstChild.textContent).toEqual('Cool'); |
| 792 | expect(mel.children[3].children[1].firstChild.tagName).toEqual('A'); |
| 793 | expect(mel.children[3].children[1].firstChild.getAttribute('href')).toEqual('https://de.wikipedia.org/wiki/Beispiel'); |
Akron | d3bb85b | 2019-02-08 10:15:13 +0100 | [diff] [blame] | 794 | |
| 795 | //type:attachement with plain text |
| 796 | expect(mel.children[4].children[1].getAttribute('data-type')).toEqual('type:attachement') |
| 797 | expect(mel.children[4].children[1].classList.contains('metakeyvalues')).toBeFalsy; |
| 798 | expect(mel.children[4].children[0].firstChild.nodeValue).toEqual('z-reference'); |
| 799 | expect(mel.children[4].children[1].firstChild.nodeValue).toEqual('This is a reference'); |
| 800 | }); |
Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 801 | |
| 802 | |
hebasta | 999d6c1 | 2018-04-23 12:44:59 +0200 | [diff] [blame] | 803 | |
Akron | fa32c9d | 2018-11-20 15:39:18 +0100 | [diff] [blame] | 804 | // Meta information should be sorted alphabetically |
| 805 | it('should be alphabetically sorted', function(){ |
| 806 | var a = mel.children[0].children[0].firstChild.nodeValue; |
| 807 | var b = mel.children[1].children[0].firstChild.nodeValue; |
| 808 | var c = mel.children[2].children[0].firstChild.nodeValue; |
| 809 | expect(a.localeCompare(b)).toBe(-1); |
| 810 | expect(b.localeCompare(c)).toBe(-1); |
Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 811 | }); |
| 812 | |
| 813 | |
| 814 | it('should handle attachements', function () { |
| 815 | let uri = attachementClass.create("data:text/plain;title=new,Hallo"); |
| 816 | expect(uri.contentType).toEqual("text/plain"); |
| 817 | |
| 818 | expect(uri.payload).toEqual("Hallo"); |
| 819 | expect(uri.base64).toBeFalsy(); |
| 820 | expect(uri.isLink).toBeFalsy(); |
| 821 | expect(uri.param["title"]).toEqual("new"); |
| 822 | |
| 823 | uri = attachementClass.create("data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel"); |
| 824 | expect(uri.contentType).toEqual("application/x.korap-link"); |
| 825 | expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel"); |
| 826 | expect(uri.base64).toBeFalsy(); |
| 827 | expect(uri.isLink).toBeTruthy(); |
| 828 | expect(uri.inline().textContent).toEqual("https://de.wikipedia.org/wiki/Beispiel"); |
| 829 | expect(uri.inline().nodeType).toEqual(1); |
| 830 | expect(uri.inline().tagName).toEqual("A"); |
| 831 | expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer"); |
| 832 | |
| 833 | |
| 834 | uri = attachementClass.create("data:application/x.korap-link;title=Das ist ein Titel,https://de.wikipedia.org/wiki/Beispiel"); |
| 835 | expect(uri.contentType).toEqual("application/x.korap-link"); |
| 836 | expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel"); |
| 837 | expect(uri.base64).toBeFalsy(); |
| 838 | expect(uri.isLink).toBeTruthy(); |
| 839 | expect(uri.inline().textContent).toEqual("Das ist ein Titel"); |
| 840 | expect(uri.inline().nodeType).toEqual(1); |
| 841 | expect(uri.inline().tagName).toEqual("A"); |
| 842 | expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer"); |
| 843 | |
| 844 | |
| 845 | uri = attachementClass.create("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D"); |
| 846 | expect(uri.contentType).toEqual("text/plain"); |
| 847 | expect(uri.payload).toEqual("Hello, World!"); |
| 848 | expect(uri.base64).toBeTruthy(); |
| 849 | expect(uri.isLink).toBeFalsy(); |
| 850 | expect(uri.inline().nodeType).toEqual(3); |
| 851 | expect(uri.inline().textContent).toEqual("Hello, World!"); |
| 852 | |
| 853 | uri = attachementClass.create("data:text/plain;title= new ; subTitle = old ;base64,SGVsbG8sIFdvcmxkIQ%3D%3D"); |
| 854 | expect(uri.contentType).toEqual("text/plain"); |
| 855 | expect(uri.payload).toEqual("Hello, World!"); |
| 856 | expect(uri.param["title"]).toEqual("new"); |
| 857 | expect(uri.param["subTitle"]).toEqual("old"); |
| 858 | expect(uri.base64).toBeTruthy(); |
| 859 | expect(uri.isLink).toBeFalsy(); |
| 860 | expect(uri.inline().nodeType).toEqual(3); |
| 861 | expect(uri.inline().textContent).toEqual("Hello, World!"); |
| 862 | }); |
hebasta | 999d6c1 | 2018-04-23 12:44:59 +0200 | [diff] [blame] | 863 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 864 | // table = view.toTable(); |
| 865 | // table.sortBy(''); |
| 866 | // table.element(); |
| 867 | // tree = view.toTree(); |
| 868 | // tree.element(); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 869 | }); |