selectDropdownCtrl-specs.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. define([
  2. 'directives/variableValueSelect',
  3. ],
  4. function () {
  5. 'use strict';
  6. describe("SelectDropdownCtrl", function() {
  7. var scope;
  8. var ctrl;
  9. var tagValuesMap = {};
  10. var rootScope;
  11. beforeEach(module('grafana.controllers'));
  12. beforeEach(inject(function($controller, $rootScope, $q) {
  13. rootScope = $rootScope;
  14. scope = $rootScope.$new();
  15. ctrl = $controller('SelectDropdownCtrl', {$scope: scope});
  16. ctrl.getValuesForTag = function(obj) {
  17. return $q.when(tagValuesMap[obj.tagKey]);
  18. };
  19. }));
  20. describe("Given simple variable", function() {
  21. beforeEach(function() {
  22. ctrl.variable = {current: {text: 'hej', value: 'hej' }};
  23. ctrl.init();
  24. });
  25. it("Should init labelText and linkText", function() {
  26. expect(ctrl.linkText).to.be("hej");
  27. });
  28. });
  29. describe("Given variable with tags and dropdown is opened", function() {
  30. beforeEach(function() {
  31. ctrl.variable = {
  32. current: {text: 'hej', value: 'hej'},
  33. options: [
  34. {text: 'server-1', value: 'server-1'},
  35. {text: 'server-2', value: 'server-2'},
  36. {text: 'server-3', value: 'server-3'},
  37. ],
  38. tags: ["key1", "key2", "key3"]
  39. };
  40. tagValuesMap.key1 = ['server-1', 'server-3'];
  41. tagValuesMap.key2 = ['server-2', 'server-3'];
  42. tagValuesMap.key3 = ['server-1', 'server-2', 'server-3'];
  43. ctrl.init();
  44. ctrl.show();
  45. });
  46. it("should init tags model", function() {
  47. expect(ctrl.tags.length).to.be(3);
  48. expect(ctrl.tags[0].text).to.be("key1");
  49. });
  50. it("should init options model", function() {
  51. expect(ctrl.options.length).to.be(3);
  52. });
  53. describe('When tag is selected', function() {
  54. beforeEach(function() {
  55. ctrl.selectTag(ctrl.tags[0]);
  56. rootScope.$digest();
  57. });
  58. it("should select tag", function() {
  59. expect(ctrl.selectedTags.length).to.be(1);
  60. });
  61. it("should select values", function() {
  62. expect(ctrl.options[0].selected).to.be(true);
  63. expect(ctrl.options[2].selected).to.be(true);
  64. });
  65. describe('and then dropdown is opened and closed without changes', function() {
  66. beforeEach(function() {
  67. ctrl.show();
  68. ctrl.commitChanges();
  69. rootScope.$digest();
  70. });
  71. it("should still have selected tag", function() {
  72. expect(ctrl.selectedTags.length).to.be(1);
  73. });
  74. });
  75. describe('and then unselected', function() {
  76. beforeEach(function() {
  77. ctrl.selectTag(ctrl.tags[0]);
  78. rootScope.$digest();
  79. });
  80. it("should deselect tag", function() {
  81. expect(ctrl.selectedTags.length).to.be(0);
  82. });
  83. });
  84. describe('and then value is unselected', function() {
  85. beforeEach(function() {
  86. ctrl.optionSelected(ctrl.options[0]);
  87. });
  88. it("should deselect tag", function() {
  89. expect(ctrl.selectedTags.length).to.be(0);
  90. });
  91. });
  92. });
  93. });
  94. });
  95. });