test_notification_box_01.html (4838B)
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 * Basic rendering 9 * Appending correct classname on wrapping 10 * Appending a notification 11 * Notification priority 12 * Closing notification 13 --> 14 <head> 15 <meta charset="utf-8"> 16 <title>Notification Box</title> 17 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 18 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 19 </head> 20 <body> 21 <pre id="test"> 22 <script src="head.js" type="application/javascript"></script> 23 <script type="application/javascript"> 24 25 'use strict' 26 27 window.onload = async function () { 28 try { 29 const ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom"); 30 const React = browserRequire("devtools/client/shared/vendor/react"); 31 const { NotificationBox, PriorityLevels } = browserRequire("devtools/client/shared/components/NotificationBox"); 32 33 info("Test rendering NotificationBox with default props"); 34 const boxElement = React.createElement(NotificationBox); 35 const notificationBox = TestUtils.renderIntoDocument(boxElement); 36 const notificationNode = ReactDOM.findDOMNode(notificationBox); 37 38 is(notificationNode.tagName, "DIV", "NotificationBox is rendered as <div>"); 39 ok(notificationNode.classList.contains("notificationbox"), 40 "NotificationBox has expected class"); 41 ok(notificationNode.classList.contains("border-bottom"), 42 "NotificationBox has expected class"); 43 is(notificationNode.textContent, "", 44 "Empty NotificationBox has no text content"); 45 46 checkNumberOfNotifications(notificationBox, 0); 47 48 // Append a notification 49 notificationBox.appendNotification( 50 "Info message", 51 "id1", 52 null, 53 PriorityLevels.PRIORITY_INFO_HIGH 54 ); 55 56 is (notificationNode.textContent, "Info message", 57 "The box must display notification message"); 58 checkNumberOfNotifications(notificationBox, 1); 59 60 // Append more important notification 61 notificationBox.appendNotification( 62 "Critical message", 63 "id2", 64 null, 65 PriorityLevels.PRIORITY_CRITICAL_BLOCK 66 ); 67 68 checkNumberOfNotifications(notificationBox, 1); 69 70 is (notificationNode.textContent, "Critical message", 71 "The box must display more important notification message"); 72 73 // Append less important notification 74 notificationBox.appendNotification( 75 "Warning message", 76 "id3", 77 null, 78 PriorityLevels.PRIORITY_WARNING_HIGH 79 ); 80 81 checkNumberOfNotifications(notificationBox, 1); 82 83 is (notificationNode.textContent, "Critical message", 84 "The box must still display the more important notification"); 85 86 ok(notificationBox.getCurrentNotification(), 87 "There must be current notification"); 88 89 notificationBox.getNotificationWithValue("id1").close(); 90 checkNumberOfNotifications(notificationBox, 1); 91 92 notificationBox.getNotificationWithValue("id2").close(); 93 checkNumberOfNotifications(notificationBox, 1); 94 95 notificationBox.getNotificationWithValue("id3").close(); 96 checkNumberOfNotifications(notificationBox, 0); 97 98 info(`Check "wrapping" prop works as expected`); 99 // Append wrapping classname to the dom element when passing wrapping prop 100 const boxElementWrapped = React.createElement(NotificationBox, {wrapping: true}); 101 const notificationBoxWrapped = TestUtils.renderIntoDocument(boxElementWrapped); 102 const wrappedNotificationNode = ReactDOM.findDOMNode(notificationBoxWrapped); 103 104 ok(wrappedNotificationNode.classList.contains("wrapping"), 105 "Wrapped notificationBox has expected class"); 106 107 info(`Check "displayBorderTop/displayBorderBottom" props work as expected`); 108 const element = React.createElement(NotificationBox, { 109 displayBorderTop: true, 110 displayBorderBottom: false, 111 }); 112 const renderedElement = TestUtils.renderIntoDocument(element); 113 const elementNode = ReactDOM.findDOMNode(renderedElement); 114 115 ok(elementNode.classList.contains("border-top"), 116 "truthy displayBorderTop render a border-top className"); 117 ok(!elementNode.classList.contains("border-bottom"), 118 "falsy displayBorderBottom does not render a border-bottom className"); 119 } catch(e) { 120 ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e)); 121 } finally { 122 SimpleTest.finish(); 123 } 124 }; 125 126 function checkNumberOfNotifications(notificationBox, expected) { 127 is(TestUtils.scryRenderedDOMComponentsWithClass( 128 notificationBox, "notification").length, expected, 129 "The notification box must have expected number of notifications"); 130 } 131 </script> 132 </pre> 133 </body> 134 </html>