summaryrefslogtreecommitdiffstats
path: root/debian/missing-sources/epoch/tests/unit/init.coffee
blob: aa8edd2cf961d82076765a8fb1c6eb36d8285ade (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
process.env.TZ = "America/Los_Angeles"

jsdom = require('jsdom')
global.assert = require('chai').assert
url = require('url')

html = "<html><head></head><body></body></html>"

exec = require('child_process').exec
exec 'pwd', (err, out) -> console.log out

before (done) ->
  jsdom.env
    html: html
    scripts: ["http://d3js.org/d3.v3.min.js", "./dist/js/epoch.js"]
    done: (errors, window) ->
      global.Epoch = window.Epoch
      # Override get context to use a test context by default
      global.Epoch.Util.getContext = -> new window.Epoch.TestContext()
      global.d3 = window.d3
      global.doc = window.document
      # Set this to "retina" so we can test canvas based charts
      window.devicePixelRatio = 2
      done()

global.addStyleSheet = (css) ->
  head = doc.head
  style = doc.createElement('style')
  style.type = 'text/css'
  style.appendChild(doc.createTextNode(css))
  head.appendChild(style)
  style

global.layerWithRange = (min, max, range) ->
  layer = { values: [{time: 0, y: min}, {time: 1, y: max}] }
  layer.range = range if range?
  layer

#
# Helper assertion methods for data format testing
#
assert.data = (expected, result, checkAttributes) ->
  checkAttributes ?= ['x', 'y']
  assert.equal expected.length, result.length
  for i, layer of expected
    resultLayer = result[i]
    msg = "Result layer #{i} does not have expected number of values."
    assert.equal layer.values.length, resultLayer.values.length, msg
    for j in [0...layer.values.length]
      for k in checkAttributes
        msg = "Layer #{i} data point #{j} does not have the expected value for key #{k}"
        assert.equal layer.values[j][k], resultLayer.values[j][k], msg

assert.timeData = (expected, result) ->
  assert.data(expected, result, ['time', 'y'])