[29468] | 1 | <!DOCTYPE html>
|
---|
| 2 | <html>
|
---|
| 3 | <head>
|
---|
| 4 | <link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
|
---|
| 5 | <script src='../editor/lib/jquery.js'></script>
|
---|
| 6 | <script type='text/javascript' src='../editor/src/browser.js'></script>
|
---|
| 7 | <script type='text/javascript' src='../editor/src/math.js'></script>
|
---|
| 8 | <script type='text/javascript' src='../editor/src/svgutils.js'></script>
|
---|
| 9 | <script type='text/javascript' src='../editor/src/select.js'></script>
|
---|
| 10 | <script type='text/javascript' src='qunit/qunit.js'></script>
|
---|
| 11 | <script type='text/javascript'>
|
---|
| 12 | $(function() {
|
---|
| 13 | // log function
|
---|
| 14 | QUnit.log = function(result, message) {
|
---|
| 15 | if (window.console && window.console.log) {
|
---|
| 16 | window.console.log(result +' :: '+ message);
|
---|
| 17 | }
|
---|
| 18 | };
|
---|
| 19 |
|
---|
| 20 | module('svgedit.select');
|
---|
| 21 |
|
---|
| 22 | var svgns = 'http://www.w3.org/2000/svg';
|
---|
| 23 | var sandbox = document.getElementById('sandbox');
|
---|
| 24 | var svgroot;
|
---|
| 25 | var svgcontent;
|
---|
| 26 | var rect;
|
---|
| 27 | var mockConfig = {
|
---|
| 28 | dimensions: [640,480]
|
---|
| 29 | };
|
---|
| 30 | var mockFactory = {
|
---|
| 31 | createSVGElement: function(jsonMap) {
|
---|
| 32 | var elem = document.createElementNS(svgns, jsonMap['element']);
|
---|
| 33 | for (var attr in jsonMap['attr']) {
|
---|
| 34 | elem.setAttribute(attr, jsonMap['attr'][attr]);
|
---|
| 35 | }
|
---|
| 36 | return elem;
|
---|
| 37 | },
|
---|
| 38 | svgRoot: function() { return svgroot; },
|
---|
| 39 | svgContent: function() { return svgcontent; }
|
---|
| 40 | };
|
---|
| 41 |
|
---|
| 42 | function setUp() {
|
---|
| 43 | svgroot = mockFactory.createSVGElement({
|
---|
| 44 | 'element': 'svg',
|
---|
| 45 | 'attr': {'id': 'svgroot'}
|
---|
| 46 | });
|
---|
| 47 | svgcontent = svgroot.appendChild(
|
---|
| 48 | mockFactory.createSVGElement({
|
---|
| 49 | 'element': 'svg',
|
---|
| 50 | 'attr': {'id': 'svgcontent'}
|
---|
| 51 | })
|
---|
| 52 | );
|
---|
| 53 | rect = svgcontent.appendChild(
|
---|
| 54 | mockFactory.createSVGElement({
|
---|
| 55 | 'element': 'rect',
|
---|
| 56 | 'attr': {
|
---|
| 57 | 'id': 'rect',
|
---|
| 58 | 'x': '50',
|
---|
| 59 | 'y': '75',
|
---|
| 60 | 'width': '200',
|
---|
| 61 | 'height': '100'
|
---|
| 62 | }
|
---|
| 63 | })
|
---|
| 64 | );
|
---|
| 65 | sandbox.appendChild(svgroot);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | function setUpWithInit() {
|
---|
| 69 | setUp();
|
---|
| 70 | svgedit.select.init(mockConfig, mockFactory);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | function tearDown() {
|
---|
| 74 | while (sandbox.hasChildNodes()) {
|
---|
| 75 | sandbox.removeChild(sandbox.firstChild);
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | test('Test svgedit.select package', function() {
|
---|
| 80 | expect(10);
|
---|
| 81 |
|
---|
| 82 | ok(svgedit.select);
|
---|
| 83 | ok(svgedit.select.Selector);
|
---|
| 84 | ok(svgedit.select.SelectorManager);
|
---|
| 85 | ok(svgedit.select.init);
|
---|
| 86 | ok(svgedit.select.getSelectorManager);
|
---|
| 87 | equals(typeof svgedit.select, typeof {});
|
---|
| 88 | equals(typeof svgedit.select.Selector, typeof function(){});
|
---|
| 89 | equals(typeof svgedit.select.SelectorManager, typeof function(){});
|
---|
| 90 | equals(typeof svgedit.select.init, typeof function(){});
|
---|
| 91 | equals(typeof svgedit.select.getSelectorManager, typeof function(){});
|
---|
| 92 | });
|
---|
| 93 |
|
---|
| 94 | test('Test Selector DOM structure', function() {
|
---|
| 95 | expect(26);
|
---|
| 96 |
|
---|
| 97 | setUp();
|
---|
| 98 |
|
---|
| 99 | ok(svgroot);
|
---|
| 100 | ok(svgroot.hasChildNodes());
|
---|
| 101 |
|
---|
| 102 | // Verify non-existence of Selector DOM nodes
|
---|
| 103 | equals(svgroot.childNodes.length, 1);
|
---|
| 104 | equals(svgroot.childNodes.item(0), svgcontent);
|
---|
| 105 | ok(!svgroot.querySelector('#selectorParentGroup'));
|
---|
| 106 |
|
---|
| 107 | svgedit.select.init(mockConfig, mockFactory);
|
---|
| 108 |
|
---|
| 109 | equals(svgroot.childNodes.length, 3);
|
---|
| 110 |
|
---|
| 111 | // Verify existence of canvas background.
|
---|
| 112 | var cb = svgroot.childNodes.item(0);
|
---|
| 113 | ok(cb);
|
---|
| 114 | equals(cb.id, 'canvasBackground');
|
---|
| 115 |
|
---|
| 116 | ok(svgroot.childNodes.item(1));
|
---|
| 117 | equals(svgroot.childNodes.item(1), svgcontent);
|
---|
| 118 |
|
---|
| 119 | // Verify existence of selectorParentGroup.
|
---|
| 120 | var spg = svgroot.childNodes.item(2);
|
---|
| 121 | ok(spg);
|
---|
| 122 | equals(svgroot.querySelector('#selectorParentGroup'), spg);
|
---|
| 123 | equals(spg.id, 'selectorParentGroup');
|
---|
| 124 | equals(spg.tagName, 'g');
|
---|
| 125 |
|
---|
| 126 | // Verify existence of all grip elements.
|
---|
| 127 | ok(spg.querySelector('#selectorGrip_resize_nw'));
|
---|
| 128 | ok(spg.querySelector('#selectorGrip_resize_n'));
|
---|
| 129 | ok(spg.querySelector('#selectorGrip_resize_ne'));
|
---|
| 130 | ok(spg.querySelector('#selectorGrip_resize_e'));
|
---|
| 131 | ok(spg.querySelector('#selectorGrip_resize_se'));
|
---|
| 132 | ok(spg.querySelector('#selectorGrip_resize_s'));
|
---|
| 133 | ok(spg.querySelector('#selectorGrip_resize_sw'));
|
---|
| 134 | ok(spg.querySelector('#selectorGrip_resize_w'));
|
---|
| 135 | ok(spg.querySelector('#selectorGrip_rotate_sw'));
|
---|
| 136 | ok(spg.querySelector('#selectorGrip_rotate_se'));
|
---|
| 137 | ok(spg.querySelector('#selectorGrip_rotate_nw'));
|
---|
| 138 | ok(spg.querySelector('#selectorGrip_rotate_ne'));
|
---|
| 139 |
|
---|
| 140 | tearDown();
|
---|
| 141 | });
|
---|
| 142 |
|
---|
| 143 | });
|
---|
| 144 | </script>
|
---|
| 145 | </head>
|
---|
| 146 | <body>
|
---|
| 147 | <h1 id='qunit-header'>Unit Tests for select.js</h1>
|
---|
| 148 | <h2 id='qunit-banner'></h2>
|
---|
| 149 | <h2 id='qunit-userAgent'></h2>
|
---|
| 150 | <ol id='qunit-tests'>
|
---|
| 151 | </ol>
|
---|
| 152 | <div id='sandbox'></div>
|
---|
| 153 | </body>
|
---|
| 154 | </html>
|
---|