Bug 1264700 - [rep tests] Add tests for undefined rep. r=Honza

This commit is contained in:
Lin Clark 2016-05-02 10:02:00 +02:00
Родитель 5a37523e25
Коммит 01bbefc9c1
3 изменённых файлов: 68 добавлений и 0 удалений

Просмотреть файл

@ -3,6 +3,7 @@ support-files =
head.js
[test_HSplitBox_01.html]
[test_reps_undefined.html]
[test_frame_01.html]
[test_tree_01.html]
[test_tree_02.html]

Просмотреть файл

@ -24,6 +24,10 @@ var { require: browserRequire } = BrowserLoader({
window: this
});
let ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom");
let React = browserRequire("devtools/client/shared/vendor/react");
var TestUtils = React.addons.TestUtils;
var EXAMPLE_URL = "http://example.com/browser/browser/devtools/shared/test/";
function forceRender(comp) {
@ -164,3 +168,20 @@ function checkFrameString({ frame, file, line, column, shouldLink, tooltip }) {
ok(!$column, "Should not have an element for `column`");
}
}
function renderComponent(component, props) {
const el = React.createElement(component, props, {});
// By default, renderIntoDocument() won't work for stateless components, but
// it will work if the stateless component is wrapped in a stateful one.
// See https://github.com/facebook/react/issues/4839
const wrappedEl = React.DOM.span({}, [el]);
const renderedComponent = TestUtils.renderIntoDocument(wrappedEl);
return ReactDOM.findDOMNode(renderedComponent).children[0];
}
function shallowRenderComponent(component, props) {
const el = React.createElement(component, props);
const renderer = TestUtils.createRenderer();
renderer.render(el, {});
return renderer.getRenderOutput();
}

Просмотреть файл

@ -0,0 +1,46 @@
<!DOCTYPE HTML>
<html>
<!--
Test undefined rep
-->
<head>
<meta charset="utf-8">
<title>Rep test - undefined</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* () {
try {
let ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom");
let React = browserRequire("devtools/client/shared/vendor/react");
let { Rep } = browserRequire("devtools/client/shared/components/reps/rep");
let { Undefined } = browserRequire("devtools/client/shared/components/reps/undefined");
let gripStub = {
"type": "undefined"
};
// Test that correct rep is chosen
const renderedRep = shallowRenderComponent(Rep, { object: gripStub });
is(renderedRep.type, Undefined.rep, `Rep correctly selects ${Undefined.rep.displayName}`);
// Test rendering
const renderedComponent = renderComponent(Undefined.rep, {});
is(renderedComponent.className, "objectBox objectBox-undefined", "Undefined rep has expected class names");
is(renderedComponent.getAttribute("role"), "presentation", "Undefined rep has expected aria role");
is(renderedComponent.textContent, "undefined", "Undefined rep has expected text content");
} catch(e) {
ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
} finally {
SimpleTest.finish();
}
});
</script>
</pre>
</body>
</html>