application_test.js 3.4 KB

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