GitHub PullRequestReviewCommentEvent at 2014-05-12 02:47:22
Repository: gaia
Actor: EragonJ
Payload: {"comment":{"url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/12513036","id":12513036,"diff_hunk":"@@ -0,0 +1,154 @@\n+/* globals MocksHelper, MockKeyboardHelper */\n+'use strict';\n+\n+require('/shared/test/unit/mocks/mock_keyboard_helper.js');\n+require('/shared/test/unit/mocks/mock_manifest_helper.js');\n+\n+suite('KeyboardAddLayoutsPanel', function() {\n+  var map = {\n+    '*': {\n+      'shared/manifest_helper': 'shared_mocks/mock_manifest_helper',\n+      'shared/keyboard_helper': 'shared_mocks/mock_keyboard_helper',\n+      'modules/settings_panel': 'unit/mock_settings_panel',\n+      'modules/settings_service': 'unit/mock_settings_service'\n+    }\n+  };\n+\n+  var mockHelper = new MocksHelper([\n+    'KeyboardHelper',\n+    'ManifestHelper'\n+  ]).init();\n+  mockHelper.attachTestHelpers();\n+\n+  suiteSetup(function(done) {\n+    testRequire([\n+      'modules/keyboard_context',\n+      'panels/keyboard_add_layouts/panel',\n+      'unit/mock_settings_panel'\n+    ], map,\n+    (function(KeyboardContext, KeyboardAddLayoutsPanel, MockSettingsPanel) {\n+      this.KeyboardContext = KeyboardContext;\n+      this.KeyboardAddLayoutsPanel = KeyboardAddLayoutsPanel;\n+      this.MockSettingsPanel = MockSettingsPanel;\n+      this.MockSettingsPanel.mInnerFunction = function(options) {\n+        return {\n+          init: options.onInit,\n+          beforeShow: options.onBeforeShow,\n+          beforeHide: options.onBeforeHide,\n+          hide: options.onHide\n+        };\n+      };\n+      done();\n+    }).bind(this));\n+  });\n+\n+  suiteTeardown(function() {\n+    this.MockSettingsPanel.mTeardown();\n+  });\n+\n+  suite('KeyboardAddLayoutsPanel', function() {\n+    var keyboards;\n+\n+    setup(function(done) {\n+      this.root = document.createElement('div');\n+      this.root.id = 'keyboard-selection-addMore';\n+      this.container = document.createElement('div');\n+      this.container.className = 'keyboardAppContainer';\n+      this.root.appendChild(this.container);\n+      document.body.appendChild(this.root);\n+      this.KeyboardContext.init();\n+      this.KeyboardContext.keyboards(function(_keyboards) {\n+        keyboards = _keyboards;\n+        done();\n+      });\n+    });\n+\n+    teardown(function() {\n+      document.body.removeChild(this.root);\n+    });\n+\n+    suite('Shows all Keyboards and Layouts', function() {\n+      setup(function() {\n+        this.KeyboardAddLayoutsPanel().init(this.root);\n+      });\n+\n+      function checkDom(container) {\n+        var elements = Array.prototype.slice.apply(container.children);\n+        assert.equal(elements.length, keyboards.length);\n+\n+        elements.forEach(function(element, index) {\n+          var keyboard = keyboards.get(index);\n+          assert.equal(\n+            element.querySelector('h2').textContent,\n+            keyboard.name,\n+            'keyboards[' + index + '] name correct'\n+          );\n+\n+          var ul = element.querySelector('ul');\n+          var children = Array.prototype.slice.apply(ul.children);\n+          children.forEach(function(li, index2) {\n+            assert.equal(\n+              li.querySelector('span').textContent,\n+              keyboard.layouts[index2].name,\n+              'keyboards[' + index + '].layouts[' + index2 + '] name correct'\n+            );\n+          });\n+        });\n+      }\n+\n+      test('creates a div for each keyboard', function() {\n+        checkDom(this.container);\n+      });\n+      test('removing and adding keyboards creates dom', function() {\n+        var temp = keyboards.get(1);\n+        keyboards.splice(1, 1);\n+        checkDom(this.container);\n+\n+        keyboards.splice(1, 0, temp);\n+        checkDom(this.container);\n+      });\n+      test('keyboards properly observe', function() {\n+        var keyboard = keyboards.get(1);\n+        var keyboardContainer = this.container.children[1];\n+\n+        keyboard.name = 'test';\n+        assert.equal(\n+          keyboardContainer.querySelector('h2').textContent,\n+          'test'\n+        );\n+\n+        keyboard.layouts[0].name = 'test';\n+        assert.equal(\n+          keyboardContainer.querySelector('li:nth-child(1) span').textContent,\n+          'test'\n+        );\n+\n+        var enabled = !keyboard.layouts[0].enabled;\n+        keyboard.layouts[0].enabled = enabled;\n+        assert.equal(\n+          keyboardContainer.querySelector('li:nth-child(1) input').checked,\n+          enabled\n+        );\n+      });\n+      test('click event on checkbox changes enabled', function() {\n+        var layout = keyboards.get(0).layouts[0];\n+        var checkbox = this.container.children[1]\n+                          .querySelector('li:nth-child(1) input');\n+        checkbox.checked = !checkbox.checked;\n+        // might want to fire this as a custom event some day\n+        checkbox.onchange();","path":"apps/settings/test/unit/panels/keyboard/keyboard_add_layouts_integration_test.js","position":139,"original_position":139,"commit_id":"e60e42a665ec06e8e75718fbc4734caee33d7c22","original_commit_id":"e60e42a665ec06e8e75718fbc4734caee33d7c22","user":{"login":"EragonJ","id":68322,"avatar_url":"https://avatars.githubusercontent.com/u/68322?","gravatar_id":"c467be2c8057ee9a73735ee2bd269504","url":"https://api.github.com/users/EragonJ","html_url":"https://github.com/EragonJ","followers_url":"https://api.github.com/users/EragonJ/followers","following_url":"https://api.github.com/users/EragonJ/following{/other_user}","gists_url":"https://api.github.com/users/EragonJ/gists{/gist_id}","starred_url":"https://api.github.com/users/EragonJ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EragonJ/subscriptions","organizations_url":"https://api.github.com/users/EragonJ/orgs","repos_url":"https://api.github.com/users/EragonJ/repos","events_url":"https://api.github.com/users/EragonJ/events{/privacy}","received_events_url":"https://api.github.com/users/EragonJ/received_events","type":"User","site_admin":false},"body":"Yeah, I am interested in this **Native behavior**, always can't understand why we change the value programmatically won't trigger the event handler hmmm ","created_at":"2014-05-12T02:47:22Z","updated_at":"2014-05-12T02:47:22Z","html_url":"https://github.com/mozilla-b2g/gaia/pull/18589#discussion_r12513036","pull_request_url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/18589","_links":{"self":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/12513036"},"html":{"href":"https://github.com/mozilla-b2g/gaia/pull/18589#discussion_r12513036"},"pull_request":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/18589"}}}}