summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/components/test/mochitest/test_reps_number.html
blob: 50f91d8b096c301426a6f0686530c9f32bcfe937 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<!DOCTYPE HTML>
<html>
<!--
Test Number rep
-->
<head>
  <meta charset="utf-8">
  <title>Rep test - Number</title>
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
</head>
<body>
<pre id="test">
<script src="head.js" type="application/javascript;version=1.8"></script>
<script type="application/javascript;version=1.8">
window.onload = Task.async(function* () {
  let { Rep } = browserRequire("devtools/client/shared/components/reps/rep");
  let { Number } = browserRequire("devtools/client/shared/components/reps/number");

  try {
    yield testInt();
    yield testBoolean();
    yield testNegativeZero();
    yield testUnsafeInt();
  } catch(e) {
    ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
  } finally {
    SimpleTest.finish();
  }


  function testInt() {
    const renderedRep = shallowRenderComponent(Rep, { object: getGripStub("testInt") });
    is(renderedRep.type, Number.rep, `Rep correctly selects ${Number.rep.displayName} for integer value`);

    const renderedComponent = renderComponent(Number.rep, { object: getGripStub("testInt") });
    is(renderedComponent.textContent, "5", "Number rep has expected text content for integer");
  }

  function testBoolean() {
    const renderedRep = shallowRenderComponent(Rep, { object: getGripStub("testTrue") });
    is(renderedRep.type, Number.rep, `Rep correctly selects ${Number.rep.displayName} for boolean value`);

    let renderedComponent = renderComponent(Number.rep, { object: getGripStub("testTrue") });
    is(renderedComponent.textContent, "true", "Number rep has expected text content for boolean true");

    renderedComponent = renderComponent(Number.rep, { object: getGripStub("testFalse") });
    is(renderedComponent.textContent, "false", "Number rep has expected text content for boolean false");
  }

  function testNegativeZero() {
    const renderedRep = shallowRenderComponent(Rep, { object: getGripStub("testNegZeroGrip") });
    is(renderedRep.type, Number.rep, `Rep correctly selects ${Number.rep.displayName} for negative zero value`);

    let renderedComponent = renderComponent(Number.rep, { object: getGripStub("testNegZeroGrip") });
    is(renderedComponent.textContent, "-0", "Number rep has expected text content for negative zero grip");

    renderedComponent = renderComponent(Number.rep, { object: getGripStub("testNegZeroValue") });
    is(renderedComponent.textContent, "-0", "Number rep has expected text content for negative zero value");
  }

  function testUnsafeInt() {
    const renderedComponent = renderComponent(Number.rep, { object: getGripStub("testUnsafeInt") });
    is(renderedComponent.textContent, "900719925474099100", "Number rep has expected text content for a long number");
  }

  function getGripStub(name) {
    switch (name) {
      case "testInt":
        return 5;

      case "testTrue":
        return true;

      case "testFalse":
        return false;

      case "testNegZeroValue":
        return -0;

      case "testNegZeroGrip":
        return {
          "type": "-0"
        };

      case "testUnsafeInt":
        return 900719925474099122;
    }
  }
});
</script>
</pre>
</body>
</html>