application_test.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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('models/cluster');
  20. var testHelpers = require('test/helpers');
  21. function getController() {
  22. return App.ApplicationController.create();
  23. }
  24. describe('App.ApplicationController', function () {
  25. var applicationController = getController();
  26. App.TestAliases.testAsComputedTruncate(getController(), 'clusterDisplayName', 'clusterName', 13, 10);
  27. App.TestAliases.testAsComputedAnd(getController(), 'isClusterDataLoaded', ['App.router.clusterController.isLoaded','App.router.loggedIn']);
  28. App.TestAliases.testAsComputedAnd(getController(), 'isExistingClusterDataLoaded', ['App.router.clusterInstallCompleted','isClusterDataLoaded']);
  29. App.TestAliases.testAsComputedAnd(getController(), 'enableLinks', ['isExistingClusterDataLoaded','!App.isOnlyViewUser']);
  30. describe('#showAboutPopup', function() {
  31. var dataToShowRes = {};
  32. beforeEach(function () {
  33. sinon.stub(App.ModalPopup, 'show', function(dataToShow){
  34. dataToShowRes = dataToShow;
  35. });
  36. });
  37. afterEach(function () {
  38. App.ModalPopup.show.restore();
  39. });
  40. it ('Should send correct data to popup', function() {
  41. applicationController.showAboutPopup();
  42. dataToShowRes = JSON.parse(JSON.stringify(dataToShowRes));
  43. expect(dataToShowRes).to.eql({
  44. "header": "About",
  45. "secondary": false
  46. });
  47. });
  48. });
  49. describe('#clusterName', function() {
  50. beforeEach(function () {
  51. sinon.stub(App.router, 'get').returns('cl1');
  52. });
  53. afterEach(function () {
  54. App.router.get.restore();
  55. });
  56. it ('Should return cluster name', function() {
  57. expect(applicationController.get('clusterName')).to.equal('cl1');
  58. });
  59. });
  60. describe('#startKeepAlivePoller', function() {
  61. it ('Should change run poller state', function() {
  62. applicationController.set('isPollerRunning', false);
  63. applicationController.startKeepAlivePoller();
  64. expect(applicationController.get('isPollerRunning')).to.be.true;
  65. });
  66. });
  67. describe('#goToAdminView', function() {
  68. var result;
  69. beforeEach(function () {
  70. sinon.stub(App.router, 'route', function(data) {
  71. result = data;
  72. return false;
  73. });
  74. });
  75. afterEach(function () {
  76. App.router.route.restore();
  77. });
  78. it ('Should call route once', function() {
  79. applicationController.goToAdminView();
  80. expect(result).to.be.equal('adminView');
  81. });
  82. });
  83. describe('#getStack', function() {
  84. it ('Should return send value', function() {
  85. var callback = {
  86. 'callback': true
  87. };
  88. applicationController.getStack(callback);
  89. var args = testHelpers.findAjaxRequest('name', 'router.login.clusters');
  90. expect(args[0]).to.exists;
  91. expect(args[0].callback.callback).to.be.true;
  92. });
  93. });
  94. });