/root/projects/slingshot/tests/alfresco/menus/AlfMenuBarSelectItemsTest.js

https://github.com/deas/alfresco · JavaScript · 267 lines · 204 code · 20 blank · 43 comment · 9 complexity · 6ec62bcacc8edab5751bf3d790186941 MD5 · raw file

  1. /**
  2. * Copyright (C) 2005-2014 Alfresco Software Limited.
  3. *
  4. * This file is part of Alfresco
  5. *
  6. * Alfresco is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Alfresco is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * This is the unit test for the alfresco/menus/AlfMenuBarSelectItems widget.
  21. *
  22. * @author Dave Draper
  23. */
  24. define(["intern!object",
  25. "intern/chai!assert",
  26. "require",
  27. "alfresco/TestCommon",
  28. "intern/dojo/node!leadfoot/keys"],
  29. function (registerSuite, assert, require, TestCommon, keys) {
  30. registerSuite({
  31. name: 'AlfMenuBarSelectItems Test',
  32. 'alfresco/menus/AlfMenuBarSelectItems': function () {
  33. var browser = this.remote;
  34. var testName = "Menu Bar Select Items Test";
  35. return TestCommon.loadTestWebScript(this.remote, "/AlfMenuBarSelectItems", testName)
  36. // Test #1
  37. // Check that the subscription is set-up correctly
  38. .findByCssSelector(TestCommon.topicSelector("MENU_BAR_SELECT_ITEMS"))
  39. .then(null, function() {
  40. assert(false, "Test #1 - A subscription for the widget could not be found");
  41. })
  42. .end()
  43. // Test #2
  44. // Check that nothing is selected on page load...
  45. .execute('return dijit.registry.byId("MENU_BAR_SELECT_ITEMS")._itemsSelected.toString()')
  46. .then(function(result) {
  47. assert(result == "0", "Test #2 - There should be nothing selected on page load");
  48. })
  49. .end()
  50. // Test #3
  51. // Check clicking on the "Select All" item...
  52. .findByCssSelector("#MENU_BAR_SELECT_ITEMS")
  53. .click()
  54. .end()
  55. .findByCssSelector("#SELECT_ALL")
  56. .click()
  57. .end()
  58. .execute('return dijit.registry.byId("MENU_BAR_SELECT_ITEMS")._itemsSelected.toString()')
  59. .then(function(result) {
  60. assert(result == "2", "Test #3 - _itemsSelected should be 2 after clicking on ALL");
  61. })
  62. .findByCssSelector(TestCommon.topicSelector("MENU_BAR_SELECT_ITEMS", "publish", "last"))
  63. .then(null, function() {
  64. assert(false, "Test #3 - Mouse selection of ALL didn't publish correctly (missing publish topic)");
  65. })
  66. .end()
  67. .findByCssSelector(TestCommon.pubSubDataCssSelector("last", "value", "selectAll"))
  68. .then(null, function() {
  69. assert(false, "Test #3 - Mouse selection of ALL didn't publish correctly (incorrect 'value' payload attribute");
  70. })
  71. .end()
  72. .findByCssSelector("#MENU_BAR_SELECT_ITEMS>img.alf-allselected-icon")
  73. .then(null, function() {
  74. assert(false, "Test #3 - Mouse selection of ALL set the correct CSS class.");
  75. })
  76. .end()
  77. // Test #4
  78. // Clicking on the 'checkbox' should now deselect everything...
  79. .findByCssSelector("#MENU_BAR_SELECT_ITEMS>img")
  80. .click()
  81. .end()
  82. .execute('return dijit.registry.byId("MENU_BAR_SELECT_ITEMS")._itemsSelected.toString()')
  83. .then(function(result) {
  84. assert(result == "0", "Test #4 - _itemsSelected should be 0 after clicking on checkbox image");
  85. })
  86. .end()
  87. .findByCssSelector(TestCommon.pubSubDataCssSelector("last", "value", "selectNone"))
  88. .then(null, function() {
  89. assert(false, "Test #4 - Mouse click on ALL checkbox image didn't publish correctly (incorrect 'value' payload attribute");
  90. })
  91. .end()
  92. .findByCssSelector("#MENU_BAR_SELECT_ITEMS>img.alf-noneselected-icon")
  93. .then(null, function() {
  94. assert(false, "Test #4 - Mouse click on ALL checkbox didn't set the correct CSS class.");
  95. })
  96. .end()
  97. // Test #5
  98. // Check clicking on the "Some" menu item...
  99. .findByCssSelector("#MENU_BAR_SELECT_ITEMS")
  100. .click()
  101. .end()
  102. .findByCssSelector("#SELECT_SOME_BY_ITEMS")
  103. .click()
  104. .end()
  105. .execute('return dijit.registry.byId("MENU_BAR_SELECT_ITEMS")._itemsSelected.toString()')
  106. .then(function(result) {
  107. assert(result == "1", "Test #5 - _itemsSelected should be 1 after clicking on SOME");
  108. })
  109. .end()
  110. .findByCssSelector(TestCommon.pubSubDataCssSelector("last", "availableItemCount", "2"))
  111. .then(null, function() {
  112. assert(false, "Test #5 - Mouse selection of SOME didn't publish correctly (incorrect 'availableItemCount' payload attribute");
  113. })
  114. .end()
  115. .findByCssSelector(TestCommon.pubSubDataCssSelector("last", "selectedItemCount", "1"))
  116. .then(null, function() {
  117. assert(false, "Test #5 - Mouse selection of SOME didn't publish correctly (incorrect 'selectedItemCount' payload attribute");
  118. })
  119. .end()
  120. .findByCssSelector("#MENU_BAR_SELECT_ITEMS>img.alf-someselected-icon")
  121. .then(null, function() {
  122. assert(false, "Test #5 - Mouse selection of SOME set the correct CSS class.");
  123. })
  124. .end()
  125. // Test #6
  126. // Clicking on the 'checkbox' should move "SOME" to "ALL"...
  127. .findByCssSelector("#MENU_BAR_SELECT_ITEMS>img")
  128. .click()
  129. .end()
  130. .execute('return dijit.registry.byId("MENU_BAR_SELECT_ITEMS")._itemsSelected.toString()')
  131. .then(function(result) {
  132. assert(result == "2", "Test #6 - _itemsSelected should be 2 after clicking on the SOME checkbox image");
  133. })
  134. .end()
  135. .findByCssSelector(TestCommon.pubSubDataCssSelector("last", "value", "selectAll"))
  136. .then(null, function() {
  137. assert(false, "Test #6 - Mouse click on SOME checkbox image didn't publish correctly (incorrect 'value' payload attribute");
  138. })
  139. .end()
  140. .findByCssSelector("#MENU_BAR_SELECT_ITEMS>img.alf-allselected-icon")
  141. .then(null, function() {
  142. assert(false, "Test #6 - Mouse click on SOME checkbox didn't set the correct CSS class.");
  143. })
  144. .end()
  145. // Test #7
  146. // Check clicking on the "None (by Items)" menu item will set the none state...
  147. .findByCssSelector("#MENU_BAR_SELECT_ITEMS")
  148. .click()
  149. .end()
  150. .findByCssSelector("#SELECT_NONE_BY_ITEMS")
  151. .click()
  152. .end()
  153. .execute('return dijit.registry.byId("MENU_BAR_SELECT_ITEMS")._itemsSelected.toString()')
  154. .then(function(result) {
  155. assert(result == "0", "Test #7 - _itemsSelected should be 0 after clicking on NONE (by items)");
  156. })
  157. .end()
  158. .findByCssSelector(TestCommon.pubSubDataCssSelector("last", "availableItemCount", "2"))
  159. .then(null, function() {
  160. assert(false, "Test #7 - Mouse selection of NONE (by items) didn't publish correctly (incorrect 'availableItemCount' payload attribute");
  161. })
  162. .end()
  163. .findByCssSelector(TestCommon.pubSubDataCssSelector("last", "selectedItemCount", "0"))
  164. .then(null, function() {
  165. assert(false, "Test #7 - Mouse selection of NONE (by items) didn't publish correctly (incorrect 'selectedItemCount' payload attribute");
  166. })
  167. .end()
  168. .findByCssSelector("#MENU_BAR_SELECT_ITEMS>img.alf-noneselected-icon")
  169. .then(null, function() {
  170. assert(false, "Test #7 - Mouse selection of NONE (by items) set the correct CSS class.");
  171. })
  172. .end()
  173. // Test #8
  174. // Check clicking on the "All (by Items)" menu item will set the all state...
  175. .findByCssSelector("#MENU_BAR_SELECT_ITEMS")
  176. .click()
  177. .end()
  178. .findByCssSelector("#SELECT_ALL_BY_ITEMS")
  179. .click()
  180. .end()
  181. .execute('return dijit.registry.byId("MENU_BAR_SELECT_ITEMS")._itemsSelected.toString()')
  182. .then(function(result) {
  183. assert(result == "2", "Test #8 - _itemsSelected should be 2 after clicking on ALL (by items)");
  184. })
  185. .end()
  186. .findByCssSelector(TestCommon.pubSubDataCssSelector("last", "availableItemCount", "2"))
  187. .then(null, function() {
  188. assert(false, "Test #8 - Mouse selection of ALL (by items) didn't publish correctly (incorrect 'availableItemCount' payload attribute");
  189. })
  190. .end()
  191. .findByCssSelector(TestCommon.pubSubDataCssSelector("last", "selectedItemCount", "2"))
  192. .then(null, function() {
  193. assert(false, "Test #8 - Mouse selection of ALL (by items) didn't publish correctly (incorrect 'selectedItemCount' payload attribute");
  194. })
  195. .end()
  196. .findByCssSelector("#MENU_BAR_SELECT_ITEMS>img.alf-allselected-icon")
  197. .then(null, function(result) {
  198. assert(false, "Test #8 - Mouse selection of ALL (by items) set the correct CSS class.");
  199. })
  200. .end()
  201. // Test #9
  202. // Check clicking on the "Select None" item...
  203. .findByCssSelector("#MENU_BAR_SELECT_ITEMS")
  204. .click()
  205. .end()
  206. .findByCssSelector("#SELECT_NONE")
  207. .click()
  208. .end()
  209. .execute('return dijit.registry.byId("MENU_BAR_SELECT_ITEMS")._itemsSelected.toString()')
  210. .then(function(result) {
  211. assert(result == "0", "Test #9 - _itemsSelected should be 0 after clicking on NONE");
  212. })
  213. .end()
  214. .findByCssSelector(TestCommon.pubSubDataCssSelector("last", "value", "selectNone"))
  215. .then(null, function() {
  216. assert(false, "Test #9 - Mouse selection of NONE didn't publish correctly (incorrect 'value' payload attribute");
  217. })
  218. .end()
  219. .findByCssSelector("#MENU_BAR_SELECT_ITEMS>img.alf-noneselected-icon")
  220. .then(null, function() {
  221. assert(false, "Test #9 - Mouse selection of NONE set the correct CSS class.");
  222. })
  223. .end()
  224. // Test #10
  225. // Clicking on the 'checkbox' should move "NONE" to "ALL"...
  226. .findByCssSelector("#MENU_BAR_SELECT_ITEMS>img")
  227. .click()
  228. .end()
  229. .execute('return dijit.registry.byId("MENU_BAR_SELECT_ITEMS")._itemsSelected.toString()')
  230. .then(function(result) {
  231. assert(result == "2", "Test #10 - _itemsSelected should be 2 after clicking on the NONE checkbox image");
  232. })
  233. .end()
  234. .findByCssSelector(TestCommon.pubSubDataCssSelector("last", "value", "selectAll"))
  235. .then(null, function() {
  236. assert(false, "Test #10 - Mouse click on NONE checkbox image didn't publish correctly (incorrect 'value' payload attribute");
  237. })
  238. .end()
  239. .findByCssSelector("#MENU_BAR_SELECT_ITEMS>img.alf-allselected-icon")
  240. .then(null, function() {
  241. assert(false, "Test #10 - Mouse click on NONE checkbox didn't set the correct CSS class.");
  242. })
  243. .end()
  244. .alfPostCoverageResults(browser);
  245. }
  246. });
  247. });