themes_mapper_test.js 8.4 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/tab');
  21. require('models/configs/section');
  22. require('models/configs/sub_section');
  23. require('models/configs/stack_config_property');
  24. describe('App.themeMapper', function () {
  25. beforeEach(function () {
  26. App.resetDsStoreTypeMap(App.Tab);
  27. App.resetDsStoreTypeMap(App.Section);
  28. App.resetDsStoreTypeMap(App.SubSection);
  29. App.resetDsStoreTypeMap(App.StackConfigProperty);
  30. sinon.stub(App.store, 'commit', Em.K);
  31. });
  32. afterEach(function () {
  33. App.store.commit.restore();
  34. });
  35. describe("#map", function () {
  36. var json = {
  37. items: [
  38. {
  39. ThemeInfo: {
  40. service_name: "HDFS",
  41. theme_data: {
  42. "Theme": {
  43. "name": "default",
  44. "description": "Default theme for HDFS service",
  45. "configuration": {
  46. "layouts": [
  47. {
  48. "name": "default",
  49. "tabs": [
  50. {
  51. "name": "settings",
  52. "display-name": "Settings",
  53. "layout": {
  54. "tab-columns": "2",
  55. "tab-rows": "1",
  56. "sections": [
  57. {
  58. "name": "Section-1",
  59. "display-name": "Section One",
  60. "row-index": "0",
  61. "column-index": "0",
  62. "row-span": "1",
  63. "column-span": "1",
  64. "section-columns": "2",
  65. "section-rows": "3",
  66. "subsections": [
  67. {
  68. "name": "subsection1",
  69. "display-name": "Storage",
  70. "border": "false",
  71. "row-index": "0",
  72. "column-index": "0",
  73. "column-span": "1",
  74. "row-span": "1"
  75. }
  76. ]
  77. },
  78. {
  79. "name": "Section-2",
  80. "display-name": "Section Two",
  81. "row-index": "0",
  82. "column-index": "1"
  83. }
  84. ]
  85. }
  86. }
  87. ]
  88. }
  89. ],
  90. "widgets": [
  91. {
  92. "config": "c1/p1",
  93. "widget": {
  94. "type": "slider",
  95. "units": [
  96. {
  97. "unit-name": "MB"
  98. },
  99. {
  100. "unit-name": "GB"
  101. }
  102. ]
  103. }
  104. },
  105. {
  106. "config": "c1/p2",
  107. "widget": {
  108. "type": "slider",
  109. "units": [
  110. {
  111. "unit-name": "percent"
  112. }
  113. ]
  114. }
  115. }
  116. ],
  117. "placement": {
  118. "configuration-layout": "default",
  119. "configs": [
  120. {
  121. "config": "c1/p1",
  122. "subsection-name": "subsection1"
  123. },
  124. {
  125. "config": "c1/p2",
  126. "subsection-name": "subsection1"
  127. }
  128. ]
  129. }
  130. }
  131. }
  132. }
  133. }
  134. }
  135. ]
  136. };
  137. it('should map theme data', function () {
  138. App.StackConfigProperty.createRecord({id: 'p1__c1'});
  139. App.StackConfigProperty.createRecord({id: 'p2__c1'});
  140. App.themesMapper.map(json);
  141. expect(App.Tab.find().get('length')).to.equal(1);
  142. expect(App.Section.find().get('length')).to.equal(2);
  143. expect(App.SubSection.find().get('length')).to.equal(1);
  144. //checking tab
  145. expect(App.Tab.find('HDFS_settings').toJSON()).to.eql({
  146. id: 'HDFS_settings',
  147. name: 'settings',
  148. display_name: 'Settings',
  149. columns: "2",
  150. rows: "1",
  151. is_advanced: false,
  152. service_name: 'HDFS',
  153. is_advanced_hidden: false,
  154. is_rendered: false
  155. });
  156. //checking section
  157. expect(App.Tab.find('HDFS_settings').get('sections').objectAt(0).toJSON()).to.eql({
  158. "id": "Section-1",
  159. "name": "Section-1",
  160. "display_name": "Section One",
  161. "row_index": "0",
  162. "row_span": "1",
  163. "column_index": "0",
  164. "column_span": "1",
  165. "section_columns": "2",
  166. "section_rows": "3",
  167. "tab_id": "HDFS_settings"
  168. });
  169. //checking subsection
  170. expect(App.Tab.find('HDFS_settings').get('sections').objectAt(0).get('subSections').objectAt(0).toJSON()).to.eql({
  171. "id": "subsection1",
  172. "name": "subsection1",
  173. "display_name": "Storage",
  174. "border": "false",
  175. "row_index": "0",
  176. "row_span": "1",
  177. "column_index": "0",
  178. "column_span": "1",
  179. "section_id": "Section-1"
  180. });
  181. //checking stack config object
  182. var config = App.Tab.find('HDFS_settings').get('sections').objectAt(0).get('subSections').objectAt(0).get('configProperties').objectAt(0);
  183. expect(config.get('id')).to.eql("p1__c1");
  184. expect(config.get('subSection.id')).to.eql("subsection1");
  185. expect(config.get('widget')).to.eql({
  186. "type": "slider",
  187. "units": [
  188. {
  189. "unit-name": "MB"
  190. },
  191. {
  192. "unit-name": "GB"
  193. }
  194. ]
  195. });
  196. });
  197. });
  198. describe('#generateAdvancedTabs', function () {
  199. it('generates advanced tabs', function () {
  200. App.themesMapper.generateAdvancedTabs(['HDFS']);
  201. expect(App.Tab.find('HDFS_advanced').toJSON()).to.eql({
  202. "id": "HDFS_advanced",
  203. "name": "advanced",
  204. "display_name": "Advanced",
  205. "columns": 1,
  206. "rows": 1,
  207. "is_advanced": true,
  208. "service_name": "HDFS",
  209. "is_advanced_hidden": false,
  210. is_rendered: 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. });