How to use headerName method in apickli

Best JavaScript code snippet using apickli

network_utils_spec.js

Source:network_utils_spec.js Github

copy

Full Screen

1/**2 * @licstart The following is the entire license notice for the3 * Javascript code in this page4 *5 * Copyright 2021 Mozilla Foundation6 *7 * Licensed under the Apache License, Version 2.0 (the "License");8 * you may not use this file except in compliance with the License.9 * You may obtain a copy of the License at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing, software14 * distributed under the License is distributed on an "AS IS" BASIS,15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16 * See the License for the specific language governing permissions and17 * limitations under the License.18 *19 * @licend The above is the entire license notice for the20 * Javascript code in this page21 */22"use strict";23var _network_utils = require("../../display/network_utils.js");24var _util = require("../../shared/util.js");25describe("network_utils", function () {26 describe("validateRangeRequestCapabilities", function () {27 it("rejects range chunk sizes that are not larger than zero", function () {28 expect(function () {29 (0, _network_utils.validateRangeRequestCapabilities)({30 rangeChunkSize: 031 });32 }).toThrow(new Error("Range chunk size must be larger than zero"));33 });34 it("rejects disabled or non-HTTP range requests", function () {35 expect((0, _network_utils.validateRangeRequestCapabilities)({36 disableRange: true,37 isHttp: true,38 getResponseHeader: headerName => {39 if (headerName === "Content-Length") {40 return 8;41 }42 throw new Error(`Unexpected headerName: ${headerName}`);43 },44 rangeChunkSize: 6445 })).toEqual({46 allowRangeRequests: false,47 suggestedLength: 848 });49 expect((0, _network_utils.validateRangeRequestCapabilities)({50 disableRange: false,51 isHttp: false,52 getResponseHeader: headerName => {53 if (headerName === "Content-Length") {54 return 8;55 }56 throw new Error(`Unexpected headerName: ${headerName}`);57 },58 rangeChunkSize: 6459 })).toEqual({60 allowRangeRequests: false,61 suggestedLength: 862 });63 });64 it("rejects invalid Accept-Ranges header values", function () {65 expect((0, _network_utils.validateRangeRequestCapabilities)({66 disableRange: false,67 isHttp: true,68 getResponseHeader: headerName => {69 if (headerName === "Accept-Ranges") {70 return "none";71 } else if (headerName === "Content-Length") {72 return 8;73 }74 throw new Error(`Unexpected headerName: ${headerName}`);75 },76 rangeChunkSize: 6477 })).toEqual({78 allowRangeRequests: false,79 suggestedLength: 880 });81 });82 it("rejects invalid Content-Encoding header values", function () {83 expect((0, _network_utils.validateRangeRequestCapabilities)({84 disableRange: false,85 isHttp: true,86 getResponseHeader: headerName => {87 if (headerName === "Accept-Ranges") {88 return "bytes";89 } else if (headerName === "Content-Encoding") {90 return "gzip";91 } else if (headerName === "Content-Length") {92 return 8;93 }94 throw new Error(`Unexpected headerName: ${headerName}`);95 },96 rangeChunkSize: 6497 })).toEqual({98 allowRangeRequests: false,99 suggestedLength: 8100 });101 });102 it("rejects invalid Content-Length header values", function () {103 expect((0, _network_utils.validateRangeRequestCapabilities)({104 disableRange: false,105 isHttp: true,106 getResponseHeader: headerName => {107 if (headerName === "Accept-Ranges") {108 return "bytes";109 } else if (headerName === "Content-Encoding") {110 return null;111 } else if (headerName === "Content-Length") {112 return "eight";113 }114 throw new Error(`Unexpected headerName: ${headerName}`);115 },116 rangeChunkSize: 64117 })).toEqual({118 allowRangeRequests: false,119 suggestedLength: undefined120 });121 });122 it("rejects file sizes that are too small for range requests", function () {123 expect((0, _network_utils.validateRangeRequestCapabilities)({124 disableRange: false,125 isHttp: true,126 getResponseHeader: headerName => {127 if (headerName === "Accept-Ranges") {128 return "bytes";129 } else if (headerName === "Content-Encoding") {130 return null;131 } else if (headerName === "Content-Length") {132 return 8;133 }134 throw new Error(`Unexpected headerName: ${headerName}`);135 },136 rangeChunkSize: 64137 })).toEqual({138 allowRangeRequests: false,139 suggestedLength: 8140 });141 });142 it("accepts file sizes large enough for range requests", function () {143 expect((0, _network_utils.validateRangeRequestCapabilities)({144 disableRange: false,145 isHttp: true,146 getResponseHeader: headerName => {147 if (headerName === "Accept-Ranges") {148 return "bytes";149 } else if (headerName === "Content-Encoding") {150 return null;151 } else if (headerName === "Content-Length") {152 return 8192;153 }154 throw new Error(`Unexpected headerName: ${headerName}`);155 },156 rangeChunkSize: 64157 })).toEqual({158 allowRangeRequests: true,159 suggestedLength: 8192160 });161 });162 });163 describe("extractFilenameFromHeader", function () {164 it("returns null when content disposition header is blank", function () {165 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {166 if (headerName === "Content-Disposition") {167 return null;168 }169 throw new Error(`Unexpected headerName: ${headerName}`);170 })).toBeNull();171 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {172 if (headerName === "Content-Disposition") {173 return undefined;174 }175 throw new Error(`Unexpected headerName: ${headerName}`);176 })).toBeNull();177 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {178 if (headerName === "Content-Disposition") {179 return "";180 }181 throw new Error(`Unexpected headerName: ${headerName}`);182 })).toBeNull();183 });184 it("gets the filename from the response header", function () {185 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {186 if (headerName === "Content-Disposition") {187 return "inline";188 }189 throw new Error(`Unexpected headerName: ${headerName}`);190 })).toBeNull();191 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {192 if (headerName === "Content-Disposition") {193 return "attachment";194 }195 throw new Error(`Unexpected headerName: ${headerName}`);196 })).toBeNull();197 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {198 if (headerName === "Content-Disposition") {199 return 'attachment; filename="filename.pdf"';200 }201 throw new Error(`Unexpected headerName: ${headerName}`);202 })).toEqual("filename.pdf");203 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {204 if (headerName === "Content-Disposition") {205 return 'attachment; filename="filename.pdf and spaces.pdf"';206 }207 throw new Error(`Unexpected headerName: ${headerName}`);208 })).toEqual("filename.pdf and spaces.pdf");209 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {210 if (headerName === "Content-Disposition") {211 return 'attachment; filename="tl;dr.pdf"';212 }213 throw new Error(`Unexpected headerName: ${headerName}`);214 })).toEqual("tl;dr.pdf");215 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {216 if (headerName === "Content-Disposition") {217 return "attachment; filename=filename.pdf";218 }219 throw new Error(`Unexpected headerName: ${headerName}`);220 })).toEqual("filename.pdf");221 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {222 if (headerName === "Content-Disposition") {223 return "attachment; filename=filename.pdf someotherparam";224 }225 throw new Error(`Unexpected headerName: ${headerName}`);226 })).toEqual("filename.pdf");227 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {228 if (headerName === "Content-Disposition") {229 return 'attachment; filename="%e4%b8%ad%e6%96%87.pdf"';230 }231 throw new Error(`Unexpected headerName: ${headerName}`);232 })).toEqual("中文.pdf");233 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {234 if (headerName === "Content-Disposition") {235 return 'attachment; filename="100%.pdf"';236 }237 throw new Error(`Unexpected headerName: ${headerName}`);238 })).toEqual("100%.pdf");239 });240 it("gets the filename from the response header (RFC 6266)", function () {241 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {242 if (headerName === "Content-Disposition") {243 return "attachment; filename*=filename.pdf";244 }245 throw new Error(`Unexpected headerName: ${headerName}`);246 })).toEqual("filename.pdf");247 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {248 if (headerName === "Content-Disposition") {249 return "attachment; filename*=''filename.pdf";250 }251 throw new Error(`Unexpected headerName: ${headerName}`);252 })).toEqual("filename.pdf");253 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {254 if (headerName === "Content-Disposition") {255 return "attachment; filename*=utf-8''filename.pdf";256 }257 throw new Error(`Unexpected headerName: ${headerName}`);258 })).toEqual("filename.pdf");259 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {260 if (headerName === "Content-Disposition") {261 return "attachment; filename=no.pdf; filename*=utf-8''filename.pdf";262 }263 throw new Error(`Unexpected headerName: ${headerName}`);264 })).toEqual("filename.pdf");265 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {266 if (headerName === "Content-Disposition") {267 return "attachment; filename*=utf-8''filename.pdf; filename=no.pdf";268 }269 throw new Error(`Unexpected headerName: ${headerName}`);270 })).toEqual("filename.pdf");271 });272 it("gets the filename from the response header (RFC 2231)", function () {273 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {274 if (headerName === "Content-Disposition") {275 return "attachment; filename*0=filename; filename*1=.pdf";276 }277 throw new Error(`Unexpected headerName: ${headerName}`);278 })).toEqual("filename.pdf");279 });280 it("only extracts filename with pdf extension", function () {281 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {282 if (headerName === "Content-Disposition") {283 return 'attachment; filename="filename.png"';284 }285 throw new Error(`Unexpected headerName: ${headerName}`);286 })).toBeNull();287 });288 it("extension validation is case insensitive", function () {289 expect((0, _network_utils.extractFilenameFromHeader)(headerName => {290 if (headerName === "Content-Disposition") {291 return 'form-data; name="fieldName"; filename="file.PdF"';292 }293 throw new Error(`Unexpected headerName: ${headerName}`);294 })).toEqual("file.PdF");295 });296 });297 describe("createResponseStatusError", function () {298 it("handles missing PDF file responses", function () {299 expect((0, _network_utils.createResponseStatusError)(404, "https://foo.com/bar.pdf")).toEqual(new _util.MissingPDFException('Missing PDF "https://foo.com/bar.pdf".'));300 expect((0, _network_utils.createResponseStatusError)(0, "file://foo.pdf")).toEqual(new _util.MissingPDFException('Missing PDF "file://foo.pdf".'));301 });302 it("handles unexpected responses", function () {303 expect((0, _network_utils.createResponseStatusError)(302, "https://foo.com/bar.pdf")).toEqual(new _util.UnexpectedResponseException("Unexpected server response (302) while retrieving PDF " + '"https://foo.com/bar.pdf".'));304 expect((0, _network_utils.createResponseStatusError)(0, "https://foo.com/bar.pdf")).toEqual(new _util.UnexpectedResponseException("Unexpected server response (0) while retrieving PDF " + '"https://foo.com/bar.pdf".'));305 });306 });307 describe("validateResponseStatus", function () {308 it("accepts valid response statuses", function () {309 expect((0, _network_utils.validateResponseStatus)(200)).toEqual(true);310 expect((0, _network_utils.validateResponseStatus)(206)).toEqual(true);311 });312 it("rejects invalid response statuses", function () {313 expect((0, _network_utils.validateResponseStatus)(302)).toEqual(false);314 expect((0, _network_utils.validateResponseStatus)(404)).toEqual(false);315 expect((0, _network_utils.validateResponseStatus)(null)).toEqual(false);316 expect((0, _network_utils.validateResponseStatus)(undefined)).toEqual(false);317 });318 });...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1/* Объявление переменных */2// Ссылка на JSON файл3const urlToJson = "https://api.github.com/repositories";4// Количество строк на страницу5let countOfItemsPerPage;6// Блок, где будет хранится таблица7let eGridDiv;8// Модель данных JSON файла9let columnDefs = [10 {headerName: "id", field: "id"},11 {headerName: "node_id", field: "node_id"},12 {headerName: "name", field: "name"},13 {headerName: "full_name", field: "full_name"},14 {headerName: "private", field: "private"},15 {headerName: "owner",16 children: [17 {headerName: "owner.login", field: "owner.login"},18 {headerName: "owner.id", field: "owner.id"},19 {headerName: "owner.node_id", field: "owner.node_id"},20 {headerName: "owner.avatar_url", field: "owner.avatar_url"},21 {headerName: "owner.gravatar_id", field: "owner.gravatar_id"},22 {headerName: "owner.url", field: "owner.url"},23 {headerName: "owner.html_url", field: "owner.html_url"},24 {headerName: "owner.followers_url", field: "owner.followers_url"},25 {headerName: "owner.following_url", field: "owner.following_url"},26 {headerName: "owner.gists_url", field: "owner.gists_url"},27 {headerName: "owner.starred_url", field: "owner.starred_url"},28 {headerName: "owner.subscriptions_url", field: "owner.subscriptions_url"},29 {headerName: "owner.organizations_url", field: "owner.organizations_url"},30 {headerName: "owner.repos_url", field: "owner.repos_url"},31 {headerName: "owner.events_url", field: "owner.events_url"},32 {headerName: "owner.received_events_url", field: "owner.received_events_url"},33 {headerName: "owner.type", field: "owner.type"},34 {headerName: "owner.site_admin", field: "owner.site_admin"},35 ]},36 {headerName: "html_url", field: "html_url"},37 {headerName: "description", field: "description"},38 {headerName: "fork", field: "fork"},39 {headerName: "url", field: "url"},40 {headerName: "forks_url", field: "forks_url"},41 {headerName: "keys_url", field: "keys_url"},42 {headerName: "collaborators_url", field: "collaborators_url"},43 {headerName: "teams_url", field: "teams_url"},44 {headerName: "hooks_url", field: "hooks_url"},45 {headerName: "issue_events_url", field: "issue_events_url"},46 {headerName: "events_url", field: "events_url"},47 {headerName: "assignees_url", field: "assignees_url"},48 {headerName: "branches_url", field: "branches_url"},49 {headerName: "tags_url", field: "tags_url"},50 {headerName: "blobs_url", field: "blobs_url"},51 {headerName: "git_tags_url", field: "git_tags_url"},52 {headerName: "git_refs_url", field: "git_refs_url"},53 {headerName: "trees_url", field: "trees_url"},54 {headerName: "statuses_url", field: "statuses_url"},55 {headerName: "languages_url", field: "languages_url"},56 {headerName: "stargazers_url", field: "stargazers_url"},57 {headerName: "contributors_url", field: "contributors_url"},58 {headerName: "subscribers_url", field: "subscribers_url"},59 {headerName: "subscription_url", field: "subscription_url"},60 {headerName: "commits_url", field: "commits_url"},61 {headerName: "git_commits_url", field: "git_commits_url"},62 {headerName: "comments_url", field: "comments_url"},63 {headerName: "issue_comment_url", field: "issue_comment_url"},64 {headerName: "contents_url", field: "contents_url"},65 {headerName: "compare_url", field: "compare_url"},66 {headerName: "merges_url", field: "merges_url"},67 {headerName: "archive_url", field: "archive_url"},68 {headerName: "downloads_url", field: "downloads_url"},69 {headerName: "issues_url", field: "issues_url"},70 {headerName: "pulls_url", field: "pulls_url"},71 {headerName: "milestones_url", field: "milestones_url"},72 {headerName: "notifications_url", field: "notifications_url"},73 {headerName: "labels_url", field: "labels_url"},74 {headerName: "releases_url", field: "releases_url"},75 {headerName: "deployments_url", field: "deployments_url"}76];77// Опции ap-Grid78let gridOptions = {79 columnDefs: columnDefs,80 pagination: true,81 paginationPageSize: 1082};83/* Подписка на событие загрузки DOM и иные события, иницилизация таблицы */84$(document).ready(function () {85 //86 $(".main-container, #mainForm, #myGrid").width(window.innerWidth - 20);87 $(".main-container, #mainForm, #myGrid").height(window.innerHeight - 20);88 eGridDiv = document.querySelector('#myGrid');89 new agGrid.Grid(eGridDiv, gridOptions);90 agGrid.simpleHttpRequest({url: urlToJson}).then(function(data) {91 gridOptions.api.setRowData(data);92 setCountOfItemsPerPage();93 autoSizeAll(true);94 });95});96/* Подписка на событие изменения размера рабочего окна */97window.onresize = function (event) {98 $(".main-container, #mainForm, #myGrid").width(window.innerWidth - 20);99 $(".main-container, #mainForm, #myGrid").height(window.innerHeight - 20);100 autoSizeAll(true);101};102/* Функция авто установки ширины колонок, параметр true/false не учитывает header */103function autoSizeAll(skipHeader) {104 let allColumnIds = [];105 gridOptions.columnApi.getAllColumns().forEach(function (column) {106 allColumnIds.push(column.colId);107 });108 gridOptions.columnApi.autoSizeColumns(allColumnIds, skipHeader);109};110/* Функция устанавливает количество строк на страницу таблицы, вводи через prompt*/111function setCountOfItemsPerPage() {112 do {113 countOfItemsPerPage = prompt("Please enter count of items that will be loaded per page:");114 } while (isNaN(countOfItemsPerPage));115 if (!isNaN(countOfItemsPerPage)){116 gridOptions.api.paginationSetPageSize(countOfItemsPerPage);117 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var apickli = require('apickli');2var {defineSupportCode} = require('cucumber');3defineSupportCode(function({Given, When, Then}) {4 Given('I set header {string} to {string}', function (headerName, headerValue, callback) {5 this.apickli.addRequestHeader(headerName, headerValue);6 callback();7 });8});9var apickli = require('apickli');10var {defineSupportCode} = require('cucumber');11defineSupportCode(function({Given, When, Then}) {12 Given('I set header {string} to {string}', function (headerName, headerValue, callback) {13 this.apickli.addRequestHeader(headerName, headerValue);14 callback();15 });16});17var apickli = require('apickli');18var {defineSupportCode} = require('cucumber');19defineSupportCode(function({Given, When, Then}) {20 Given('I set header {string} to {string}', function (headerName, headerValue, callback) {21 this.apickli.addRequestHeader(headerName, headerValue);22 callback();23 });24});25var apickli = require('apickli');26var {defineSupportCode} = require('cucumber');27defineSupportCode(function({Given, When, Then}) {28 Given('I set header {string} to {string}', function (headerName, headerValue, callback) {29 this.apickli.addRequestHeader(headerName, headerValue);30 callback();31 });32});33var apickli = require('apickli');34var {defineSupportCode} = require('cucumber');35defineSupportCode(function({Given, When, Then}) {36 Given('I set header {string} to {string}', function (headerName, headerValue, callback) {37 this.apickli.addRequestHeader(headerName, headerValue);38 callback();39 });40});

Full Screen

Using AI Code Generation

copy

Full Screen

1var apickli = require('apickli');2var {defineSupportCode} = require('cucumber');3defineSupportCode(function({Before, Given, When, Then}) {4 Before(function() {5 this.apickli = new apickli.Apickli('http', 'localhost:8000');6 });7 Given('I set header {string} to {string}', function(headerName, headerValue, callback) {8 this.apickli.addRequestHeader(headerName, headerValue);9 callback();10 });11 When('I GET {string}', function(resource, callback) {12 this.apickli.get(resource, callback);13 });14 Then('response code should be {int}', function(statusCode, callback) {15 this.apickli.assertResponseCode(statusCode);16 callback();17 });18});

Full Screen

Using AI Code Generation

copy

Full Screen

1var apickli = require('apickli');2var {defineSupportCode} = require('cucumber');3defineSupportCode(function({Given, When, Then}) {4 var myApickli = new apickli.Apickli('http', 'localhost:8000');5 myApickli.addRequestHeader('headerName', 'headerValue');6 Given('a request header is set', function (callback) {7 callback(null, 'pending');8 });9 When('a request is made to the API', function (callback) {10 callback(null, 'pending');11 });12 Then('the request header is included in the request', function (callback) {13 callback(null, 'pending');14 });15});

Full Screen

Using AI Code Generation

copy

Full Screen

1var headerName = apickli.Apickli.prototype.headerName;2var headerName = apickli.Apickli.prototype.headerName;3var headerName = apickli.Apickli.prototype.headerName;4var headerName = apickli.Apickli.prototype.headerName;5var headerName = apickli.Apickli.prototype.headerName;6var headerName = apickli.Apickli.prototype.headerName;7var headerName = apickli.Apickli.prototype.headerName;8var headerName = apickli.Apickli.prototype.headerName;9var headerName = apickli.Apickli.prototype.headerName;10var headerName = apickli.Apickli.prototype.headerName;11var headerName = apickli.Apickli.prototype.headerName;12var headerName = apickli.Apickli.prototype.headerName;13var headerName = apickli.Apickli.prototype.headerName;

Full Screen

Using AI Code Generation

copy

Full Screen

1var apickli = require('apickli');2var {defineSupportCode} = require('cucumber');3defineSupportCode(function({Given, When, Then}) {4 var apickli = new apickli.Apickli('http', 'localhost:8080');5 var headerName = apickli.getHeaderName('Content-Type');6 apickli.addRequestHeader(headerName, 'application/json');7 Given('I have the following products', function (table, callback) {8 callback(null, 'pending');9 });10});

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 apickli 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