Debian Codegraph @

bqplot/js/src/test/image.ts

raw
1 import { expect } from 'chai';
2
3 import { DummyManager } from './dummy-manager';
4
5 import * as bqplot from '..';
6
7 import { create_figure_image, create_model } from './widget-utils';
8
9 import { testX, testY, pixelRed, redPngData, redPngDataUrl } from './common';
10
11 import * as d3Timer from 'd3-timer';
12
13 describe('image >', () => {
14 beforeEach(async function () {
15 this.manager = new DummyManager({ bqplot: bqplot });
16 });
17
18 it('image buffer', async function () {
19 const png_buffer = new DataView(new Uint8Array(redPngData).buffer);
20 const ipywidgetImage = await create_model(
21 this.manager,
22 '@jupyter-widgets/controls',
23 'ImageModel',
24 'ImageView',
25 'im1',
26 {
27 value: png_buffer,
28 format: 'png',
29 }
30 );
31 const { figure } = await create_figure_image(this.manager, ipywidgetImage);
32
33 d3Timer.timerFlush(); // this makes sure the animations are all executed
34 const canvas = await figure.get_rendered_canvas();
35 const context = canvas.getContext('2d');
36 const pixel = context.getImageData(testX, testY, 1, 1);
37 expect(Array.prototype.slice.call(pixel.data)).to.deep.equals(pixelRed);
38 });
39 it('image data url', async function () {
40 const png_buffer = new DataView(
41 new TextEncoder().encode(redPngDataUrl).buffer
42 );
43 const ipywidgetImage = await create_model(
44 this.manager,
45 '@jupyter-widgets/controls',
46 'ImageModel',
47 'ImageView',
48 'im1',
49 {
50 value: png_buffer,
51 format: 'url',
52 }
53 );
54 const { figure } = await create_figure_image(this.manager, ipywidgetImage);
55
56 d3Timer.timerFlush(); // this makes sure the animations are all executed
57 const canvas = await figure.get_rendered_canvas();
58 const context = canvas.getContext('2d');
59 const pixel = context.getImageData(testX, testY, 1, 1);
60 expect(Array.prototype.slice.call(pixel.data)).to.deep.equals(pixelRed);
61 });
62 });