UNPKG

3.38 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2017 Mozilla Foundation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * @licend The above is the entire license notice for the
20 * Javascript code in this page
21 */
22'use strict';
23
24var _dom_utils = require('../../display/dom_utils');
25
26var _is_node = require('../../shared/is_node');
27
28var _is_node2 = _interopRequireDefault(_is_node);
29
30function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
32describe('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