Akron | 0f6552f | 2020-10-20 10:06:46 +0200 | [diff] [blame^] | 1 | define([ |
| 2 | 'panel', |
| 3 | 'view', |
| 4 | 'view/match/meta', |
| 5 | 'view/match/relations', |
| 6 | 'view/match/tokentable', |
| 7 | 'view/result/koralquery', |
| 8 | 'util'], function ( |
| 9 | panelClass, |
| 10 | viewClass, |
| 11 | metaViewClass, |
| 12 | relViewClass, |
| 13 | tokenViewClass, |
| 14 | kqViewClass) { |
| 15 | |
| 16 | describe('KorAP.View', function () { |
| 17 | it('should be initializable', function () { |
| 18 | var view = viewClass.create(); |
| 19 | |
| 20 | expect(view.shown()).toBeFalsy(); |
| 21 | |
| 22 | var e = view.element(); |
| 23 | expect(view.shown()).toBeTruthy(); |
| 24 | |
| 25 | expect(e.tagName).toEqual("DIV"); |
| 26 | expect(e.classList.contains("view")).toBeTruthy(); |
| 27 | |
| 28 | var btn = e.firstChild; |
| 29 | expect(btn.tagName).toEqual("DIV"); |
| 30 | expect(btn.classList.contains("button-view")).toBeTruthy(); |
| 31 | expect(btn.classList.contains("button-group")).toBeTruthy(); |
| 32 | |
| 33 | expect(btn.firstChild.tagName).toEqual("SPAN"); |
| 34 | expect(btn.firstChild.getAttribute("title")).toEqual("Close"); |
| 35 | expect(btn.firstChild.classList.contains("button-icon")).toBeTruthy(); |
| 36 | expect(btn.firstChild.classList.contains("close")).toBeTruthy(); |
| 37 | expect(btn.firstChild.firstChild.tagName).toEqual("SPAN"); |
| 38 | expect(btn.firstChild.firstChild.firstChild.data).toEqual("Close"); |
| 39 | }); |
| 40 | |
| 41 | it('should be classable', function () { |
| 42 | var view = viewClass.create(['versuch']); |
| 43 | var e = view.element(); |
| 44 | expect(e.tagName).toEqual("DIV"); |
| 45 | expect(e.classList.contains("view")).toBeTruthy(); |
| 46 | expect(e.classList.contains("versuch")).toBeTruthy(); |
| 47 | |
| 48 | var btn = e.firstChild; |
| 49 | expect(btn.tagName).toEqual("DIV"); |
| 50 | expect(btn.classList.contains("button-view")).toBeTruthy(); |
| 51 | expect(btn.classList.contains("button-group")).toBeTruthy(); |
| 52 | expect(btn.classList.contains("versuch")).toBeTruthy(); |
| 53 | }); |
| 54 | |
| 55 | it('should be minimizable', function () { |
| 56 | var view = viewClass.create(['versuch']); |
| 57 | var e = view.element(); |
| 58 | expect(e.classList.contains('show')).toBeTruthy(); |
| 59 | view.minimize(); |
| 60 | expect(e.classList.contains('show')).toBeFalsy(); |
| 61 | }); |
| 62 | }); |
| 63 | |
| 64 | describe('KorAP.View.Match.Meta', function () { |
| 65 | it('should be initializable', function () { |
| 66 | let match = null; |
| 67 | let view = metaViewClass.create(match); |
| 68 | expect(view).toBeTruthy(); |
| 69 | }) |
| 70 | }); |
| 71 | |
| 72 | describe('KorAP.View.Match.Relation', function () { |
| 73 | it('should be initializable', function () { |
| 74 | let match = null; |
| 75 | let view = relViewClass.create(match, "corenlp","l"); |
| 76 | expect(view).toBeTruthy(); |
| 77 | }); |
| 78 | |
| 79 | it('should be visible', function () { |
| 80 | let match = null; |
| 81 | let view = relViewClass.create(match, "corenlp","l","spans"); |
| 82 | var el = view.show(); |
| 83 | expect(el.tagName).toEqual('DIV'); |
| 84 | expect(el.children[0].tagName).toEqual('H6'); |
| 85 | expect(el.children[0].getElementsByTagName('span')[0].textContent).toEqual('corenlp'); |
| 86 | expect(el.children[0].getElementsByTagName('span')[1].textContent).toEqual('l'); |
| 87 | expect(el.children[1].tagName).toEqual('DIV'); |
| 88 | }) |
| 89 | }); |
| 90 | |
| 91 | describe('KorAP.View.Match.TokenTable', function () { |
| 92 | it('should be initializable', function () { |
| 93 | let match = null; |
| 94 | let view = tokenViewClass.create(match); |
| 95 | expect(view).toBeTruthy(); |
| 96 | }) |
| 97 | |
| 98 | it('should be visible', function () { |
| 99 | let match = null; |
| 100 | let view = tokenViewClass.create(match); |
| 101 | expect(view).toBeTruthy(); |
| 102 | |
| 103 | let el = view.show(); |
| 104 | expect(el.tagName).toEqual("DIV"); |
| 105 | expect(el.classList.contains("loading")).toBeTruthy(); |
| 106 | }) |
| 107 | }); |
| 108 | |
| 109 | describe('KorAP.View.Result.KoralQuery', function () { |
| 110 | |
| 111 | beforeEach( |
| 112 | function () { |
| 113 | KorAP.koralQuery = {} |
| 114 | } |
| 115 | ); |
| 116 | |
| 117 | afterEach( |
| 118 | function () { |
| 119 | KorAP.koralQuery = {} |
| 120 | } |
| 121 | ); |
| 122 | |
| 123 | it('should be initializable', function () { |
| 124 | KorAP.koralQuery = { |
| 125 | "test" : "cool" |
| 126 | }; |
| 127 | var kq = kqViewClass.create(); |
| 128 | var content = kq.element().firstChild.textContent; |
| 129 | expect(content).toMatch(/test/); |
| 130 | expect(content).toMatch(/cool/); |
| 131 | }); |
| 132 | |
| 133 | it('should deal with XML fragments', function () { |
| 134 | KorAP.koralQuery = { |
| 135 | "test" : "Das ist <b>Super!</b>" |
| 136 | }; |
| 137 | var kq = kqViewClass.create(); |
| 138 | var content = kq.element().firstChild.textContent; |
| 139 | expect(content).toMatch(/test/); |
| 140 | expect(content).toMatch(/Das ist <b>Super!<\/b>/); |
| 141 | }); |
| 142 | }); |
| 143 | }); |