Bug 1264683 - [rep tests] Add tests for function rep. r=Honza

This commit is contained in:
Lin Clark 2016-06-29 07:07:00 +02:00
parent 5b0915aa18
commit dadbb21b58
4 changed files with 194 additions and 18 deletions

View File

@ -8,6 +8,7 @@ support-files =
[test_notification_box_03.html]
[test_reps_attribute.html]
[test_reps_date-time.html]
[test_reps_function.html]
[test_reps_grip.html]
[test_reps_object-with-url.html]
[test_reps_stylesheet.html]

View File

@ -188,3 +188,18 @@ function shallowRenderComponent(component, props) {
renderer.render(el, {});
return renderer.getRenderOutput();
}
/**
* Test that a rep renders correctly across different modes.
*/
function testRepRenderModes(modeTests, testName, componentUnderTest, gripStub) {
modeTests.forEach(({mode, expectedOutput, message}) => {
const modeString = typeof mode === "undefined" ? "no mode" : mode;
if (!message) {
message = `${testName}: ${modeString} renders correctly.`;
}
const rendered = renderComponent(componentUnderTest.rep, { object: gripStub, mode });
is(rendered.textContent, expectedOutput, message);
});
}

View File

@ -0,0 +1,171 @@
<!DOCTYPE HTML>
<html>
<!--
Test Func rep
-->
<head>
<meta charset="utf-8">
<title>Rep test - Func</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 { Func } = browserRequire("devtools/client/shared/components/reps/function");
const componentUnderTest = Func;
try {
// Test that correct rep is chosen
const gripStub = getGripStub("testNamed");
const renderedRep = shallowRenderComponent(Rep, { object: gripStub });
is(renderedRep.type, Func.rep, `Rep correctly selects ${Func.rep.displayName}`);
yield testNamed();
yield testVarNamed();
yield testAnon();
yield testLongName();
} catch(e) {
ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
} finally {
SimpleTest.finish();
}
function testNamed() {
// Test declaration: `function testName{ let innerVar = "foo" }`
const testName = "testNamed";
const defaultOutput = `testName()`;
const modeTests = [
{
mode: undefined,
expectedOutput: defaultOutput,
}
];
testRepRenderModes(modeTests, testName, componentUnderTest, getGripStub(testName));
}
function testVarNamed() {
// Test declaration: `let testVarName = function() { }`
const testName = "testVarNamed";
const defaultOutput = `testVarName()`;
const modeTests = [
{
mode: undefined,
expectedOutput: defaultOutput,
}
];
testRepRenderModes(modeTests, testName, componentUnderTest, getGripStub(testName));
}
function testAnon() {
// Test declaration: `() => {}`
const testName = "testAnon";
const defaultOutput = `function()`;
const modeTests = [
{
mode: undefined,
expectedOutput: defaultOutput,
}
];
testRepRenderModes(modeTests, testName, componentUnderTest, getGripStub(testName));
}
function testLongName() {
// Test declaration: `let f = function loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong() { }`
const testName = "testLongName";
const defaultOutput = `looooooooooooooooooooooooooooooooooooooooooooooooo\u2026ooooooooooooooooooooooooooooooooooooooooooooong()`;
const modeTests = [
{
mode: undefined,
expectedOutput: defaultOutput,
}
];
testRepRenderModes(modeTests, testName, componentUnderTest, getGripStub(testName));
}
function getGripStub(functionName) {
switch (functionName) {
case "testNamed":
return {
"type": "object",
"class": "Function",
"actor": "server1.conn6.obj35",
"extensible": true,
"frozen": false,
"sealed": false,
"name": "testName",
"displayName": "testName",
"location": {
"url": "debugger eval code",
"line": 1
}
};
case "testVarNamed":
return {
"type": "object",
"class": "Function",
"actor": "server1.conn7.obj41",
"extensible": true,
"frozen": false,
"sealed": false,
"displayName": "testVarName",
"location": {
"url": "debugger eval code",
"line": 1
}
};
case "testAnon":
return {
"type": "object",
"class": "Function",
"actor": "server1.conn7.obj45",
"extensible": true,
"frozen": false,
"sealed": false,
"location": {
"url": "debugger eval code",
"line": 1
}
};
case "testLongName":
return {
"type": "object",
"class": "Function",
"actor": "server1.conn7.obj67",
"extensible": true,
"frozen": false,
"sealed": false,
"name": "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
"displayName": "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
"location": {
"url": "debugger eval code",
"line": 1
}
};
}
}
});
</script>
</pre>
</body>
</html>

View File

@ -18,6 +18,8 @@ window.onload = Task.async(function* () {
let { Rep } = browserRequire("devtools/client/shared/components/reps/rep");
let { Grip } = browserRequire("devtools/client/shared/components/reps/grip");
const componentUnderTest = Grip;
try {
yield testBasic();
@ -66,7 +68,7 @@ window.onload = Task.async(function* () {
}
];
testRenderingInMode(modeTests, testName);
testRepRenderModes(modeTests, testName, componentUnderTest, getGripStub(testName));
}
function testMaxProps() {
@ -94,7 +96,7 @@ window.onload = Task.async(function* () {
}
];
testRenderingInMode(modeTests, testName);
testRepRenderModes(modeTests, testName, componentUnderTest, getGripStub(testName));
}
function testMoreThanMaxProps() {
@ -131,7 +133,7 @@ window.onload = Task.async(function* () {
}
];
testRenderingInMode(modeTests, testName);
testRepRenderModes(modeTests, testName, componentUnderTest, getGripStub(testName));
}
function testUninterestingProps() {
@ -166,7 +168,7 @@ window.onload = Task.async(function* () {
}
];
testRenderingInMode(modeTests, testName);
testRepRenderModes(modeTests, testName, componentUnderTest, getGripStub(testName));
}
function testNestedArray() {
@ -194,20 +196,7 @@ window.onload = Task.async(function* () {
}
];
testRenderingInMode(modeTests, testName);
}
function testRenderingInMode(modeTests, testName) {
modeTests.forEach(({mode, expectedOutput, message}) => {
const modeString = typeof mode === "undefined" ? "no mode" : mode;
if (!message) {
message = `${testName}: ${modeString} renders correctly.`
}
const gripStub = getGripStub(testName);
const rendered = renderComponent(Grip.rep, { object: gripStub, mode });
is(rendered.textContent, expectedOutput, message);
});
testRepRenderModes(modeTests, testName, componentUnderTest, getGripStub(testName));
}
function getGripStub(functionName) {