controls_view_test.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  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('views/common/controls_view');
  20. var validator = require('utils/validator');
  21. var testHelpers = require('test/helpers');
  22. describe('App.ServiceConfigRadioButtons', function () {
  23. var view;
  24. beforeEach(function () {
  25. view = App.ServiceConfigRadioButtons.create();
  26. });
  27. describe('#handleDBConnectionProperty', function () {
  28. var cases = [
  29. {
  30. dbType: 'mysql',
  31. driver: 'mysql-connector-java.jar',
  32. serviceConfig: {
  33. name: 'hive_database',
  34. value: 'New MySQL Database',
  35. serviceName: 'HIVE'
  36. },
  37. controller: Em.Object.create({
  38. selectedService: {
  39. configs: [
  40. Em.Object.create({
  41. name: 'javax.jdo.option.ConnectionURL',
  42. displayName: 'Database URL'
  43. }),
  44. Em.Object.create({
  45. name: 'hive_database',
  46. displayName: 'Hive Database'
  47. })
  48. ]
  49. }
  50. }),
  51. currentStackVersion: 'HDP-2.2',
  52. rangerVersion: '0.4.0',
  53. propertyAppendTo1: 'javax.jdo.option.ConnectionURL',
  54. propertyAppendTo2: 'hive_database',
  55. isAdditionalView1Null: true,
  56. isAdditionalView2Null: true,
  57. title: 'Hive, embedded database'
  58. },
  59. {
  60. dbType: 'postgres',
  61. driver: 'postgresql.jar',
  62. serviceConfig: {
  63. name: 'hive_database',
  64. value: 'Existing PostgreSQL Database',
  65. serviceName: 'HIVE'
  66. },
  67. controller: Em.Object.create({
  68. selectedService: {
  69. configs: [
  70. Em.Object.create({
  71. name: 'javax.jdo.option.ConnectionURL',
  72. displayName: 'Database URL'
  73. }),
  74. Em.Object.create({
  75. name: 'hive_database',
  76. displayName: 'Hive Database'
  77. })
  78. ]
  79. }
  80. }),
  81. currentStackVersion: 'HDP-2.2',
  82. rangerVersion: '0.4.0',
  83. propertyAppendTo1: 'javax.jdo.option.ConnectionURL',
  84. propertyAppendTo2: 'hive_database',
  85. isAdditionalView1Null: false,
  86. isAdditionalView2Null: false,
  87. title: 'Hive, external database'
  88. },
  89. {
  90. dbType: 'derby',
  91. driver: 'driver.jar',
  92. serviceConfig: {
  93. name: 'oozie_database',
  94. value: 'New Derby Database',
  95. serviceName: 'OOZIE'
  96. },
  97. controller: Em.Object.create({
  98. selectedService: {
  99. configs: [
  100. Em.Object.create({
  101. name: 'oozie.service.JPAService.jdbc.url',
  102. displayName: 'Database URL'
  103. }),
  104. Em.Object.create({
  105. name: 'oozie_database',
  106. displayName: 'Oozie Database'
  107. })
  108. ]
  109. }
  110. }),
  111. currentStackVersion: 'HDP-2.2',
  112. rangerVersion: '0.4.0',
  113. propertyAppendTo1: 'oozie.service.JPAService.jdbc.url',
  114. propertyAppendTo2: 'oozie_database',
  115. isAdditionalView1Null: true,
  116. isAdditionalView2Null: true,
  117. title: 'Oozie, embedded database'
  118. },
  119. {
  120. dbType: 'oracle',
  121. driver: 'ojdbc6.jar',
  122. serviceConfig: {
  123. name: 'oozie_database',
  124. value: 'Existing Oracle Database',
  125. serviceName: 'OOZIE'
  126. },
  127. controller: Em.Object.create({
  128. selectedService: {
  129. configs: [
  130. Em.Object.create({
  131. name: 'oozie.service.JPAService.jdbc.url',
  132. displayName: 'Database URL'
  133. }),
  134. Em.Object.create({
  135. name: 'oozie_database',
  136. displayName: 'Oozie Database'
  137. })
  138. ]
  139. }
  140. }),
  141. currentStackVersion: 'HDP-2.2',
  142. rangerVersion: '0.4.0',
  143. propertyAppendTo1: 'oozie.service.JPAService.jdbc.url',
  144. propertyAppendTo2: 'oozie_database',
  145. isAdditionalView1Null: false,
  146. isAdditionalView2Null: false,
  147. title: 'Oozie, external database'
  148. },
  149. {
  150. dbType: 'mysql',
  151. driver: 'mysql-connector-java.jar',
  152. serviceConfig: {
  153. name: 'DB_FLAVOR',
  154. value: 'MYSQL',
  155. serviceName: 'RANGER'
  156. },
  157. controller: Em.Object.create({
  158. selectedService: {
  159. configs: [
  160. Em.Object.create({
  161. name: 'ranger.jpa.jdbc.url'
  162. }),
  163. Em.Object.create({
  164. name: 'DB_FLAVOR'
  165. })
  166. ]
  167. }
  168. }),
  169. currentStackVersion: 'HDP-2.2',
  170. rangerVersion: '0.4.0',
  171. propertyAppendTo1: 'ranger.jpa.jdbc.url',
  172. propertyAppendTo2: 'DB_FLAVOR',
  173. isAdditionalView1Null: true,
  174. isAdditionalView2Null: true,
  175. title: 'Ranger, HDP 2.2, external database'
  176. },
  177. {
  178. dbType: 'mssql',
  179. driver: 'sqljdbc4.jar',
  180. serviceConfig: {
  181. name: 'DB_FLAVOR',
  182. value: 'MSSQL',
  183. serviceName: 'RANGER'
  184. },
  185. controller: Em.Object.create({
  186. selectedService: {
  187. configs: [
  188. Em.Object.create({
  189. name: 'ranger.jpa.jdbc.url'
  190. }),
  191. Em.Object.create({
  192. name: 'DB_FLAVOR'
  193. })
  194. ]
  195. }
  196. }),
  197. currentStackVersion: 'HDP-2.3',
  198. rangerVersion: '0.5.0',
  199. propertyAppendTo1: 'ranger.jpa.jdbc.url',
  200. propertyAppendTo2: 'DB_FLAVOR',
  201. isAdditionalView1Null: false,
  202. isAdditionalView2Null: false,
  203. title: 'Ranger, HDP 2.3, external database'
  204. }
  205. ];
  206. var rangerVersion = '';
  207. before(function () {
  208. sinon.stub(Em.run, 'next', function (arg) {
  209. arg();
  210. });
  211. });
  212. beforeEach(function () {
  213. sinon.stub(view, 'sendRequestRorDependentConfigs', Em.K);
  214. this.stub = sinon.stub(App, 'get');
  215. this.stub.withArgs('currentStackName').returns('HDP');
  216. sinon.stub(App.StackService, 'find', function() {
  217. return [Em.Object.create({
  218. serviceName: 'RANGER',
  219. serviceVersion: rangerVersion || ''
  220. })];
  221. });
  222. });
  223. afterEach(function () {
  224. App.get.restore();
  225. App.StackService.find.restore();
  226. view.sendRequestRorDependentConfigs.restore();
  227. });
  228. after(function () {
  229. Em.run.next.restore();
  230. });
  231. cases.forEach(function (item) {
  232. describe(item.title, function () {
  233. var additionalView1, additionalView2;
  234. beforeEach(function () {
  235. this.stub.withArgs('currentStackVersion').returns(item.currentStackVersion);
  236. rangerVersion = item.rangerVersion;
  237. view.reopen({controller: item.controller});
  238. view.setProperties({
  239. categoryConfigsAll: item.controller.get('selectedService.configs'),
  240. serviceConfig: item.serviceConfig
  241. });
  242. additionalView1 = view.get('categoryConfigsAll').findProperty('name', item.propertyAppendTo1).get('additionalView');
  243. additionalView2 = view.get('categoryConfigsAll').findProperty('name', item.propertyAppendTo2).get('additionalView');
  244. });
  245. it('additionalView1 is ' + (item.isAdditionalView1Null ? '' : 'not') + ' null', function () {
  246. expect(Em.isNone(additionalView1)).to.equal(item.isAdditionalView1Null);
  247. });
  248. it('additionalView2 is ' + (item.isAdditionalView2Null ? '' : 'not') + ' null', function () {
  249. expect(Em.isNone(additionalView2)).to.equal(item.isAdditionalView2Null);
  250. });
  251. if (!item.isAdditionalView2Null) {
  252. it('additionalView2.message is valid', function () {
  253. expect(additionalView2.create().get('message')).to.equal(Em.I18n.t('services.service.config.database.msg.jdbcSetup').format(item.dbType, item.driver));
  254. });
  255. }
  256. });
  257. });
  258. });
  259. describe('#options', function () {
  260. var options = [
  261. {
  262. displayName: 'MySQL'
  263. },
  264. {
  265. displayName: 'New PostgreSQL Database'
  266. },
  267. {
  268. displayName: 'existing postgres db'
  269. },
  270. {
  271. displayName: 'sqla database: existing'
  272. },
  273. {
  274. displayName: 'SQL Anywhere database (New)'
  275. },
  276. {
  277. displayName: 'displayName'
  278. }
  279. ],
  280. classNames = ['mysql', 'new-postgres', 'postgres', 'sqla', 'new-sqla', undefined];
  281. beforeEach(function () {
  282. view.reopen({
  283. serviceConfig: Em.Object.create({
  284. options: options
  285. })
  286. });
  287. });
  288. it('should set class names for options', function () {
  289. expect(view.get('options').mapProperty('displayName')).to.eql(options.mapProperty('displayName'));
  290. expect(view.get('options').mapProperty('className')).to.eql(classNames);
  291. });
  292. });
  293. describe('#name', function () {
  294. var cases = [
  295. {
  296. serviceConfig: {
  297. radioName: 'n0',
  298. isOriginalSCP: true,
  299. isComparison: false
  300. },
  301. name: 'n0',
  302. title: 'original value'
  303. },
  304. {
  305. serviceConfig: {
  306. radioName: 'n1',
  307. isOriginalSCP: false,
  308. isComparison: true,
  309. compareConfigs: []
  310. },
  311. controller: {
  312. selectedVersion: 1
  313. },
  314. name: 'n1-v1',
  315. title: 'comparison view, original value'
  316. },
  317. {
  318. serviceConfig: {
  319. radioName: 'n2',
  320. isOriginalSCP: false,
  321. isComparison: true,
  322. compareConfigs: null
  323. },
  324. version: 2,
  325. name: 'n2-v2',
  326. title: 'comparison view, value to be compared with'
  327. },
  328. {
  329. serviceConfig: {
  330. radioName: 'n3',
  331. isOriginalSCP: false,
  332. isComparison: false,
  333. group: {
  334. name: 'g'
  335. }
  336. },
  337. name: 'n3-g',
  338. title: 'override value'
  339. }
  340. ];
  341. beforeEach(function () {
  342. view.reopen({
  343. serviceConfig: Em.Object.create()
  344. });
  345. });
  346. cases.forEach(function (item) {
  347. it(item.title, function () {
  348. if (item.controller) {
  349. view.reopen({
  350. controller: item.controller
  351. });
  352. }
  353. view.set('version', item.version);
  354. view.get('serviceConfig').setProperties(item.serviceConfig);
  355. expect(view.get('name')).to.equal(item.name);
  356. });
  357. });
  358. });
  359. describe('#dontUseHandleDbConnection', function () {
  360. var rangerService = Em.Object.create({
  361. serviceName: 'RANGER'
  362. });
  363. beforeEach(function () {
  364. sinon.stub(App.StackService, 'find', function () {
  365. return [rangerService];
  366. });
  367. });
  368. afterEach(function () {
  369. App.StackService.find.restore();
  370. });
  371. var cases = [
  372. {
  373. title: 'Should return properties for old version of Ranger',
  374. version: '0.1',
  375. result: ['DB_FLAVOR', 'authentication_method']
  376. },
  377. {
  378. title: 'Should return properties for old version of Ranger',
  379. version: '0.4.0',
  380. result: ['DB_FLAVOR', 'authentication_method']
  381. },
  382. {
  383. title: 'Should return properties for old version of Ranger',
  384. version: '0.4.9',
  385. result: ['DB_FLAVOR', 'authentication_method']
  386. },
  387. {
  388. title: 'Should return properties for new version of Ranger',
  389. version: '0.5.0',
  390. result: ['ranger.authentication.method']
  391. },
  392. {
  393. title: 'Should return properties for new version of Ranger',
  394. version: '1.0.0',
  395. result: ['ranger.authentication.method']
  396. },
  397. {
  398. title: 'Should return properties for new version of Ranger',
  399. version: '0.5.0.1',
  400. result: ['ranger.authentication.method']
  401. }
  402. ];
  403. cases.forEach(function (test) {
  404. it(test.title, function () {
  405. rangerService.set('serviceVersion', test.version);
  406. expect(view.get('dontUseHandleDbConnection')).to.eql(test.result);
  407. });
  408. });
  409. });
  410. });
  411. describe('App.ServiceConfigRadioButton', function () {
  412. var view;
  413. beforeEach(function () {
  414. view = App.ServiceConfigRadioButton.create({
  415. parentView: Em.Object.create({
  416. serviceConfig: Em.Object.create()
  417. }),
  418. controller: Em.Object.create({
  419. wizardController: Em.Object.create({
  420. name: null
  421. })
  422. })
  423. })
  424. });
  425. describe('#disabled', function () {
  426. var cases = [
  427. {
  428. wizardControllerName: 'addServiceController',
  429. value: 'New MySQL Database',
  430. title: 'Add Service Wizard, new database',
  431. disabled: false
  432. },
  433. {
  434. wizardControllerName: 'installerController',
  435. value: 'New MySQL Database',
  436. title: 'Install Wizard, new database',
  437. disabled: false
  438. },
  439. {
  440. wizardControllerName: 'addServiceController',
  441. value: 'Existing MySQL Database',
  442. title: 'Add Service Wizard, existing database',
  443. disabled: false
  444. },
  445. {
  446. wizardControllerName: 'installerController',
  447. value: 'Existing MySQL Database',
  448. title: 'Install Wizard, existing database',
  449. disabled: false
  450. },
  451. {
  452. wizardControllerName: null,
  453. value: 'New MySQL Database',
  454. title: 'No installer, new database',
  455. disabled: true
  456. },
  457. {
  458. wizardControllerName: null,
  459. value: 'Existing MySQL Database',
  460. title: 'No installer, existing database',
  461. disabled: false
  462. }
  463. ];
  464. cases.forEach(function (item) {
  465. it(item.title, function () {
  466. view.setProperties({
  467. 'value': item.value,
  468. 'controller.wizardController.name': item.wizardControllerName,
  469. 'parentView.serviceConfig.isEditable': true
  470. });
  471. expect(view.get('disabled')).to.equal(item.disabled);
  472. });
  473. });
  474. it('parent view is disabled', function () {
  475. view.set('parentView.serviceConfig.isEditable', false);
  476. expect(view.get('disabled')).to.be.true;
  477. });
  478. });
  479. describe('#onChecked', function () {
  480. var cases = [
  481. {
  482. clicked: true,
  483. value: 'v1',
  484. sendRequestRorDependentConfigsCallCount: 1,
  485. updateForeignKeysCallCount: 1,
  486. title: 'invoked with click'
  487. },
  488. {
  489. clicked: false,
  490. value: 'v0',
  491. sendRequestRorDependentConfigsCallCount: 0,
  492. updateForeignKeysCallCount: 0,
  493. title: 'not invoked with click'
  494. }
  495. ];
  496. cases.forEach(function (item) {
  497. describe(item.title, function () {
  498. beforeEach(function () {
  499. sinon.stub(Em.run, 'next', function (context, callback) {
  500. callback.call(context);
  501. });
  502. sinon.stub(view, 'sendRequestRorDependentConfigs', Em.K);
  503. sinon.stub(view, 'updateForeignKeys', Em.K);
  504. sinon.stub(view, 'updateCheck', Em.K);
  505. view.setProperties({
  506. 'clicked': item.clicked,
  507. 'parentView.serviceConfig.value': 'v0',
  508. 'value': 'v1'
  509. });
  510. view.propertyDidChange('checked');
  511. });
  512. afterEach(function () {
  513. Em.run.next.restore();
  514. view.sendRequestRorDependentConfigs.restore();
  515. view.updateForeignKeys.restore();
  516. view.updateCheck.restore();
  517. });
  518. it('property value', function () {
  519. expect(view.get('parentView.serviceConfig.value')).to.equal(item.value);
  520. });
  521. it('dependent configs request', function () {
  522. expect(view.sendRequestRorDependentConfigs.callCount).to.equal(item.sendRequestRorDependentConfigsCallCount);
  523. });
  524. if (item.sendRequestRorDependentConfigsCallCount) {
  525. it('config object for dependent configs request', function () {
  526. expect(view.sendRequestRorDependentConfigs.firstCall.args).to.eql([
  527. Em.Object.create({
  528. value: item.value
  529. })
  530. ]);
  531. });
  532. }
  533. it('clicked flag reset', function () {
  534. expect(view.get('clicked')).to.be.false;
  535. });
  536. it('update foreign keys', function () {
  537. expect(view.updateForeignKeys.callCount).to.equal(item.updateForeignKeysCallCount);
  538. });
  539. });
  540. });
  541. });
  542. });
  543. describe('App.CheckDBConnectionView', function () {
  544. describe('#masterHostName', function () {
  545. var cases = [
  546. {
  547. serviceName: 'OOZIE',
  548. value: 'h0'
  549. },
  550. {
  551. serviceName: 'KERBEROS',
  552. value: 'h1'
  553. },
  554. {
  555. serviceName: 'HIVE',
  556. value: 'h2'
  557. },
  558. {
  559. serviceName: 'RANGER',
  560. value: 'h3'
  561. }
  562. ],
  563. categoryConfigsAll = [
  564. Em.Object.create({
  565. name: 'oozie_server_hosts',
  566. value: 'h0'
  567. }),
  568. Em.Object.create({
  569. name: 'kdc_hosts',
  570. value: 'h1'
  571. }),
  572. Em.Object.create({
  573. name: 'hive_metastore_hosts',
  574. value: 'h2'
  575. }),
  576. Em.Object.create({
  577. name: 'ranger_server_hosts',
  578. value: 'h3'
  579. })
  580. ];
  581. cases.forEach(function (item) {
  582. it(item.serviceName, function () {
  583. var view = App.CheckDBConnectionView.create({
  584. parentView: {
  585. service: {
  586. serviceName: item.serviceName
  587. },
  588. categoryConfigsAll: categoryConfigsAll
  589. }
  590. });
  591. expect(view.get('masterHostName')).to.equal(item.value);
  592. });
  593. });
  594. });
  595. describe('#setResponseStatus', function () {
  596. var view,
  597. cases = [
  598. {
  599. isSuccess: 'success',
  600. logsPopupBefore: null,
  601. logsPopup: null,
  602. responseCaption: Em.I18n.t('services.service.config.database.connection.success'),
  603. isConnectionSuccess: true,
  604. title: 'success, no popup displayed'
  605. },
  606. {
  607. isSuccess: 'success',
  608. logsPopupBefore: {},
  609. logsPopup: {
  610. header: Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.success'))
  611. },
  612. responseCaption: Em.I18n.t('services.service.config.database.connection.success'),
  613. isConnectionSuccess: true,
  614. title: 'success, popup is displayed'
  615. },
  616. {
  617. isSuccess: 'error',
  618. logsPopupBefore: {},
  619. logsPopup: {
  620. header: Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.error'))
  621. },
  622. responseCaption: Em.I18n.t('services.service.config.database.connection.failed'),
  623. isConnectionSuccess: false,
  624. title: 'error, popup is displayed'
  625. }
  626. ];
  627. beforeEach(function () {
  628. view = App.CheckDBConnectionView.create({
  629. databaseName: 'MySQL'
  630. });
  631. sinon.stub(view, 'setConnectingStatus', Em.K);
  632. });
  633. afterEach(function () {
  634. view.setConnectingStatus.restore();
  635. });
  636. cases.forEach(function (item) {
  637. describe(item.title, function () {
  638. beforeEach(function () {
  639. view.set('logsPopup', item.logsPopupBefore);
  640. view.setResponseStatus(item.isSuccess);
  641. });
  642. it('isRequestResolved is true', function () {
  643. expect(view.get('isRequestResolved')).to.be.true;
  644. });
  645. it('setConnectingStatus is called with valid arguments', function () {
  646. expect(view.setConnectingStatus.calledOnce).to.be.true;
  647. expect(view.setConnectingStatus.calledWith(false)).to.be.true;
  648. });
  649. it('responseCaption is valid', function () {
  650. expect(view.get('responseCaption')).to.equal(item.responseCaption);
  651. });
  652. it('isConnectionSuccess is valid', function () {
  653. expect(view.get('isConnectionSuccess')).to.equal(item.isConnectionSuccess);
  654. });
  655. it('logsPopup is valid', function () {
  656. expect(view.get('logsPopup')).to.eql(item.logsPopup);
  657. });
  658. });
  659. });
  660. });
  661. describe('#showLogsPopup', function () {
  662. var view;
  663. beforeEach(function () {
  664. view = App.CheckDBConnectionView.create({
  665. databaseName: 'MySQL'
  666. });
  667. sinon.spy(App, 'showAlertPopup');
  668. });
  669. afterEach(function () {
  670. App.showAlertPopup.restore();
  671. });
  672. it('successful connection', function () {
  673. view.set('isConnectionSuccess', true);
  674. view.showLogsPopup();
  675. expect(App.showAlertPopup.callCount).to.equal(0);
  676. });
  677. describe('failed connection without output data, popup dismissed with Close button', function () {
  678. beforeEach(function () {
  679. view.set('isConnectionSuccess', false);
  680. view.set('isRequestResolved', true);
  681. view.set('responseFromServer', 'fail');
  682. view.showLogsPopup();
  683. });
  684. it('showAlertPopup is called once', function () {
  685. expect(App.showAlertPopup.callCount).to.equal(1);
  686. });
  687. it('logsPopup.header is valid', function () {
  688. expect(view.get('logsPopup.header')).to.equal(Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.error')));
  689. });
  690. it('logsPopup.body is valid', function () {
  691. expect(view.get('logsPopup.body')).to.equal('fail');
  692. });
  693. it('logsPopup is null after close', function () {
  694. view.get('logsPopup').onClose();
  695. expect(view.get('logsPopup')).to.be.null;
  696. });
  697. });
  698. describe('check in progress with output data, popup dismissed with OK button', function () {
  699. var response = {
  700. stderr: 'stderr',
  701. stdout: 'stdout',
  702. structuredOut: 'structuredOut'
  703. };
  704. beforeEach(function () {
  705. view.set('isConnectionSuccess', false);
  706. view.set('isRequestResolved', false);
  707. view.set('responseFromServer', response);
  708. view.showLogsPopup();
  709. });
  710. it('showAlertPopup is called once', function () {
  711. expect(App.showAlertPopup.callCount).to.equal(1);
  712. });
  713. it('logsPopup.header is valid', function () {
  714. expect(view.get('logsPopup.header')).to.equal(Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.testing')));
  715. });
  716. it('logsPopup.bodyClass is valid', function () {
  717. expect(view.get('logsPopup.bodyClass').create().get('openedTask')).to.eql(response);
  718. });
  719. it('logsPopup is null after primary click', function () {
  720. view.get('logsPopup').onPrimary();
  721. expect(view.get('logsPopup')).to.be.null;
  722. });
  723. });
  724. });
  725. describe("#createCustomAction()", function() {
  726. var view;
  727. beforeEach(function () {
  728. view = App.CheckDBConnectionView.create({
  729. databaseName: 'MySQL',
  730. getConnectionProperty: Em.K,
  731. masterHostName: 'host1'
  732. });
  733. this.mock = sinon.stub(App.Service, 'find');
  734. });
  735. afterEach(function () {
  736. this.mock.restore();
  737. });
  738. it("service not installed", function() {
  739. this.mock.returns(Em.Object.create({isLoaded: false}));
  740. view.createCustomAction();
  741. var args = testHelpers.findAjaxRequest('name', 'custom_action.create');
  742. expect(args[0]).exists;
  743. });
  744. it("service is installed", function() {
  745. this.mock.returns(Em.Object.create({isLoaded: true}));
  746. view.createCustomAction();
  747. var args = testHelpers.findAjaxRequest('name', 'cluster.custom_action.create');
  748. expect(args[0]).exists;
  749. });
  750. });
  751. });
  752. describe('App.BaseUrlTextField', function () {
  753. var view = App.BaseUrlTextField.create({
  754. repository: Em.Object.create({
  755. baseUrl: 'val'
  756. }),
  757. parentView: Em.Object.create({
  758. uiValidation: Em.K
  759. })
  760. });
  761. describe('#valueWasChanged', function () {
  762. it('should be recalculated after value is changed', function () {
  763. view.setProperties({
  764. value: 'val',
  765. defaultValue: 'val'
  766. });
  767. expect(view.get('valueWasChanged')).to.be.false;
  768. view.set('value', 'newVal');
  769. expect(view.get('valueWasChanged')).to.be.true;
  770. });
  771. });
  772. describe('#restoreValue()', function () {
  773. it('should unset value', function () {
  774. view.setProperties({
  775. value: 'valNew',
  776. defaultValue: 'val'
  777. });
  778. view.restoreValue();
  779. expect(view.get('value')).to.equal('val');
  780. });
  781. });
  782. describe('#didInsertElement()', function () {
  783. it('should set defaultValue', function () {
  784. view.setProperties({
  785. value: 'valNew',
  786. defaultValue: 'val'
  787. });
  788. view.didInsertElement();
  789. expect(view.get('defaultValue')).to.equal('valNew');
  790. });
  791. });
  792. describe('#validate()', function () {
  793. beforeEach(function(){
  794. sinon.stub(view.get('parentView'), 'uiValidation', Em.K);
  795. sinon.stub(validator, 'isValidBaseUrl').returns(true);
  796. });
  797. afterEach(function(){
  798. view.get('parentView').uiValidation.restore();
  799. validator.isValidBaseUrl.restore();
  800. });
  801. it('skip validation', function () {
  802. view.set('repository', Em.Object.create({
  803. skipValidation: true
  804. }));
  805. expect(view.get('repository.hasError')).to.be.false;
  806. });
  807. it('apply validation', function () {
  808. view.set('repository', Em.Object.create({
  809. skipValidation: false
  810. }));
  811. expect(view.get('repository.hasError')).to.be.false;
  812. expect(validator.isValidBaseUrl.calledOnce).to.be.true;
  813. });
  814. });
  815. });