Skip to content

Commit

Permalink
Merge pull request #4529 from hstastna/Incorrect_title_displaying_Dat…
Browse files Browse the repository at this point in the history
…astore_details

Fix incorrect title while displaying Datastore details page
  • Loading branch information
h-kataria committed Aug 28, 2018
2 parents 2cddff2 + ef055df commit 0664fa8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
16 changes: 14 additions & 2 deletions app/controllers/storage_controller.rb
Expand Up @@ -328,12 +328,12 @@ def features

def get_node_info(node, _show_list = true)
node = valid_active_node(node)
session_reset # Reset session to same values as first time in
case x_active_tree
when :storage_tree then storage_get_node_info(node)
when :storage_pod_tree then storage_pod_get_node_info(node)
end
@right_cell_text += _(" (Names with \"%{search_text}\")") % {:search_text => @search_text} if @search_text.present?
@right_cell_text += @edit[:adv_search_applied][:text] if x_tree && x_tree[:type] == :storage && @edit && @edit[:adv_search_applied]
set_right_cell_text

if @edit && @edit.fetch_path(:adv_search_applied, :qs_exp) # If qs is active, save it in history
x_history_add_item(:id => x_node,
Expand Down Expand Up @@ -493,6 +493,18 @@ def storage_scan

private

def session_reset
if @record
session[:edit] = @edit = nil
session[:adv_search]['Storage'] = nil if session[:adv_search]
end
end

def set_right_cell_text
@right_cell_text += _(" (Names with \"%{search_text}\")") % {:search_text => @search_text} if @search_text.present? && @nodetype != 'ds'
@right_cell_text += @edit[:adv_search_applied][:text] if x_tree && x_tree[:type] == :storage && @edit && @edit[:adv_search_applied]
end

def textual_group_list
[
%i(properties registered_vms relationships),
Expand Down
54 changes: 46 additions & 8 deletions spec/controllers/storage_controller_spec.rb
Expand Up @@ -271,6 +271,7 @@

before do
allow(controller).to receive(:render).and_return(true)
allow(controller).to receive(:build_accordions_and_trees)

controller.instance_variable_set(:@record, datastore)
controller.instance_variable_set(:@sb, :active_tree => :storage_tree)
Expand Down Expand Up @@ -396,17 +397,54 @@
end

describe '#get_node_info' do
before do
controller.instance_variable_set(:@right_cell_text, "")
controller.instance_variable_set(:@search_text, search)
context 'resetting session' do
let(:datastore) { FactoryGirl.create(:storage, :name => 'storage_name') }

before do
allow(controller).to receive(:session).and_return(:edit => {}, :adv_search => {'Storage' => {}})
controller.instance_variable_set(:@edit, {})
controller.instance_variable_set(:@record, datastore)
end

it 'calls session_reset method' do
expect(controller).to receive(:session_reset)
controller.send(:get_node_info, 'root')
end

it 'resets session to same values as first time in' do
controller.send(:session_reset)
expect(controller.instance_variable_get(:@edit)).to be(nil)
expect(controller.session).to eq(:edit => nil, :adv_search => {'Storage' => nil})
end
end

context 'searching text' do
let(:search) { "Datastore" }
context 'setting right cell text' do
before do
controller.instance_variable_set(:@right_cell_text, 'All Datastores')
end

it 'updates right cell text according to search text' do
controller.send(:get_node_info, "root")
expect(controller.instance_variable_get(:@right_cell_text)).to eq(" (Names with \"#{search}\")")
context 'searching text' do
before do
controller.instance_variable_set(:@search_text, 'Datastore')
end

it 'updates right cell text according to search text' do
controller.send(:get_node_info, 'root')
expect(controller.instance_variable_get(:@right_cell_text)).to eq("All Datastores (Names with \"Datastore\")")
end
end

context 'using Advanced Search' do
before do
allow(controller).to receive(:x_tree).and_return(:type => :storage)
allow(controller).to receive(:valid_active_node).and_return('ms-1')
controller.instance_variable_set(:@edit, :adv_search_applied => {:text => " - Filtered by \"Filter1\""})
end

it 'updates right cell text according to chosen filter' do
controller.send(:get_node_info, 'ms-1')
expect(controller.instance_variable_get(:@right_cell_text)).to eq("All Datastores - Filtered by \"Filter1\"")
end
end
end
end
Expand Down

0 comments on commit 0664fa8

Please sign in to comment.