"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
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 chai_1 = require("chai");
const dummy_manager_1 = require("./dummy-manager");
const bqplot = __importStar(require(".."));
const widget_utils_1 = require("./widget-utils");
const common_1 = require("./common");
const d3Timer = __importStar(require("d3-timer"));
describe('image >', () => {
    beforeEach(function () {
        return __awaiter(this, void 0, void 0, function* () {
            this.manager = new dummy_manager_1.DummyManager({ bqplot: bqplot });
        });
    });
    it('image buffer', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const png_buffer = new DataView(new Uint8Array(common_1.redPngData).buffer);
            const ipywidgetImage = yield widget_utils_1.create_model(this.manager, '@jupyter-widgets/controls', 'ImageModel', 'ImageView', 'im1', {
                value: png_buffer,
                format: 'png',
            });
            const { figure } = yield widget_utils_1.create_figure_image(this.manager, ipywidgetImage);
            d3Timer.timerFlush(); // this makes sure the animations are all executed
            const canvas = yield figure.get_rendered_canvas();
            const context = canvas.getContext('2d');
            const pixel = context.getImageData(common_1.testX, common_1.testY, 1, 1);
            chai_1.expect(Array.prototype.slice.call(pixel.data)).to.deep.equals(common_1.pixelRed);
        });
    });
    it('image data url', function () {
        return __awaiter(this, void 0, void 0, function* () {
            const png_buffer = new DataView(new TextEncoder().encode(common_1.redPngDataUrl).buffer);
            const ipywidgetImage = yield widget_utils_1.create_model(this.manager, '@jupyter-widgets/controls', 'ImageModel', 'ImageView', 'im1', {
                value: png_buffer,
                format: 'url',
            });
            const { figure } = yield widget_utils_1.create_figure_image(this.manager, ipywidgetImage);
            d3Timer.timerFlush(); // this makes sure the animations are all executed
            const canvas = yield figure.get_rendered_canvas();
            const context = canvas.getContext('2d');
            const pixel = context.getImageData(common_1.testX, common_1.testY, 1, 1);
            chai_1.expect(Array.prototype.slice.call(pixel.data)).to.deep.equals(common_1.pixelRed);
        });
    });
});
//# sourceMappingURL=image.js.map