themes_mapper_test.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('mappers/configs/themes_mapper');
  20. require('models/configs/theme/tab');
  21. require('models/configs/theme/section');
  22. require('models/configs/theme/sub_section');
  23. describe('App.themeMapper', function () {
  24. beforeEach(function () {
  25. App.resetDsStoreTypeMap(App.Tab);
  26. App.resetDsStoreTypeMap(App.Section);
  27. App.resetDsStoreTypeMap(App.SubSection);
  28. sinon.stub(App.store, 'commit', Em.K);
  29. });
  30. afterEach(function () {
  31. App.store.commit.restore();
  32. });
  33. describe("#map", function () {
  34. var json = {
  35. items: [
  36. {
  37. ThemeInfo: {
  38. service_name: "HDFS",
  39. theme_data: {
  40. "Theme": {
  41. "name": "default",
  42. "description": "Default theme for HDFS service",
  43. "configuration": {
  44. "layouts": [
  45. {
  46. "name": "default",
  47. "tabs": [
  48. {
  49. "name": "settings",
  50. "display-name": "Settings",
  51. "layout": {
  52. "tab-columns": "2",
  53. "tab-rows": "1",
  54. "sections": [
  55. {
  56. "name": "Section-1",
  57. "display-name": "Section One",
  58. "row-index": "0",
  59. "column-index": "0",
  60. "row-span": "1",
  61. "column-span": "1",
  62. "section-columns": "2",
  63. "section-rows": "3",
  64. "subsections": [
  65. {
  66. "name": "subsection1",
  67. "display-name": "Storage",
  68. "border": "false",
  69. "row-index": "0",
  70. "column-index": "0",
  71. "column-span": "1",
  72. "row-span": "1"
  73. }
  74. ]
  75. },
  76. {
  77. "name": "Section-2",
  78. "display-name": "Section Two",
  79. "row-index": "0",
  80. "column-index": "1"
  81. }
  82. ]
  83. }
  84. }
  85. ]
  86. }
  87. ],
  88. "widgets": [
  89. {
  90. "config": "c1/p1",
  91. "widget": {
  92. "type": "slider",
  93. "units": [
  94. {
  95. "unit-name": "MB"
  96. },
  97. {
  98. "unit-name": "GB"
  99. }
  100. ]
  101. }
  102. },
  103. {
  104. "config": "c1/p2",
  105. "widget": {
  106. "type": "slider",
  107. "units": [
  108. {
  109. "unit-name": "percent"
  110. }
  111. ]
  112. }
  113. }
  114. ],
  115. "placement": {
  116. "configuration-layout": "default",
  117. "configs": [
  118. {
  119. "config": "c1/p1",
  120. "subsection-name": "subsection1"
  121. },
  122. {
  123. "config": "c1/p2",
  124. "subsection-name": "subsection1"
  125. }
  126. ]
  127. }
  128. }
  129. }
  130. }
  131. }
  132. }
  133. ]
  134. };
  135. describe('should map theme data', function () {
  136. beforeEach(function () {
  137. App.themesMapper.map(json);
  138. });
  139. it('1 Tab is mapped', function () {
  140. expect(App.Tab.find().get('length')).to.equal(1);
  141. });
  142. it('2 Sections are mapped', function () {
  143. expect(App.Section.find().get('length')).to.equal(2);
  144. });
  145. it('1 SubSection is mapped', function () {
  146. expect(App.SubSection.find().get('length')).to.equal(1);
  147. });
  148. it('HDFS_settings tab is mapped correctly', function () {
  149. //checking tab
  150. expect(App.Tab.find('HDFS_settings').toJSON()).to.eql({
  151. id: 'HDFS_settings',
  152. name: 'settings',
  153. display_name: 'Settings',
  154. columns: "2",
  155. rows: "1",
  156. is_advanced: false,
  157. service_name: 'HDFS',
  158. is_advanced_hidden: false,
  159. is_rendered: false,
  160. is_configs_prepared: false
  161. });
  162. });
  163. it('HDFS_settings section is mapped correctly', function () {
  164. //checking section
  165. expect(App.Tab.find('HDFS_settings').get('sections').objectAt(0).toJSON()).to.eql({
  166. "id": "Section-1",
  167. "name": "Section-1",
  168. "display_name": "Section One",
  169. "row_index": "0",
  170. "row_span": "1",
  171. "column_index": "0",
  172. "column_span": "1",
  173. "section_columns": "2",
  174. "section_rows": "3",
  175. "tab_id": "HDFS_settings"
  176. });
  177. });
  178. it('HDFS_settings section subsection is mapped correctly', function () {
  179. //checking subsection
  180. expect(App.Tab.find('HDFS_settings').get('sections').objectAt(0).get('subSections').objectAt(0).toJSON()).to.eql({
  181. "id": "subsection1",
  182. "name": "subsection1",
  183. "display_name": "Storage",
  184. "border": "false",
  185. "row_index": "0",
  186. "row_span": "1",
  187. "column_index": "0",
  188. "depends_on": [],
  189. "config_properties": [],
  190. "left_vertical_splitter": true,
  191. "column_span": "1",
  192. "section_id": "Section-1"
  193. });
  194. });
  195. });
  196. });
  197. describe('#generateAdvancedTabs', function () {
  198. it('generates advanced tabs', function () {
  199. App.themesMapper.generateAdvancedTabs(['HDFS']);
  200. expect(App.Tab.find('HDFS_advanced').toJSON()).to.eql({
  201. "id": "HDFS_advanced",
  202. "name": "advanced",
  203. "display_name": "Advanced",
  204. "columns": 1,
  205. "rows": 1,
  206. "is_advanced": true,
  207. "service_name": "HDFS",
  208. "is_advanced_hidden": false,
  209. is_rendered: false,
  210. is_configs_prepared: false
  211. });
  212. });
  213. });
  214. describe('#getConfigId', function () {
  215. it('gets configs id from json', function () {
  216. expect(App.themesMapper.getConfigId({config: "c1/p1"})).to.equal("p1__c1");
  217. });
  218. it('returns null as data is invalid', function () {
  219. expect(App.themesMapper.getConfigId({configs: "c1/p1"})).to.equal(null);
  220. });
  221. });
  222. });