diff --git a/octavia_dashboard/static/dashboard/project/lbaasv2/widgets/filterselect/filter-select.component.js b/octavia_dashboard/static/dashboard/project/lbaasv2/widgets/filterselect/filter-select.component.js index b03f1e6d..78e5e9b9 100644 --- a/octavia_dashboard/static/dashboard/project/lbaasv2/widgets/filterselect/filter-select.component.js +++ b/octavia_dashboard/static/dashboard/project/lbaasv2/widgets/filterselect/filter-select.component.js @@ -134,6 +134,8 @@ ctrl.isOpen = false; // Arrays of text to be displayed ctrl.rows = []; + // Array of non-rendered options after filter apply + ctrl.filtered_options = []; // Lifecycle methods ctrl.$onInit = function() { @@ -184,7 +186,7 @@ }; ctrl.selectOption = function(index) { - var option = ctrl.options[index]; + var option = ctrl.filtered_options[index]; ctrl.onSelect({ option: option }); @@ -218,11 +220,13 @@ }; ctrl._buildRows = function() { + ctrl.filtered_options.length = 0; ctrl.rows.length = 0; angular.forEach(ctrl.options, function(option) { var row = ctrl._buildRow(option); if (row) { ctrl.rows.push(row); + ctrl.filtered_options.push(option); } }); }; diff --git a/octavia_dashboard/static/dashboard/project/lbaasv2/widgets/filterselect/filter-select.component.spec.js b/octavia_dashboard/static/dashboard/project/lbaasv2/widgets/filterselect/filter-select.component.spec.js index d5872573..66292731 100644 --- a/octavia_dashboard/static/dashboard/project/lbaasv2/widgets/filterselect/filter-select.component.spec.js +++ b/octavia_dashboard/static/dashboard/project/lbaasv2/widgets/filterselect/filter-select.component.spec.js @@ -188,6 +188,19 @@ }); expect(ctrl.isOpen).toBe(false); }); + + it('should select correct option after filter input', function() { + var mockInput = '2'; + ctrl.text = mockInput; + ctrl.onTextChange(); + ctrl.selectOption(0); + expect(ctrl.onSelect).toHaveBeenCalledWith({ + option: mockOptions[1] + }); + expect(ctrl.filtered_options.length).toBe(1); + expect(ctrl.filtered_options[0].text).toContain(mockInput); + expect(ctrl.isOpen).toBe(false); + }); }); describe('controller', function() {