| | 455 | function test_Elements_drawAndErase(t) { |
|---|
| | 456 | t.plan(20); |
|---|
| | 457 | |
|---|
| | 458 | setUp(); |
|---|
| | 459 | |
|---|
| | 460 | var r = create_renderer(); |
|---|
| | 461 | var element = document.createElement("div"); |
|---|
| | 462 | r.root = element; |
|---|
| | 463 | document.body.appendChild(element); |
|---|
| | 464 | |
|---|
| | 465 | r.createNode = function(type, id) { |
|---|
| | 466 | var element = document.createElement("div"); |
|---|
| | 467 | element.id = id; |
|---|
| | 468 | return element; |
|---|
| | 469 | }; |
|---|
| | 470 | r.setStyle = function(node, style, options, geometry) { |
|---|
| | 471 | return node; |
|---|
| | 472 | }; |
|---|
| | 473 | |
|---|
| | 474 | var geometry = { |
|---|
| | 475 | id: 'foo', |
|---|
| | 476 | CLASS_NAME: 'bar' |
|---|
| | 477 | }; |
|---|
| | 478 | var style = { |
|---|
| | 479 | graphicZIndex: 10 |
|---|
| | 480 | }; |
|---|
| | 481 | var featureId = 'foo'; |
|---|
| | 482 | r.drawGeometry(geometry, style, featureId); |
|---|
| | 483 | |
|---|
| | 484 | function count(obj) { |
|---|
| | 485 | var result = 0; |
|---|
| | 486 | for (var i in obj) { |
|---|
| | 487 | result++; |
|---|
| | 488 | } |
|---|
| | 489 | return result; |
|---|
| | 490 | } |
|---|
| | 491 | |
|---|
| | 492 | t.ok(r.root.childNodes.length == 1, "root is correctly filled"); |
|---|
| | 493 | t.ok(r.indexer.maxZIndex == 10, "indexer.maxZIndex is correctly filled"); |
|---|
| | 494 | t.ok(r.indexer.order.length == 1, "indexer.order is correctly filled"); |
|---|
| | 495 | t.ok(count(r.indexer.indices) == 1, "indexer.indices is correctly filled"); |
|---|
| | 496 | |
|---|
| | 497 | r.eraseGeometry(geometry); |
|---|
| | 498 | |
|---|
| | 499 | t.ok(r.root.childNodes.length == 0, "root is correctly cleared"); |
|---|
| | 500 | t.ok(r.indexer.maxZIndex == 0, "indexer.maxZIndex is correctly reset"); |
|---|
| | 501 | t.ok(r.indexer.order.length == 0, "indexer.order is correctly reset"); |
|---|
| | 502 | t.ok(count(r.indexer.indices) == 0, "indexer.indices is correctly reset"); |
|---|
| | 503 | |
|---|
| | 504 | delete(style.graphicZIndex); |
|---|
| | 505 | r.drawGeometry(geometry, style, featureId); |
|---|
| | 506 | |
|---|
| | 507 | t.ok(r.root.childNodes.length == 1, "root is correctly filled"); |
|---|
| | 508 | t.ok(r.indexer.maxZIndex == 0, "indexer.maxZIndex is correctly filled"); |
|---|
| | 509 | t.ok(r.indexer.order.length == 1, "indexer.order is correctly filled"); |
|---|
| | 510 | t.ok(count(r.indexer.indices) == 1, "indexer.indices is correctly filled"); |
|---|
| | 511 | |
|---|
| | 512 | r.clear(); |
|---|
| | 513 | |
|---|
| | 514 | t.ok(r.root.childNodes.length == 0, "root is correctly cleared"); |
|---|
| | 515 | t.ok(r.indexer.maxZIndex == 0, "indexer.maxZIndex is correctly reset"); |
|---|
| | 516 | t.ok(r.indexer.order.length == 0, "indexer.order is correctly reset"); |
|---|
| | 517 | t.ok(count(r.indexer.indices) == 0, "indexer.indices is correctly reset"); |
|---|
| | 518 | |
|---|
| | 519 | style.graphicZIndex = 12; |
|---|
| | 520 | r.drawGeometry(geometry, style, featureId); |
|---|
| | 521 | |
|---|
| | 522 | t.ok(r.root.childNodes.length == 1, "root is correctly filled"); |
|---|
| | 523 | t.ok(r.indexer.maxZIndex == 12, "indexer.maxZIndex is correctly filled"); |
|---|
| | 524 | t.ok(r.indexer.order.length == 1, "indexer.order is correctly filled"); |
|---|
| | 525 | t.ok(count(r.indexer.indices) == 1, "indexer.indices is correctly filled"); |
|---|
| | 526 | |
|---|
| | 527 | tearDown(); |
|---|
| | 528 | } |
|---|
| | 529 | |
|---|
| | 530 | |
|---|