forked from cornerstonejs/cornerstone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw_test.js
More file actions
84 lines (69 loc) · 1.99 KB
/
Copy pathdraw_test.js
File metadata and controls
84 lines (69 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { assert } from 'chai'; // eslint-disable-line import/extensions
import enable from '../src/enable.js';
import displayImage from '../src/displayImage.js';
import draw from '../src/draw.js';
import disable from '../src/disable.js';
describe('draw', function () {
beforeEach(function () {
// Arrange
this.element = document.createElement('div');
const height = 2;
const width = 2;
const getPixelData = () => new Uint8Array([0, 255, 255, 0]);
this.image = {
imageId: 'exampleImageId',
minPixelValue: 0,
maxPixelValue: 255,
slope: 1.0,
intercept: 0,
windowCenter: 127,
windowWidth: 256,
getPixelData,
rows: height,
columns: width,
height,
width,
color: false,
sizeInBytes: width * height * 2
};
enable(this.element);
});
it('should throw an error if no image is displayed in the enabled element', function () {
// Act
assert.throws(() => draw(this.element));
});
it('should draw immediately', function (done) {
// Arrange
const element = this.element;
const image = this.image;
displayImage(this.element, this.image);
element.addEventListener('cornerstoneimagerendered', function (event) {
// Assert
assert.equal(event.target, element);
assert.equal(event.detail.image, image);
done();
});
// Act
draw(this.element);
});
it('should draw 300x150 images too (issue #300)', function (done) {
// Arrange
const element = this.element;
const image = this.image;
image.width = 300;
image.height = 150;
image.getPixelData = () => new Uint8Array(300*150);
displayImage(this.element, this.image);
element.addEventListener('cornerstoneimagerendered', function (event) {
// Assert
assert.equal(event.target, element);
assert.equal(event.detail.image, image);
done();
});
// Act
draw(this.element);
});
afterEach(function () {
disable(this.element);
});
});