controls_view_test.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  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. describe('#disabled', function () {
  413. var cases = [
  414. {
  415. wizardControllerName: 'addServiceController',
  416. value: 'New MySQL Database',
  417. title: 'Add Service Wizard, new database',
  418. disabled: false
  419. },
  420. {
  421. wizardControllerName: 'installerController',
  422. value: 'New MySQL Database',
  423. title: 'Install Wizard, new database',
  424. disabled: false
  425. },
  426. {
  427. wizardControllerName: 'addServiceController',
  428. value: 'Existing MySQL Database',
  429. title: 'Add Service Wizard, existing database',
  430. disabled: false
  431. },
  432. {
  433. wizardControllerName: 'installerController',
  434. value: 'Existing MySQL Database',
  435. title: 'Install Wizard, existing database',
  436. disabled: false
  437. },
  438. {
  439. wizardControllerName: null,
  440. value: 'New MySQL Database',
  441. title: 'No installer, new database',
  442. disabled: true
  443. },
  444. {
  445. wizardControllerName: null,
  446. value: 'Existing MySQL Database',
  447. title: 'No installer, existing database',
  448. disabled: false
  449. }
  450. ];
  451. cases.forEach(function (item) {
  452. it(item.title, function () {
  453. var view = App.ServiceConfigRadioButton.create({
  454. parentView: Em.Object.create({
  455. serviceConfig: Em.Object.create()
  456. }),
  457. controller: Em.Object.create({
  458. wizardController: Em.Object.create({
  459. name: null
  460. })
  461. })
  462. });
  463. view.set('value', item.value);
  464. view.set('controller.wizardController.name', item.wizardControllerName);
  465. view.set('parentView.serviceConfig.isEditable', true);
  466. expect(view.get('disabled')).to.equal(item.disabled);
  467. });
  468. });
  469. it('parent view is disabled', function () {
  470. var view = App.ServiceConfigRadioButton.create({
  471. parentView: Em.Object.create({
  472. serviceConfig: Em.Object.create()
  473. })
  474. });
  475. view.set('parentView.serviceConfig.isEditable', false);
  476. expect(view.get('disabled')).to.be.true;
  477. });
  478. });
  479. });
  480. describe('App.CheckDBConnectionView', function () {
  481. describe('#masterHostName', function () {
  482. var cases = [
  483. {
  484. serviceName: 'OOZIE',
  485. value: 'h0'
  486. },
  487. {
  488. serviceName: 'KERBEROS',
  489. value: 'h1'
  490. },
  491. {
  492. serviceName: 'HIVE',
  493. value: 'h2'
  494. },
  495. {
  496. serviceName: 'RANGER',
  497. value: 'h3'
  498. }
  499. ],
  500. categoryConfigsAll = [
  501. Em.Object.create({
  502. name: 'oozie_server_hosts',
  503. value: 'h0'
  504. }),
  505. Em.Object.create({
  506. name: 'kdc_host',
  507. value: 'h1'
  508. }),
  509. Em.Object.create({
  510. name: 'hive_metastore_hosts',
  511. value: 'h2'
  512. }),
  513. Em.Object.create({
  514. name: 'ranger_server_hosts',
  515. value: 'h3'
  516. })
  517. ];
  518. cases.forEach(function (item) {
  519. it(item.serviceName, function () {
  520. var view = App.CheckDBConnectionView.create({
  521. parentView: {
  522. service: {
  523. serviceName: item.serviceName
  524. },
  525. categoryConfigsAll: categoryConfigsAll
  526. }
  527. });
  528. expect(view.get('masterHostName')).to.equal(item.value);
  529. });
  530. });
  531. });
  532. describe('#setResponseStatus', function () {
  533. var view,
  534. cases = [
  535. {
  536. isSuccess: 'success',
  537. logsPopupBefore: null,
  538. logsPopup: null,
  539. responseCaption: Em.I18n.t('services.service.config.database.connection.success'),
  540. isConnectionSuccess: true,
  541. title: 'success, no popup displayed'
  542. },
  543. {
  544. isSuccess: 'success',
  545. logsPopupBefore: {},
  546. logsPopup: {
  547. header: Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.success'))
  548. },
  549. responseCaption: Em.I18n.t('services.service.config.database.connection.success'),
  550. isConnectionSuccess: true,
  551. title: 'success, popup is displayed'
  552. },
  553. {
  554. isSuccess: 'error',
  555. logsPopupBefore: {},
  556. logsPopup: {
  557. header: Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.error'))
  558. },
  559. responseCaption: Em.I18n.t('services.service.config.database.connection.failed'),
  560. isConnectionSuccess: false,
  561. title: 'error, popup is displayed'
  562. }
  563. ];
  564. beforeEach(function () {
  565. view = App.CheckDBConnectionView.create({
  566. databaseName: 'MySQL'
  567. });
  568. sinon.stub(view, 'setConnectingStatus', Em.K);
  569. });
  570. afterEach(function () {
  571. view.setConnectingStatus.restore();
  572. });
  573. cases.forEach(function (item) {
  574. describe(item.title, function () {
  575. beforeEach(function () {
  576. view.set('logsPopup', item.logsPopupBefore);
  577. view.setResponseStatus(item.isSuccess);
  578. });
  579. it('isRequestResolved is true', function () {
  580. expect(view.get('isRequestResolved')).to.be.true;
  581. });
  582. it('setConnectingStatus is called with valid arguments', function () {
  583. expect(view.setConnectingStatus.calledOnce).to.be.true;
  584. expect(view.setConnectingStatus.calledWith(false)).to.be.true;
  585. });
  586. it('responseCaption is valid', function () {
  587. expect(view.get('responseCaption')).to.equal(item.responseCaption);
  588. });
  589. it('isConnectionSuccess is valid', function () {
  590. expect(view.get('isConnectionSuccess')).to.equal(item.isConnectionSuccess);
  591. });
  592. it('logsPopup is valid', function () {
  593. expect(view.get('logsPopup')).to.eql(item.logsPopup);
  594. });
  595. });
  596. });
  597. });
  598. describe('#showLogsPopup', function () {
  599. var view;
  600. beforeEach(function () {
  601. view = App.CheckDBConnectionView.create({
  602. databaseName: 'MySQL'
  603. });
  604. sinon.spy(App, 'showAlertPopup');
  605. });
  606. afterEach(function () {
  607. App.showAlertPopup.restore();
  608. });
  609. it('successful connection', function () {
  610. view.set('isConnectionSuccess', true);
  611. view.showLogsPopup();
  612. expect(App.showAlertPopup.callCount).to.equal(0);
  613. });
  614. describe('failed connection without output data, popup dismissed with Close button', function () {
  615. beforeEach(function () {
  616. view.set('isConnectionSuccess', false);
  617. view.set('isRequestResolved', true);
  618. view.set('responseFromServer', 'fail');
  619. view.showLogsPopup();
  620. });
  621. it('showAlertPopup is called once', function () {
  622. expect(App.showAlertPopup.callCount).to.equal(1);
  623. });
  624. it('logsPopup.header is valid', function () {
  625. expect(view.get('logsPopup.header')).to.equal(Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.error')));
  626. });
  627. it('logsPopup.body is valid', function () {
  628. expect(view.get('logsPopup.body')).to.equal('fail');
  629. });
  630. it('logsPopup is null after close', function () {
  631. view.get('logsPopup').onClose();
  632. expect(view.get('logsPopup')).to.be.null;
  633. });
  634. });
  635. describe('check in progress with output data, popup dismissed with OK button', function () {
  636. var response = {
  637. stderr: 'stderr',
  638. stdout: 'stdout',
  639. structuredOut: 'structuredOut'
  640. };
  641. beforeEach(function () {
  642. view.set('isConnectionSuccess', false);
  643. view.set('isRequestResolved', false);
  644. view.set('responseFromServer', response);
  645. view.showLogsPopup();
  646. });
  647. it('showAlertPopup is called once', function () {
  648. expect(App.showAlertPopup.callCount).to.equal(1);
  649. });
  650. it('logsPopup.header is valid', function () {
  651. expect(view.get('logsPopup.header')).to.equal(Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.testing')));
  652. });
  653. it('logsPopup.bodyClass is valid', function () {
  654. expect(view.get('logsPopup.bodyClass').create().get('openedTask')).to.eql(response);
  655. });
  656. it('logsPopup is null after primary click', function () {
  657. view.get('logsPopup').onPrimary();
  658. expect(view.get('logsPopup')).to.be.null;
  659. });
  660. });
  661. });
  662. describe("#createCustomAction()", function() {
  663. var view;
  664. beforeEach(function () {
  665. view = App.CheckDBConnectionView.create({
  666. databaseName: 'MySQL',
  667. getConnectionProperty: Em.K,
  668. masterHostName: 'host1'
  669. });
  670. this.mock = sinon.stub(App.Service, 'find');
  671. });
  672. afterEach(function () {
  673. this.mock.restore();
  674. });
  675. it("service not installed", function() {
  676. this.mock.returns(Em.Object.create({isLoaded: false}));
  677. view.createCustomAction();
  678. var args = testHelpers.findAjaxRequest('name', 'custom_action.create');
  679. expect(args[0]).exists;
  680. });
  681. it("service is installed", function() {
  682. this.mock.returns(Em.Object.create({isLoaded: true}));
  683. view.createCustomAction();
  684. var args = testHelpers.findAjaxRequest('name', 'cluster.custom_action.create');
  685. expect(args[0]).exists;
  686. });
  687. });
  688. });
  689. describe('App.BaseUrlTextField', function () {
  690. var view = App.BaseUrlTextField.create({
  691. repository: Em.Object.create({
  692. baseUrl: 'val'
  693. }),
  694. parentView: Em.Object.create({
  695. uiValidation: Em.K
  696. })
  697. });
  698. describe('#valueWasChanged', function () {
  699. it('should be recalculated after value is changed', function () {
  700. view.setProperties({
  701. value: 'val',
  702. defaultValue: 'val'
  703. });
  704. expect(view.get('valueWasChanged')).to.be.false;
  705. view.set('value', 'newVal');
  706. expect(view.get('valueWasChanged')).to.be.true;
  707. });
  708. });
  709. describe('#restoreValue()', function () {
  710. it('should unset value', function () {
  711. view.setProperties({
  712. value: 'valNew',
  713. defaultValue: 'val'
  714. });
  715. view.restoreValue();
  716. expect(view.get('value')).to.equal('val');
  717. });
  718. });
  719. describe('#didInsertElement()', function () {
  720. it('should set defaultValue', function () {
  721. view.setProperties({
  722. value: 'valNew',
  723. defaultValue: 'val'
  724. });
  725. view.didInsertElement();
  726. expect(view.get('defaultValue')).to.equal('valNew');
  727. });
  728. });
  729. describe('#validate()', function () {
  730. beforeEach(function(){
  731. sinon.stub(view.get('parentView'), 'uiValidation', Em.K);
  732. sinon.stub(validator, 'isValidBaseUrl').returns(true);
  733. });
  734. afterEach(function(){
  735. view.get('parentView').uiValidation.restore();
  736. validator.isValidBaseUrl.restore();
  737. });
  738. it('skip validation', function () {
  739. view.set('repository', Em.Object.create({
  740. skipValidation: true
  741. }));
  742. expect(view.get('repository.hasError')).to.be.false;
  743. });
  744. it('apply validation', function () {
  745. view.set('repository', Em.Object.create({
  746. skipValidation: false
  747. }));
  748. expect(view.get('repository.hasError')).to.be.false;
  749. expect(validator.isValidBaseUrl.calledOnce).to.be.true;
  750. });
  751. });
  752. });