host_test.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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('utils/batch_scheduled_requests');
  20. require('controllers/main/host');
  21. require('mappers/server_data_mapper');
  22. describe('MainHostController', function () {
  23. var hostController, db;
  24. beforeEach(function () {
  25. hostController = App.MainHostController.create({});
  26. });
  27. afterEach(function () {
  28. hostController.destroy();
  29. });
  30. describe('#getRegExp()', function() {
  31. var message = '`{0}` should convert to `{1}`',
  32. tests = [
  33. { value: '.*', expected: '.*' },
  34. { value: '.', expected: '.*' },
  35. { value: '.*.*', expected: '.*' },
  36. { value: '*', expected: '^$' },
  37. { value: '........', expected: '.*' },
  38. { value: '........*', expected: '.*' },
  39. { value: 'a1', expected: '.*a1.*' },
  40. { value: 'a1.', expected: '.*a1.*' },
  41. { value: 'a1...', expected: '.*a1.*' },
  42. { value: 'a1.*', expected: '.*a1.*' },
  43. { value: 'a1.*.a2.a3', expected: '.*a1.*.a2.a3.*' },
  44. { value: 'a1.*.a2...a3', expected: '.*a1.*.a2...a3.*' }
  45. ];
  46. tests.forEach(function(test){
  47. it(message.format(test.value, test.expected), function() {
  48. expect(hostController.getRegExp(test.value)).to.be.equal(test.expected);
  49. });
  50. });
  51. });
  52. describe('#getQueryParameters', function() {
  53. beforeEach(function() {
  54. sinon.spy(hostController, 'getRegExp');
  55. sinon.stub(App.db, 'getFilterConditions', function() {
  56. return [{
  57. iColumn: 1,
  58. skipFilter: false,
  59. type: "string",
  60. value: "someval"
  61. }];
  62. });
  63. });
  64. afterEach(function() {
  65. App.db.getFilterConditions.restore();
  66. hostController.getRegExp.restore();
  67. });
  68. it('should call #getRegExp with value `someval` on host name filter', function() {
  69. hostController.getQueryParameters();
  70. expect(hostController.getRegExp.calledWith('someval')).to.ok;
  71. });
  72. it('result should include host name filter converted value', function() {
  73. expect(hostController.getQueryParameters().findProperty('key', 'Hosts/host_name').value).to.equal('.*someval.*');
  74. });
  75. });
  76. describe('#getSortProps', function () {
  77. beforeEach(function () {
  78. db = {mainHostController: [
  79. {name: 'hostName', status: 'sorting'}
  80. ]};
  81. sinon.stub(App.db, 'getSortingStatuses', function (k) {
  82. return db[k];
  83. });
  84. sinon.stub(App.db, 'setSortingStatuses', function (k, v) {
  85. db[k] = Em.typeOf(v) === 'array' ? v : [v];
  86. });
  87. });
  88. afterEach(function () {
  89. App.db.getSortingStatuses.restore();
  90. App.db.setSortingStatuses.restore();
  91. });
  92. it('should set default sorting condition', function () {
  93. hostController.getSortProps();
  94. expect(db.mainHostController).to.eql([{name: 'hostName', status: 'sorting_asc'}]);
  95. });
  96. });
  97. });