test_tree_07.html (2218B)
1 <!-- This Source Code Form is subject to the terms of the Mozilla Public 2 - License, v. 2.0. If a copy of the MPL was not distributed with this 3 - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 4 <!DOCTYPE HTML> 5 <html> 6 <!-- 7 Test that arrows get the open attribute when their item's children are expanded. 8 --> 9 <head> 10 <meta charset="utf-8"> 11 <title>Tree component test</title> 12 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 13 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 14 <link rel="stylesheet" href="chrome://devtools/skin/light-theme.css" type="text/css"> 15 </head> 16 <body> 17 <pre id="test"> 18 <script src="head.js" type="application/javascript"></script> 19 <script type="application/javascript"> 20 21 'use strict' 22 23 window.onload = async function () { 24 try { 25 const ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom"); 26 const React = browserRequire("devtools/client/shared/vendor/react"); 27 const dom = require("devtools/client/shared/vendor/react-dom-factories"); 28 const Tree = 29 React.createFactory(browserRequire("devtools/client/shared/components/VirtualizedTree")); 30 31 const treeProps = Object.assign({}, TEST_TREE_INTERFACE, { 32 renderItem: (item, depth, focused, arrow) => { 33 return dom.div( 34 { 35 id: item, 36 style: { marginLeft: depth * 16 + "px" } 37 }, 38 arrow, 39 item 40 ); 41 } 42 }); 43 const tree = ReactDOM.render(Tree(treeProps), window.document.body); 44 45 TEST_TREE.expanded = new Set("ABCDEFGHIJKLMNO".split("")); 46 await forceRender(tree); 47 48 let arrows = document.querySelectorAll(".arrow"); 49 for (const a of arrows) { 50 ok(a.classList.contains("open"), "Every arrow should be open."); 51 } 52 53 TEST_TREE.expanded = new Set(); 54 await forceRender(tree); 55 56 arrows = document.querySelectorAll(".arrow"); 57 for (const a of arrows) { 58 ok(!a.classList.contains("open"), "Every arrow should be closed."); 59 } 60 } catch(e) { 61 ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e)); 62 } finally { 63 SimpleTest.finish(); 64 } 65 }; 66 </script> 67 </pre> 68 </body> 69 </html>