UNPKG

flagpole

Version:

Simple and fast DOM integration, headless or headful browser, and REST API testing framework.

72 lines 2.77 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const response_1 = require("./response"); const enums_1 = require("./enums"); const url_1 = require("url"); const value_1 = require("./value"); class ImageResponse extends response_1.ProtoResponse { constructor() { super(...arguments); this.imageProperties = { width: 0, height: 0, type: "", mime: "", wUnits: "0", hUnits: "0", length: 0, url: "" }; } get length() { return this._wrapAsValue(this.imageProperties.length, "Image Size"); } get url() { return this._wrapAsValue(this.imageProperties.url, "URL of Image"); } get path() { return this._wrapAsValue(new url_1.URL(this.imageProperties.url).pathname, "URL Path of Image"); } get responseType() { return enums_1.ResponseType.image; } get responseTypeName() { return "Image"; } init(httpResponse) { super.init(httpResponse); this.imageProperties = JSON.parse(httpResponse.body); this.context .assert("MIME Type matches expected value for an image", this.imageProperties.mime) .startsWith("image/"); } evaluate(context, callback) { return __awaiter(this, void 0, void 0, function* () { throw new Error("Evaluate does not support images."); }); } find(propertyName) { return __awaiter(this, void 0, void 0, function* () { return new value_1.Value(typeof this.imageProperties[propertyName] !== "undefined" ? this.imageProperties[propertyName] : null, this.context, `${propertyName} of Image`); }); } findAll(propertyName) { return __awaiter(this, void 0, void 0, function* () { const value = yield this.find(propertyName); return value.isNull() ? [] : [value]; }); } } exports.ImageResponse = ImageResponse; //# sourceMappingURL=imageresponse.js.map