test_List_01.html (2539B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 Test to verify the delete button calls the onDelete handler for an item 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Tree component test</title> 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 11 </head> 12 <body> 13 <div id="container"></div> 14 15 <pre id="test"> 16 <script src="head.js" type="application/javascript"></script> 17 <script type="application/javascript"> 18 "use strict"; 19 window.onload = async function() { 20 try { 21 const container = document.getElementById("container"); 22 23 const deletedSnapshots = []; 24 25 const snapshots = [ TEST_SNAPSHOT, TEST_SNAPSHOT, TEST_SNAPSHOT ] 26 .map((snapshot, index) => immutableUpdate(snapshot, { 27 index: snapshot.index + index, 28 })); 29 30 await renderComponent( 31 List({ 32 itemComponent: SnapshotListItem, 33 onClick: noop, 34 onDelete: (item) => deletedSnapshots.push(item), 35 items: snapshots, 36 }), 37 container 38 ); 39 40 const deleteButtons = container.querySelectorAll(".delete"); 41 42 is(container.querySelectorAll(".snapshot-list-item").length, 3, 43 "There are 3 list items\n"); 44 is(deletedSnapshots.length, 0, 45 "Not snapshots have been deleted\n"); 46 47 deleteButtons[1].click(); 48 49 is(deletedSnapshots.length, 1, "One snapshot was deleted\n"); 50 is(deletedSnapshots[0], snapshots[1], 51 "Deleted snapshot was added to the deleted list\n"); 52 53 deleteButtons[0].click(); 54 55 is(deletedSnapshots.length, 2, "Two snapshots were deleted\n"); 56 is(deletedSnapshots[1], snapshots[0], 57 "Deleted snapshot was added to the deleted list\n"); 58 59 deleteButtons[2].click(); 60 61 is(deletedSnapshots.length, 3, "Three snapshots were deleted\n"); 62 is(deletedSnapshots[2], snapshots[2], 63 "Deleted snapshot was added to the deleted list\n"); 64 } catch (e) { 65 ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e)); 66 } finally { 67 SimpleTest.finish(); 68 } 69 }; 70 </script> 71 </pre> 72 </body> 73 </html>