4 <script src="https://cdn.rawgit.com/google/closure-library/master/closure/goog/base.js"></script>
5 <script src="../../cr.js"></script>
6 <script src="../event_target.js"></script>
7 <script src="../ui.js"></script>
8 <script src="command.js"></script>
9 <script src="menu.js"></script>
10 <script src="menu_item.js"></script>
13 goog.require('goog.testing.jsunit');
23 * Tests that if the command attributes are spacified, they are copied to the
24 * corresponding menuitem.
26 function testCommandMenuItem() {
27 // Test 1: The case that the comamnd label is set.
28 var command = new cr.ui.Command();
29 command.id = 'the-command';
30 command.label = 'CommandLabel';
31 command.disabled = false;
32 command.hidden = false;
33 document.body.appendChild(command);
35 var menuItem = new cr.ui.MenuItem();
36 menuItem.command = '#the-command';
38 // Confirms the label is copied from the command.
39 assertEquals('CommandLabel', menuItem.label);
40 // Confirms the attributes are copied from the command.
41 assertEquals(false, menuItem.disabled);
42 assertEquals(false, menuItem.hidden);
44 // Test 2: The case that the comamnd label is not set.
45 var command2 = new cr.ui.Command();
46 command2.id = 'the-command2';
47 command2.disabled = false;
48 command2.hidden = false;
49 document.body.appendChild(command2);
51 var menuItem2 = new cr.ui.MenuItem();
52 menuItem2.label = 'MenuLabel';
53 menuItem2.command = '#the-command2';
55 // Confirms the label is not copied, keeping the original label.
56 assertEquals('MenuLabel', menuItem2.label);
57 // Confirms the attributes are copied from the command.
58 assertEquals(false, menuItem2.disabled);
59 assertEquals(false, menuItem2.hidden);