1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | 'use strict';
|
23 |
|
24 | var _dom_utils = require('../../display/dom_utils');
|
25 |
|
26 | var _is_node = require('../../shared/is_node');
|
27 |
|
28 | var _is_node2 = _interopRequireDefault(_is_node);
|
29 |
|
30 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
31 |
|
32 | describe('dom_utils', function () {
|
33 | describe('DOMSVGFactory', function () {
|
34 | var svgFactory = void 0;
|
35 | beforeAll(function (done) {
|
36 | svgFactory = new _dom_utils.DOMSVGFactory();
|
37 | done();
|
38 | });
|
39 | afterAll(function () {
|
40 | svgFactory = null;
|
41 | });
|
42 | it('`create` should throw an error if the dimensions are invalid', function () {
|
43 | expect(function () {
|
44 | return svgFactory.create(-1, 0);
|
45 | }).toThrow(new Error('Invalid SVG dimensions'));
|
46 | expect(function () {
|
47 | return svgFactory.create(0, -1);
|
48 | }).toThrow(new Error('Invalid SVG dimensions'));
|
49 | });
|
50 | it('`create` should return an SVG element if the dimensions are valid', function () {
|
51 | if ((0, _is_node2.default)()) {
|
52 | pending('Document is not supported in Node.js.');
|
53 | }
|
54 | var svg = svgFactory.create(20, 40);
|
55 | expect(svg instanceof SVGSVGElement).toBe(true);
|
56 | expect(svg.getAttribute('version')).toBe('1.1');
|
57 | expect(svg.getAttribute('width')).toBe('20px');
|
58 | expect(svg.getAttribute('height')).toBe('40px');
|
59 | expect(svg.getAttribute('preserveAspectRatio')).toBe('none');
|
60 | expect(svg.getAttribute('viewBox')).toBe('0 0 20 40');
|
61 | });
|
62 | it('`createElement` should throw an error if the type is not a string', function () {
|
63 | expect(function () {
|
64 | return svgFactory.createElement(true);
|
65 | }).toThrow(new Error('Invalid SVG element type'));
|
66 | });
|
67 | it('`createElement` should return an SVG element if the type is valid', function () {
|
68 | if ((0, _is_node2.default)()) {
|
69 | pending('Document is not supported in Node.js.');
|
70 | }
|
71 | var svg = svgFactory.createElement('svg:rect');
|
72 | expect(svg instanceof SVGRectElement).toBe(true);
|
73 | });
|
74 | });
|
75 | describe('getFilenameFromUrl', function () {
|
76 | it('should get the filename from an absolute URL', function () {
|
77 | var url = 'http://server.org/filename.pdf';
|
78 | var result = (0, _dom_utils.getFilenameFromUrl)(url);
|
79 | var expected = 'filename.pdf';
|
80 | expect(result).toEqual(expected);
|
81 | });
|
82 | it('should get the filename from a relative URL', function () {
|
83 | var url = '../../filename.pdf';
|
84 | var result = (0, _dom_utils.getFilenameFromUrl)(url);
|
85 | var expected = 'filename.pdf';
|
86 | expect(result).toEqual(expected);
|
87 | });
|
88 | });
|
89 | }); |
\ | No newline at end of file |