Akron | 644ad9f | 2021-07-26 16:12:59 +0200 | [diff] [blame] | 1 | define(['panel','view','panel/result','panel/pagination','util'], function (panelClass,viewClass,resultClass,paginationClass) { |
Akron | 56d4207 | 2018-07-24 11:17:24 +0200 | [diff] [blame] | 2 | |
| 3 | var controlStr = ""; |
| 4 | |
| 5 | var helloViewClass = { |
| 6 | create : function () { |
| 7 | return Object.create(viewClass)._init(['myview']).upgradeTo(this); |
| 8 | }, |
| 9 | |
| 10 | show : function () { |
| 11 | if (this._show) |
| 12 | return this._show; |
| 13 | |
| 14 | var e = document.createElement('span'); |
| 15 | e.addT("Hello World!"); |
| 16 | |
| 17 | this._show = e; |
| 18 | return e; |
| 19 | } |
| 20 | }; |
hebasta | d025eb9 | 2019-12-07 21:04:42 +0100 | [diff] [blame] | 21 | |
| 22 | var secViewClass = { |
| 23 | create : function () { |
| 24 | return Object.create(viewClass)._init(['secview']).upgradeTo(this); |
| 25 | }, |
| 26 | }; |
Akron | 56d4207 | 2018-07-24 11:17:24 +0200 | [diff] [blame] | 27 | |
| 28 | describe('KorAP.Panel', function () { |
| 29 | |
| 30 | it('should be initializable', function () { |
| 31 | var panel = panelClass.create(); |
| 32 | var e = panel.element(); |
| 33 | expect(e.tagName).toEqual("DIV"); |
| 34 | expect(e.classList.contains("panel")).toBeTruthy(); |
| 35 | expect(e.firstChild.tagName).toEqual("DIV"); |
| 36 | |
| 37 | // No children in the empty view element |
| 38 | expect(e.firstChild.firstChild).toBeFalsy(); |
| 39 | expect(e.lastChild.tagName).toEqual("DIV"); |
| 40 | expect(e.lastChild.classList.contains("button-panel")).toBeTruthy(); |
| 41 | expect(e.lastChild.classList.contains("button-group")).toBeTruthy(); |
| 42 | expect(e.lastChild.firstChild).toBeFalsy(); |
| 43 | |
Akron | 37ea119 | 2021-07-28 10:40:14 +0200 | [diff] [blame] | 44 | expect(panel.actions()).toBeTruthy(); |
Akron | 56d4207 | 2018-07-24 11:17:24 +0200 | [diff] [blame] | 45 | }); |
| 46 | |
| 47 | |
| 48 | it('should be extensible', function () { |
| 49 | var panel = panelClass.create(); |
| 50 | |
| 51 | controlStr = ""; |
Akron | 37ea119 | 2021-07-28 10:40:14 +0200 | [diff] [blame] | 52 | panel.actions().add("New", {'cls':["new"]}, function () { |
Akron | 56d4207 | 2018-07-24 11:17:24 +0200 | [diff] [blame] | 53 | controlStr = 'New!!!'; |
| 54 | }); |
| 55 | |
| 56 | var e = panel.element(); |
| 57 | |
| 58 | expect(e.tagName).toEqual("DIV"); |
| 59 | expect(e.firstChild.firstChild).toBeFalsy(); |
| 60 | |
| 61 | expect(e.lastChild.firstChild.tagName).toEqual("SPAN"); |
| 62 | expect(e.lastChild.firstChild.getAttribute("title")).toEqual("New"); |
| 63 | expect(e.lastChild.firstChild.classList.contains("new")).toBeTruthy(); |
| 64 | expect(e.lastChild.firstChild.firstChild.tagName).toEqual("SPAN"); |
| 65 | expect(e.lastChild.firstChild.firstChild.firstChild.data).toEqual("New"); |
| 66 | |
| 67 | expect(controlStr).toEqual(""); |
| 68 | e.lastChild.firstChild.click(); |
| 69 | expect(controlStr).toEqual("New!!!"); |
| 70 | }); |
| 71 | |
| 72 | it('should be classable', function () { |
| 73 | var panel = panelClass.create(["versuch"]); |
| 74 | var e = panel.element(); |
| 75 | expect(e.tagName).toEqual("DIV"); |
| 76 | expect(e.classList.contains("panel")).toBeTruthy(); |
| 77 | expect(e.classList.contains("versuch")).toBeTruthy(); |
| 78 | expect(e.lastChild.classList.contains("button-panel")).toBeTruthy(); |
| 79 | expect(e.lastChild.classList.contains("versuch")).toBeTruthy(); |
| 80 | }); |
| 81 | |
| 82 | it('should be extensible by a view', function () { |
| 83 | var panel = panelClass.create(); |
| 84 | var view = helloViewClass.create(); |
| 85 | var e = panel.element(); |
| 86 | |
| 87 | panel.add(view); |
| 88 | |
| 89 | var viewE = e.firstChild.firstChild; |
| 90 | expect(viewE.classList.contains('view')).toBeTruthy(); |
| 91 | expect(viewE.classList.contains('myview')).toBeTruthy(); |
| 92 | expect(viewE.firstChild.tagName).toEqual("SPAN"); |
| 93 | expect(viewE.firstChild.firstChild.data).toEqual("Hello World!"); |
| 94 | }); |
hebasta | d025eb9 | 2019-12-07 21:04:42 +0100 | [diff] [blame] | 95 | |
| 96 | it('views should be appended or prepended', function () { |
| 97 | let panel = panelClass.create(); |
| 98 | let view = helloViewClass.create(); |
| 99 | let e = panel.element(); |
| 100 | panel.add(view); |
| 101 | let secview = secViewClass.create(); |
| 102 | panel.add(secview); |
| 103 | let viewFirst = e.firstChild.firstChild; |
| 104 | expect(viewFirst.classList.contains('myview')).toBeTruthy(); |
| 105 | |
| 106 | let prependPanel = panelClass.create(); |
| 107 | prependPanel.prepend = true; |
| 108 | prependPanel.add(view); |
| 109 | prependPanel.add(secview); |
| 110 | viewFirst = prependPanel.element().firstChild.firstChild; |
| 111 | expect(viewFirst.classList.contains('secview')).toBeTruthy(); |
| 112 | }); |
| 113 | |
Akron | 56d4207 | 2018-07-24 11:17:24 +0200 | [diff] [blame] | 114 | }); |
Akron | 362c11a | 2018-08-29 20:01:30 +0200 | [diff] [blame] | 115 | |
| 116 | describe('KorAP.Panel.Result', function () { |
| 117 | |
| 118 | it('should be initializable', function () { |
| 119 | var show = {}; |
| 120 | var result = resultClass.create(show); |
| 121 | expect(result.element().children.length).toEqual(2); |
| 122 | expect(result.element().firstChild.children.length).toEqual(0); |
| 123 | }); |
| 124 | |
| 125 | it('should open KQAction', function () { |
| 126 | var show = {}; |
| 127 | var result = resultClass.create(show); |
| 128 | |
| 129 | result.addKqAction(); |
| 130 | |
| 131 | expect(result.element().lastChild.firstChild.textContent).toEqual("show KoralQuery"); |
| 132 | expect(show["kq"]).toBeFalsy(); |
| 133 | |
| 134 | // Open KQ view |
| 135 | result.element().lastChild.firstChild.click(); |
| 136 | |
| 137 | expect(result.element().querySelector('#koralquery').textContent).toEqual("{}"); |
| 138 | expect(show["kq"]).toBeTruthy(); |
| 139 | |
| 140 | var close = result.element().firstChild.firstChild.lastChild.firstChild; |
| 141 | expect(close.textContent).toEqual("Close"); |
| 142 | |
| 143 | // Close view |
| 144 | close.click(); |
| 145 | |
| 146 | expect(result.element().querySelector('#koralquery')).toBeFalsy(); |
| 147 | expect(show["kq"]).toBeFalsy(); |
| 148 | }); |
Akron | ece4bb7 | 2020-10-19 12:24:20 +0200 | [diff] [blame] | 149 | |
| 150 | it('should open toggler', function () { |
| 151 | const show = {}; |
| 152 | |
| 153 | const div = document.body.addE("div"); |
| 154 | div.setAttribute("id","search"); |
| 155 | const ol = div.addE("ol"); |
| 156 | ol.classList.add("align-left"); |
| 157 | |
| 158 | const result = resultClass.create(show); |
| 159 | |
| 160 | result.addAlignAction(); |
| 161 | |
| 162 | const b = result.element().lastChild.firstChild; |
| 163 | |
| 164 | expect(b.textContent).toEqual("toggle alignment"); |
| 165 | expect(b.classList.contains('right')).toBeTruthy(); |
| 166 | expect(ol.classList.contains('align-left')).toBeTruthy(); |
| 167 | |
| 168 | b.click(); |
| 169 | |
| 170 | expect(b.textContent).toEqual("toggle alignment"); |
| 171 | expect(b.classList.contains('center')).toBeTruthy(); |
| 172 | expect(ol.classList.contains('align-right')).toBeTruthy(); |
| 173 | |
| 174 | b.click(); |
| 175 | |
| 176 | expect(b.textContent).toEqual("toggle alignment"); |
| 177 | expect(b.classList.contains('left')).toBeTruthy(); |
| 178 | expect(ol.classList.contains('align-center')).toBeTruthy(); |
| 179 | |
| 180 | b.click(); |
| 181 | |
| 182 | expect(b.textContent).toEqual("toggle alignment"); |
| 183 | expect(b.classList.contains('right')).toBeTruthy(); |
| 184 | expect(ol.classList.contains('align-left')).toBeTruthy(); |
| 185 | |
| 186 | document.body.removeChild(div); |
| 187 | }); |
Akron | 362c11a | 2018-08-29 20:01:30 +0200 | [diff] [blame] | 188 | }); |
Akron | 644ad9f | 2021-07-26 16:12:59 +0200 | [diff] [blame] | 189 | |
| 190 | describe('KorAP.Panel.Pagination', function () { |
| 191 | it('should be initializable', function () { |
| 192 | // Create pagination element for pagination information |
| 193 | let p = document.createElement('div'); |
| 194 | p.setAttribute('id', 'pagination') |
| 195 | p.setAttribute('data-page',3); |
| 196 | p.setAttribute('data-total',30); |
| 197 | p.setAttribute('data-count',25); |
| 198 | |
| 199 | document.body.appendChild(p); |
| 200 | |
| 201 | // Create pagination class object |
| 202 | var pagination = paginationClass.create(); |
| 203 | let list = pagination.actions().element(); |
| 204 | expect(list.classList.contains('button-group-list')).toBeTruthy(); |
| 205 | expect(list.classList.contains('visible')).toBeFalsy(); |
| 206 | |
| 207 | pagination.addRandomPage(); |
| 208 | |
| 209 | let clicked = false; |
| 210 | pagination.actions().add( |
| 211 | "test", {}, function () { clicked = true } |
| 212 | ); |
| 213 | |
| 214 | pagination.buttonGroup().element().firstChild.click(); |
| 215 | expect(list.classList.contains('visible')).toBeTruthy(); |
| 216 | |
| 217 | expect(clicked).toBeFalsy(); |
| 218 | pagination.actions().element().children[4].click(); |
| 219 | expect(clicked).toBeTruthy(); |
| 220 | |
| 221 | document.body.removeChild(p); |
| 222 | document.body.removeChild(pagination.actions().element()); |
| 223 | }); |
| 224 | }); |
Akron | 56d4207 | 2018-07-24 11:17:24 +0200 | [diff] [blame] | 225 | }); |