test_notification_box_03.html (2677B)
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 for Notification Box. The test is checking: 8 * Using custom buttons in a notification 9 --> 10 <head> 11 <meta charset="utf-8"> 12 <title>Notification Box</title> 13 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 14 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.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 { NotificationBox, PriorityLevels } = browserRequire("devtools/client/shared/components/NotificationBox"); 28 29 // Test rendering 30 const boxElement = React.createElement(NotificationBox); 31 const notificationBox = TestUtils.renderIntoDocument(boxElement); 32 const notificationNode = ReactDOM.findDOMNode(notificationBox); 33 34 let buttonCallbackExecuted = false; 35 const buttons = [{ 36 label: "Button1", 37 callback: () => { 38 buttonCallbackExecuted = true; 39 40 // Do not close the notification 41 return true; 42 }, 43 }, { 44 label: "Button2", 45 callback: () => { 46 // Close the notification (return value undefined) 47 }, 48 }]; 49 50 // Append a notification with buttons. 51 notificationBox.appendNotification( 52 "Info message", 53 "id1", 54 null, 55 PriorityLevels.PRIORITY_INFO_LOW, 56 buttons 57 ); 58 59 const buttonNodes = notificationNode.querySelectorAll( 60 ".notificationButton"); 61 62 is(buttonNodes.length, 2, "There must be two buttons"); 63 64 // Click the first button 65 TestUtils.Simulate.click(buttonNodes[0]); 66 ok(buttonCallbackExecuted, "Button callback must be executed."); 67 68 is(TestUtils.scryRenderedDOMComponentsWithClass( 69 notificationBox, "notification").length, 1, 70 "There must be one notification"); 71 72 // Click the second button (closing the notification) 73 TestUtils.Simulate.click(buttonNodes[1]); 74 75 is(TestUtils.scryRenderedDOMComponentsWithClass( 76 notificationBox, "notification").length, 0, 77 "The notification box must be empty now"); 78 } catch(e) { 79 ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e)); 80 } finally { 81 SimpleTest.finish(); 82 } 83 }; 84 </script> 85 </pre> 86 </body> 87 </html>