Advertisement
Guest User

Untitled

a guest
Jun 13th, 2014
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 2.73 KB | None | 0 0
  1. package com.greencatsoft.igs.chart
  2.  
  3. import scala.scalajs.js.Any.{ fromBoolean, fromFunction0 }
  4.  
  5. import org.scalajs.jquery.jQuery
  6.  
  7. import com.greencatsoft.igs.NameSpaces.NamespaceChart
  8. import com.greencatsoft.igs.StyleClasses.{ ClassDesignTime, ClassHide }
  9. import com.greencatsoft.igs.any2JsAny
  10. import com.greencatsoft.igs.chart.StyleClasses.ClassLabel
  11. import com.greencatsoft.igs.datasource.BasicDataSource
  12. import com.greencatsoft.igs.hasClass
  13.  
  14. object DialChartTest extends ChartTest {
  15.  
  16.   val minimal = s"""<?xml version="1.0" encoding="UTF-8" ?>
  17.         <svg xmlns="http://www.w3.org/2000/svg" xmlns:greencat="$NamespaceChart"
  18.             width="400px" height="400px">
  19.             <metadata>
  20.                 <greencat:chart type="dial" />
  21.             </metadata>
  22.             <rect x="0" y="0" width="400" height="400" fill="black" />
  23.             <circle cx="200" cy="200" r="200" fill="white" />
  24.             <rect x="199" y="100" width="2" height="100" fill="black" class="gc-plot">
  25.                 <circle cx="200" cy="200" r="10" fill="black" class="gc-axis" />
  26.                 <circle cx="200" cy="200" r="5" fill="red" class="gc-design" />
  27.             </rect>
  28.             <text x="180" y="300" class="gc-label">
  29.                 <tspan>100</tspan>
  30.             </text>
  31.         </svg>
  32.         """
  33.  
  34.  describe("Dial chart") {
  35.    it("can be constructed.") {
  36.      val chart = Chart(appendSvg("test", minimal), new BasicDataSource[Int])
  37.  
  38.      expect(chart.isInstanceOf[SingleDialChart[_]]) toBe true
  39.    }
  40.  
  41.    it("can be initialized.") {
  42.      val chart = Chart(appendSvg("test", minimal), new BasicDataSource[Int])
  43.  
  44.      expect(chart.isInitialized) toBe false
  45.  
  46.      expect(() => chart.initialize()).not.toThrow
  47.  
  48.      expect(chart.isInitialized) toBe true
  49.    }
  50.  
  51.    it("should hide design time elements after being initialized.") {
  52.      val node = appendSvg("test", minimal)
  53.  
  54.      val chart = Chart(node, new BasicDataSource[Int])
  55.  
  56.      expect(hasClass(jQuery(s".$ClassDesignTime", node), ClassHide)) toBe false
  57.  
  58.      chart.initialize()
  59.  
  60.      expect(hasClass(jQuery(s".$ClassDesignTime", node), ClassHide)) toBe true
  61.    }
  62.  
  63.    it("can be rendered.") {
  64.      val chart = Chart(appendSvg("test", minimal), new BasicDataSource[Int])
  65.      chart.initialize()
  66.  
  67.      expect(() => chart.render()).not.toThrow
  68.    }
  69.  
  70.    it("should change its label text according to the value.") {
  71.      val node = appendSvg("test", minimal)
  72.  
  73.      val dataSource = new BasicDataSource[Int]
  74.      val chart = Chart(appendSvg("test", minimal), dataSource)
  75. scalajs.js.Dynamic.global.console.log(scalajs.js.Dynamic.global.document.body.innerHTML)
  76.      expect(jQuery(s".$ClassLabel tspan", node).text) toBe "100"
  77.  
  78.      chart.initialize()
  79.      chart.render()
  80.  
  81.      dataSource.value = 30
  82.  
  83.      expect(jQuery(s".$ClassLabel tspan", node).text) toBe "30"
  84.    }
  85.  }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement