forked from cornerstonejs/cornerstone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimageLoader_test.js
More file actions
118 lines (88 loc) · 3.64 KB
/
Copy pathimageLoader_test.js
File metadata and controls
118 lines (88 loc) · 3.64 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* eslint-disable no-unused-expressions */
import { assert } from 'chai'; // eslint-disable-line import/extensions
import { registerImageLoader,
registerUnknownImageLoader,
loadImage,
loadAndCacheImage
} from '../src/index'; // eslint-disable-line import/extensions
describe('imageLoader registration module', function () {
beforeEach(function () {
this.exampleImageLoader1 = (imageId, options) => {
console.log('loading via exampleImageLoader1');
console.log(options);
return {
promise: new Promise(() => {}),
cancelFn: undefined
};
};
this.exampleImageLoader2 = (imageId, options) => {
console.log('loading via exampleImageLoader2');
console.log(options);
return {
promise: new Promise(() => {}),
cancelFn: undefined
};
};
this.exampleScheme1 = 'example1';
this.exampleScheme2 = 'example2';
this.exampleScheme1ImageId = `${this.exampleScheme1}://image1`;
this.exampleScheme2ImageId = `${this.exampleScheme2}://image2`;
this.options = {};
});
it('allows registration of new image loader', function () {
registerImageLoader(this.exampleScheme1, this.exampleImageLoader1);
registerImageLoader(this.exampleScheme2, this.exampleImageLoader2);
const imagePromise1 = loadImage(this.exampleScheme1ImageId, this.options);
assert.isDefined(imagePromise1);
const imagePromise2 = loadImage(this.exampleScheme2ImageId, this.options);
assert.isDefined(imagePromise2);
});
it('allows registration of unknown image loader', function () {
let oldUnknownImageLoader = registerUnknownImageLoader(this.exampleImageLoader1);
assert.isUndefined(oldUnknownImageLoader);
// Check that it returns the old value for the unknown image loader
oldUnknownImageLoader = registerUnknownImageLoader(this.exampleImageLoader1);
assert.equal(oldUnknownImageLoader, this.exampleImageLoader1);
});
});
describe('imageLoader loading module', function () {
beforeEach(function () {
this.exampleImageLoader1 = (imageId, options) => {
console.log('loading via exampleImageLoader1');
console.log(options);
return {
promise: new Promise(() => {}),
cancelFn: undefined
};
};
this.exampleImageLoader2 = (imageId, options) => {
console.log('loading via exampleImageLoader2');
console.log(options);
return {
promise: new Promise(() => {}),
cancelFn: undefined
};
};
this.exampleScheme1 = 'example1';
this.exampleScheme2 = 'example2';
this.exampleScheme1ImageId = `${this.exampleScheme1}://image1`;
this.exampleScheme2ImageId = `${this.exampleScheme2}://image2`;
this.options = {};
});
it('allows loading with storage in image cache (loadImage)', function () {
registerImageLoader(this.exampleScheme1, this.exampleImageLoader1);
const imageLoadObject1 = loadAndCacheImage(this.exampleScheme1ImageId, this.options);
assert.isDefined(imageLoadObject1);
});
it('allows loading without storage in image cache (loadAndCacheImage)', function () {
registerImageLoader(this.exampleScheme1, this.exampleImageLoader1);
const imageLoadObject1 = loadImage(this.exampleScheme1ImageId, this.options);
assert.isDefined(imageLoadObject1);
});
it('falls back to the unknownImageLoader if no appropriate scheme is present', function () {
registerImageLoader(this.exampleScheme1, this.exampleImageLoader1);
registerUnknownImageLoader(this.exampleScheme2, this.exampleImageLoader2);
const imageLoadObject1 = loadAndCacheImage(this.exampleScheme2ImageId, this.options);
assert.isDefined(imageLoadObject1);
});
});