How to use twoHeaders method in frisby

Best JavaScript code snippet using frisby

grid.complexHeaders.js

Source:grid.complexHeaders.js Github

copy

Full Screen

1/**2 * jqGrid complexGroupHeaders3 * name cj4 * email 85309651@qq.com5 * blog http://cjblog.iteye.com/6 * version 0.27 * date 2012-06-038**/9(function($){10 $.jgrid.extend({11 /**12 * 三级表头 by ljq13 * @参数 o : 三级表头参数14 */15 setComplexHeaders : function ( o ) {16 o = $.extend({17 complexHeaders: {18 defaultStyle : true,19 threeLevel:[],20 twoLevel:[]21 }22 }, o || {});23 return this.each(function(){24 //三级表头和二级表头25 var complexHeaders = o.complexHeaders,26 threeHeaders = complexHeaders["threeLevel"],27 twoHeaders = complexHeaders["twoLevel"];28 if (threeHeaders.length === 0 || twoHeaders.length === 0) {29 return; 30 }31 this.p.complexHeader = o;32 var ts = this,33 defaultStyle = complexHeaders.defaultStyle === undefined ? true : complexHeaders.defaultStyle,34 i, cmi, $thirdHeaderRow, $fourHeaderRow, $colHeader, th, $th, thStyle,35 iCol,36 tempInCol,37 inThreeCol,38 inTwoCol,39 threeLevelSkip = 0, 40 twoLevelSkip = 0, 41 hasTwoLevel = false,42 cghi,43 numberOfColumns,44 titleText,45 cVisibleColumns,46 colModel = ts.p.colModel,47 cml = colModel.length,48 ths = ts.grid.headers,49 $htable = $("table.ui-jqgrid-htable", ts.grid.hDiv),50 $secondHeaderRow = $htable.children("thead").children("tr.ui-jqgrid-labels:last").addClass("jqg-second-row-header"),51 $thead = $htable.children("thead"),52 $theadInTable,53 originalResizeStop,54 $firstHeaderRow = $htable.find(".jqg-first-row-header");55 if ($firstHeaderRow[0] === undefined) {56 $firstHeaderRow = $('<tr>', {role: "row", "aria-hidden": "true"}).addClass("jqg-first-row-header").css("height", "auto");57 } else {58 $firstHeaderRow.empty();59 }60 var $firstRow,61 inColumnHeader = function (text, columnHeaders) {62 var i = 0, length = columnHeaders.length;63 for (; i < length; i++) {64 if (columnHeaders[i] && columnHeaders[i].startColumnName === text) {65 return i;66 }67 }68 return -1;69 };70 $(ts).prepend($thead);71 $thirdHeaderRow = $('<tr>', {role: "rowheader"}).addClass("ui-jqgrid-labels jqg-third-row-header");72 $fourHeaderRow = $('<tr>', {role: "rowheader"}).addClass("ui-jqgrid-labels jqg-four-row-header");73 74 //循环模型每列75 for (i = 0; i < cml; i++) {76 th = ths[i].el;77 $th = $(th);78 cmi = colModel[i];79 // 给第一行添加单元格80 thStyle = { height: '0px', width: ths[i].width +'px', display: (cmi.hidden ? 'none' : '')};81 $("<th>", {role: 'gridcell'}).css(thStyle).addClass("ui-first-th-"+ts.p.direction).appendTo($firstHeaderRow);82 //移除不需要的样式83 th.style.width = ""; 84 85 //是否在threeHeaders配置里面86 inThreeCol = inColumnHeader(cmi.name, threeHeaders);87 if (inThreeCol >= 0) {88 cghi = threeHeaders[inThreeCol];89 numberOfColumns = parseInt(cghi.numberOfColumns,10);90 titleText = cghi.titleText;91 // 计算显示的列长度92 for (cVisibleColumns = 0, iCol = 0; iCol < numberOfColumns && (i + iCol < cml); iCol++) {93 if (!colModel[i + iCol].hidden) {94 cVisibleColumns++;95 }96 }97 98 $colHeader = $('<th>').attr({role: "columnheader",noWrap:true})99 .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)100 .css({'height':'22px', 'border-top':'0px none','overflow':'hidden'})101 .html(titleText);102 if(cVisibleColumns > 0) {103 $colHeader.attr("colspan", String(cVisibleColumns));104 }105 if (ts.p.headertitles) {106 $colHeader.attr("title", $colHeader.text());107 }108 //如果没有可见列则隐藏109 if( cVisibleColumns === 0) {110 $colHeader.hide();111 }112 $th.before($colHeader); 113 threeLevelSkip = numberOfColumns;114 if (defaultStyle === false) {115 hasTwoLevel = false;116 //判断是否存在二层117 for (var a=0;a<threeLevelSkip && (a+i<cml);a++) {118 tempInCol = inColumnHeader(colModel[a+i].name, twoHeaders);119 if (tempInCol>=0) {120 cghi = twoHeaders[tempInCol];121 numberOfColumns = parseInt(cghi.numberOfColumns,10);122 // 计算显示的列长度123 for (iCol = 0; iCol < numberOfColumns && (a+i+iCol < cml); iCol++) {124 if (!colModel[a+i+iCol].hidden) {125 hasTwoLevel = true;126 break;127 }128 }129 if (hasTwoLevel === true) {130 break;131 }132 }133 }134 }135 }136 137 //是否在twoHeaders配置里面138 inTwoCol = inColumnHeader(cmi.name, twoHeaders);139 if (threeLevelSkip >0 && inTwoCol >= 0) {140 cghi = twoHeaders[inTwoCol];141 numberOfColumns = parseInt(cghi.numberOfColumns,10);142 titleText = cghi.titleText;143 // 计算显示的列长度144 for (cVisibleColumns = 0, iCol = 0; iCol < numberOfColumns && (i + iCol < cml); iCol++) {145 if (!colModel[i + iCol].hidden) {146 cVisibleColumns++;147 }148 }149 150 $colHeader = $('<th>').attr({role: "columnheader",noWrap:true})151 .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)152 .css({'height':'22px', 'border-top': '0px none','overflow':'hidden'})153 .html(titleText);154 if(cVisibleColumns > 0) {155 $colHeader.attr("colspan", String(cVisibleColumns));156 }157 158 if (ts.p.headertitles) {159 $colHeader.attr("title", $colHeader.text());160 }161 //如果没有可见列则隐藏162 if( cVisibleColumns === 0) {163 $colHeader.hide();164 }165 $thirdHeaderRow.append($colHeader);166 twoLevelSkip = numberOfColumns;167 }168 169 //不在第三层170 if (threeLevelSkip === 0) {171 $th.attr("rowspan", "3");172 twoLevelSkip = 0;173 continue;174 }175 176 //在第三层不在第二层177 if (threeLevelSkip > 0 && twoLevelSkip === 0) {178 if (defaultStyle) {179 $th.attr("rowspan", "2");180 $thirdHeaderRow.append(th);181 } else {182 if (hasTwoLevel) {183 $th.attr("rowspan", "2");184 $thirdHeaderRow.append(th); 185 } else {186 $colHeader.attr("rowspan", "2");187 $fourHeaderRow.append(th); 188 }189 }190 threeLevelSkip--;191 continue;192 }193 194 //在第三层也在第二层195 if (threeLevelSkip > 0 && twoLevelSkip > 0) {196 $fourHeaderRow.append(th);197 threeLevelSkip--;198 twoLevelSkip--;199 }200 }201 $theadInTable = $(ts).children("thead");202 $theadInTable.prepend($firstHeaderRow);203 $thirdHeaderRow.insertAfter($secondHeaderRow);204 $fourHeaderRow.insertAfter($thirdHeaderRow);205 $htable.append($theadInTable);206 $htable.find("span.ui-jqgrid-resize").each(function () {207 var $parent = $(this).parent();208 if ($parent.is(":visible")) {209 this.style.cssText = 'height: ' + ($parent.height()/*+4*/) + 'px !important; cursor: col-resize;';210 }211 });212 $htable.find("div.ui-jqgrid-sortable").each(function () {213 var $ts = $(this), $parent = $ts.parent();214 if ($parent.is(":visible") && $parent.is(":has(span.ui-jqgrid-resize)")) {215 $ts.css('top', ($parent.height() - $ts.outerHeight()) / 2 + 'px');216 }217 });218 219 $firstRow = $theadInTable.find("tr.jqg-first-row-header");220 $(ts).bind('jqGridResizeStop.setGroupHeaders', function (e, nw, idx) {221 $firstRow.find('th').eq(idx).width(nw);222 });223 }); 224 },225 226 /**227 * 构造多表头冻结表格 by ljq228 * @参数 maxfrozen : 冻结的列index229 * @参数 htbl : 表格230 */231 createFrozenHtable : function(maxfrozen, htbl) {232 var ts = this[0],233 complexHeader = ts.p.complexHeader,234 complexHeaders = complexHeader["complexHeaders"],235 defaultStyle = complexHeaders.defaultStyle,236 threeHeaders = complexHeaders["threeLevel"],237 twoHeaders = complexHeaders["twoLevel"],238 tableid = ts.p.id,239 colModel = ts.p.colModel,240 cml = maxfrozen+1,241 ths = ts.grid.headers,242 threeLevelSkip = 0, 243 twoLevelSkip = 0, 244 hasTwoLevel = false,245 i, cmi, thStyle, th, $th, cn, $tempTh, iCol, $colHeader, cghi,246 tempInCol,247 inThreeCol,248 inTwoCol,249 numberOfColumns,250 titleText,251 cVisibleColumns,252 height = ts.grid.fhDiv.height(),253 $fhTable = $("<table class='ui-jqgrid-htable' style='width:1px;height:"+ height +"px' role='grid' aria-labelledby='gbox_"+tableid+"' cellspacing='0' cellpadding='0' border='0'></table>"),254 $thead = $("<thead></thead>"),255 $firstHeaderRow = $('<tr>', {role: "row", "aria-hidden": "true"}).addClass("jqg-first-row-header").css("height", "auto"),256 $secondHeaderRow = $('<tr>', {role: "rowheader"}).addClass("ui-jqgrid-labels jqg-second-row-header"),257 $thirdHeaderRow = $('<tr>', {role: "rowheader"}).addClass("ui-jqgrid-labels jqg-third-row-header"),258 $fourHeaderRow = $('<tr>', {role: "rowheader"}).addClass("ui-jqgrid-labels jqg-four-row-header"),259 inColumnHeader = function (text, columnHeaders) {260 var i = 0, length = columnHeaders.length;261 for (; i < length; i++) {262 if (columnHeaders[i] && columnHeaders[i].startColumnName === text) {263 return i;264 }265 }266 return -1;267 };268 269 //循环模型每列270 for (i = 0; i < cml; i++) {271 cmi = colModel[i];272 cn = cmi.name;273 $th = $("#"+tableid+"_"+cn,htbl);274 // 给第一行添加单元格275 thStyle = { height: '0px', width: ths[i].width +'px', display: (cmi.hidden ? 'none' : '')};276 $("<th>", {role: 'gridcell'}).css(thStyle).addClass("ui-first-th-"+ts.p.direction).appendTo($firstHeaderRow);277 //是否在threeHeaders配置里面278 inThreeCol = inColumnHeader(cmi.name, threeHeaders);279 if (inThreeCol >= 0) {280 cghi = threeHeaders[inThreeCol];281 numberOfColumns = parseInt(cghi.numberOfColumns,10);282 if (numberOfColumns+i-1>maxfrozen) {283 numberOfColumns = maxfrozen-i+1;284 }285 titleText = cghi.titleText;286 // 计算显示的列长度287 for (cVisibleColumns = 0, iCol = 0; iCol < numberOfColumns && (i + iCol < cml); iCol++) {288 if (!colModel[i + iCol].hidden) {289 cVisibleColumns++;290 }291 }292 $colHeader = $('<th>').attr({role: "columnheader",noWrap:true})293 .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)294 .css({'height':'22px', 'border-top':'0px none','overflow':'hidden'})295 .html(titleText);296 if(cVisibleColumns > 0) {297 $colHeader.attr("colspan", String(cVisibleColumns));298 }299 if (ts.p.headertitles) {300 $colHeader.attr("title", $colHeader.text());301 }302 //如果没有可见列则隐藏303 if( cVisibleColumns === 0) {304 $colHeader.hide();305 }306 $colHeader.appendTo($secondHeaderRow);307 threeLevelSkip = numberOfColumns;308 if (defaultStyle === false) {309 hasTwoLevel = false;310 //判断是否存在二层311 for (var a=0;a<threeLevelSkip && (a+i<cml);a++) {312 tempInCol = inColumnHeader(colModel[a+i].name, twoHeaders);313 if (tempInCol>=0) {314 cghi = twoHeaders[tempInCol];315 numberOfColumns = parseInt(cghi.numberOfColumns,10);316 if (numberOfColumns+a+i-1>maxfrozen) {317 numberOfColumns = maxfrozen-(a+i)+1;318 }319 // 计算显示的列长度320 for (iCol = 0; iCol < numberOfColumns && (a+i+iCol < cml); iCol++) {321 if (!colModel[a+i+iCol].hidden) {322 hasTwoLevel = true;323 break;324 }325 }326 }327 if (hasTwoLevel === true) {328 break;329 } 330 }331 }332 }333 //是否在twoHeaders配置里面334 inTwoCol = inColumnHeader(cmi.name, twoHeaders);335 if (threeLevelSkip >0 && inTwoCol >= 0) {336 cghi = twoHeaders[inTwoCol];337 numberOfColumns = parseInt(cghi.numberOfColumns,10);338 if (numberOfColumns+i-1>maxfrozen) {339 numberOfColumns = maxfrozen-i+1;340 }341 titleText = cghi.titleText;342 // 计算显示的列长度343 for (cVisibleColumns = 0, iCol = 0; iCol < numberOfColumns && (i + iCol < cml); iCol++) {344 if (!colModel[i + iCol].hidden) {345 cVisibleColumns++;346 }347 }348 $colHeader = $('<th>').attr({role: "columnheader",noWrap:true})349 .addClass("ui-state-default ui-th-column-header ui-th-"+ts.p.direction)350 .css({'height':'22px', 'border-top': '0px none','overflow':'hidden'})351 .html(titleText);352 if(cVisibleColumns > 0) {353 $colHeader.attr("colspan", String(cVisibleColumns));354 }355 if (ts.p.headertitles) {356 $colHeader.attr("title", $colHeader.text());357 }358 //如果没有可见列则隐藏359 if( cVisibleColumns === 0) {360 $colHeader.hide();361 }362 $colHeader.appendTo($thirdHeaderRow);363 twoLevelSkip = numberOfColumns;364 }365 //不在第三层366 if (threeLevelSkip === 0) {367 $th.attr("rowspan", "3");368 $th.appendTo($secondHeaderRow);369 twoLevelSkip = 0;370 continue;371 }372 //在第三层不在第二层373 if (threeLevelSkip > 0 && twoLevelSkip === 0) {374 if (defaultStyle) {375 $th.attr("rowspan", "2");376 $th.appendTo($thirdHeaderRow);377 } else {378 if (hasTwoLevel) {379 $th.attr("rowspan", "2");380 $th.appendTo($thirdHeaderRow);381 } else {382 $colHeader.attr("rowspan", "2");383 $th.appendTo($fourHeaderRow);384 }385 }386 threeLevelSkip--;387 continue;388 }389 //在第三层也在第二层390 if (threeLevelSkip > 0 && twoLevelSkip > 0) {391 $th.appendTo($fourHeaderRow);392 threeLevelSkip--;393 twoLevelSkip--;394 }395 }396 var thirdLen = $thirdHeaderRow.children().length,397 fourLen = $fourHeaderRow.children().length;398 if (thirdLen=== 0 && fourLen === 0) {399 $secondHeaderRow.height(height);400 }401 if (defaultStyle) {402 //默认渲染样式处理403 if (thirdLen > 0 && fourLen === 0) {404 $thirdHeaderRow.height(height-23);405 }406 } else {407 if (thirdLen === 0 && fourLen > 0) {408 $secondHeaderRow.height(height-23);409 $secondHeaderRow.find("th").each(function(){410 var rowspan = $(this).attr("rowspan");411 if (rowspan) {412 $(this).attr("rowspan",String(parseInt(rowspan,10)-1));413 }414 });415 }416 }417 418 $firstHeaderRow.appendTo($thead);419 $secondHeaderRow.appendTo($thead);420 thirdLen && $thirdHeaderRow.appendTo($thead);421 fourLen && $fourHeaderRow.appendTo($thead);422 $thead.appendTo($fhTable);423 return $fhTable;424 }425 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var frisby = require('frisby');2frisby.create('twoHeaders')3 .expectStatus(200)4 .expectHeaderContains('content-type', 'text/html')5 .expectHeaderContains('content-type', 'charset=UTF-8')6 .toss();7expectHeaderContains(headerName, value)8var frisby = require('frisby');9frisby.create('expectHeaderContains')10 .expectStatus(200)11 .expectHeaderContains('content-type', 'text/html')12 .toss();13expectHeaderToMatch(headerName, regex)14var frisby = require('frisby');15frisby.create('expectHeaderToMatch')16 .expectStatus(200)17 .expectHeaderToMatch('content-type', /text\/html/)18 .toss();19expectHeaderToNotMatch(headerName, regex)20var frisby = require('frisby');21frisby.create('expectHeaderToNotMatch')22 .expectStatus(200)23 .expectHeaderToNotMatch('content-type', /text\/html/)24 .toss();

Full Screen

Using AI Code Generation

copy

Full Screen

1var frisby = require('frisby');2frisby.create('twoHeaders')3 .expectStatus(200)4 .expectHeaderContains('content-type', 'application/json')5 .expectHeaderContains('content-type', 'charset=utf-8')6 .toss();

Full Screen

Using AI Code Generation

copy

Full Screen

1var frisby = require('frisby');2frisby.create('twoHeaders')3.expectStatus(200)4.expectHeader('Content-Type', 'text/html; charset=UTF-8')5.expectHeaderContains('Content-Type', 'text/html')6.toss();7var frisby = require('frisby');8frisby.create('addHeader')9.addHeader('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20100101 Firefox/17.0')10.expectStatus(200)11.expectHeader('Content-Type', 'text/html; charset=UTF-8')12.expectHeaderContains('Content-Type', 'text/html')13.toss();14var frisby = require('frisby');15frisby.create('addHeaders')16.addHeaders({17'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20100101 Firefox/17.0',18'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'19})20.expectStatus(200)21.expectHeader('Content-Type', 'text/html; charset=UTF-8')22.expectHeaderContains('Content-Type', 'text/html')23.toss();24var frisby = require('frisby');25frisby.create('removeHeader')26.addHeaders({27'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20100101 Firefox/17.0',28'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'29})30.expectStatus(200)31.expectHeader('Content-Type', 'text/html; charset=UTF-8')32.expectHeaderContains('Content-Type', 'text/html')33.removeHeader('Accept')34.toss();35var frisby = require('frisby');36frisby.create('removeHeaders')37.addHeaders({

Full Screen

Using AI Code Generation

copy

Full Screen

1var frisby = require('frisby');2frisby.create('twoHeaders')3 .get(URL)4 .expectStatus(200)5 .expectHeaderContains('content-type', 'text/html')6 .expectHeaderContains('content-length', '11')7 .toss();8var frisby = require('frisby');9frisby.create('twoHeaders')10 .get(URL)11 .expectStatus(200)12 .expectHeaderContains('content-type', 'text/html')13 .expectHeaderContains('content-length', '11')14 .toss();15var frisby = require('frisby');16frisby.create('twoHeaders')17 .get(URL)18 .expectStatus(200)19 .expectHeaderContains('content-type', 'text/html')20 .expectHeaderContains('content-length', '11')21 .toss();22var frisby = require('frisby');23frisby.create('twoHeaders')24 .get(URL)25 .expectStatus(200)26 .expectHeaderContains('content-type', 'text/html')27 .expectHeaderContains('content-length', '11')28 .toss();29var frisby = require('frisby');30frisby.create('twoHeaders')31 .get(URL)32 .expectStatus(200)33 .expectHeaderContains('content-type', 'text/html')34 .expectHeaderContains('content-length', '11')35 .toss();36var frisby = require('frisby');37frisby.create('twoHeaders')38 .get(URL)39 .expectStatus(200)40 .expectHeaderContains('

Full Screen

Using AI Code Generation

copy

Full Screen

1var frisby = require('frisby');2frisby.create('Test POST /api/v1/headers')3 .post(url + '/api/v1/headers', {4 headers: {5 }6 })7 .expectStatus(200)8 .expectHeader('X-Foo', 'Bar')9 .expectHeaderContains('X-Bar', 'Baz')10 .toss();11var frisby = require('frisby');12frisby.create('Test POST /api/v1/headers')13 .post(url + '/api/v1/headers', {14 headers: {15 }16 })17 .expectStatus(200)18 .expectHeader('X-Foo', 'Bar')19 .expectHeaderContains('X-Bar', 'Baz')20 .toss();21var frisby = require('frisby');22frisby.create('Test POST /api/v1/headers')23 .post(url + '/api/v1/headers', {24 headers: {25 }26 })27 .expectStatus(200)28 .expectHeader('X-Foo', 'Bar')29 .expectHeaderContains('X-Bar', 'Baz')30 .toss();31var frisby = require('frisby');32frisby.create('Test POST /api/v1/headers')33 .post(url + '/api/v1/headers', {34 headers: {35 }36 })37 .expectStatus(200)38 .expectHeader('X-Foo', 'Bar')39 .expectHeaderContains('X-Bar', '

Full Screen

Using AI Code Generation

copy

Full Screen

1var frisby = require('frisby');2frisby.create('Test to check response code and response headers')3 .get(url)4 .expectStatus(200)5 .expectHeaderContains('content-type', 'application/json')6 .toss();7var frisby = require('frisby');8frisby.create('Test to check response code and response headers')9 .get(url)10 .expectStatus(200)11 .expectHeaderContains('content-type', 'application/json')12 .toss();13var frisby = require('frisby');14frisby.create('Test to check response code and response headers')15 .get(url)16 .expectStatus(200)17 .expectHeaderContains('content-type', 'application/json')18 .toss();19var frisby = require('frisby');20frisby.create('Test to check response code and response headers')21 .get(url)22 .expectStatus(200)23 .expectHeaderContains('content-type', 'application/json')24 .toss();25var frisby = require('frisby');26frisby.create('Test to check response code and response headers')27 .get(url)28 .expectStatus(200)29 .expectHeaderContains('content-type', 'application/json')30 .toss();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run frisby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful