-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbase.d3.spec.ts
51 lines (44 loc) · 1.39 KB
/
base.d3.spec.ts
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
import { BaseD3, RenderOptions } from './base.d3';
import { ElementRef } from '@angular/core';
describe('BaseD3', () => {
// since BaseD3 is an abstract class, make a concrete child class
class TestBaseD3 extends BaseD3<RenderOptions> {
}
let containerElement: HTMLElement;
let svgElement: HTMLElement;
let renderOptions: RenderOptions;
let baseD3: TestBaseD3;
beforeEach(() => {
containerElement = document.createElement('div');
svgElement = document.createElement('svg');
containerElement.appendChild(svgElement);
renderOptions = {
elementRef: new ElementRef<HTMLElement>(containerElement),
width: 256,
height: 256,
};
baseD3 = new TestBaseD3(renderOptions);
});
afterEach(() => {
svgElement.remove();
containerElement.remove();
baseD3.clear();
});
it('should instantiate.', () => {
expect(baseD3).toBeInstanceOf(BaseD3);
});
it('should render on the svg element.', async () => {
baseD3.render();
const viewBox = svgElement.getAttribute('viewBox');
expect(viewBox).toBe(`0 0 ${renderOptions.width} ${renderOptions.height}`);
});
it('should change the config.', () => {
const newWidth = 128;
baseD3.config({
...renderOptions,
width: newWidth,
}).render();
const viewBox = svgElement.getAttribute('viewBox');
expect(viewBox).toBe(`0 0 ${newWidth} ${renderOptions.height}`);
});
});