Bug 1286700 - Reps: Fix function import in text-node.js . r=Honza
Import `cropMultipleLines` function from the correct file.
Add a test for the TextNode Rep.
MozReview-Commit-ID: 8dk1EHgkKwK
--- a/devtools/client/shared/components/reps/text-node.js
+++ b/devtools/client/shared/components/reps/text-node.js
@@ -6,19 +6,18 @@
"use strict";
// Make this available to both AMD and CJS environments
define(function (require, exports, module) {
// ReactJS
const React = require("devtools/client/shared/vendor/react");
// Reps
- const { createFactories, isGrip } = require("./rep-utils");
+ const { createFactories, isGrip, cropMultipleLines } = require("./rep-utils");
const { ObjectBox } = createFactories(require("./object-box"));
- const { cropMultipleLines } = require("./string");
// Shortcuts
const DOM = React.DOM;
/**
* Renders DOM #text node.
*/
let TextNode = React.createClass({
--- a/devtools/client/shared/components/test/mochitest/chrome.ini
+++ b/devtools/client/shared/components/test/mochitest/chrome.ini
@@ -15,16 +15,17 @@ support-files =
[test_reps_grip-array.html]
[test_reps_null.html]
[test_reps_number.html]
[test_reps_object.html]
[test_reps_object-with-text.html]
[test_reps_object-with-url.html]
[test_reps_string.html]
[test_reps_stylesheet.html]
+[test_reps_text-node.html]
[test_reps_undefined.html]
[test_reps_window.html]
[test_sidebar_toggle.html]
[test_tree_01.html]
[test_tree_02.html]
[test_tree_03.html]
[test_tree_04.html]
[test_tree_05.html]
new file mode 100644
--- /dev/null
+++ b/devtools/client/shared/components/test/mochitest/test_reps_text-node.html
@@ -0,0 +1,60 @@
+
+<!DOCTYPE HTML>
+<html>
+<!--
+Test text-node rep
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Rep test - text-node</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">
+"use strict";
+
+window.onload = Task.async(function* () {
+ try {
+ let { Rep } = browserRequire("devtools/client/shared/components/reps/rep");
+ let { TextNode } = browserRequire("devtools/client/shared/components/reps/text-node");
+
+ let gripStub = {
+ "type": "object",
+ "class": "Text",
+ "actor": "server1.conn1.child1/obj50",
+ "extensible": true,
+ "frozen": false,
+ "sealed": false,
+ "ownPropertyLength": 0,
+ "preview": {
+ "kind": "DOMNode",
+ "nodeType": 3,
+ "nodeName": "#text",
+ "textContent": "hello world"
+ }
+ };
+
+ // Test that correct rep is chosen
+ const renderedRep = shallowRenderComponent(Rep, { object: gripStub });
+ is(renderedRep.type, TextNode.rep,
+ `Rep correctly selects ${TextNode.rep.displayName}`);
+
+ // Test rendering
+ const renderedComponent = renderComponent(TextNode.rep, { object: gripStub });
+ is(renderedComponent.className, "objectBox objectBox-textNode",
+ "TextNode rep has expected class names");
+ is(renderedComponent.textContent, `"hello world"`,
+ "TextNode rep has expected text content");
+ } catch (e) {
+ ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
+ } finally {
+ SimpleTest.finish();
+ }
+});
+</script>
+</pre>
+</body>
+</html>