From ce00be77e68fc6258b8e6bbe6e1d04456e78313c Mon Sep 17 00:00:00 2001 From: Hauke Klement Date: Fri, 27 Feb 2015 09:30:26 +0100 Subject: [PATCH] added tests --- spec/lib/file_tree_spec.rb | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/spec/lib/file_tree_spec.rb b/spec/lib/file_tree_spec.rb index 4e0d3671..963ec8fa 100644 --- a/spec/lib/file_tree_spec.rb +++ b/spec/lib/file_tree_spec.rb @@ -73,6 +73,52 @@ describe FileTree do end end + describe '#map_to_js_tree' do + let(:file) { FactoryGirl.build(:file) } + let(:js_tree) { file_tree.send(:map_to_js_tree, node) } + let!(:leaf) { root.add(Tree::TreeNode.new('', file)) } + let(:root) { Tree::TreeNode.new('', file) } + + context 'for a leaf node' do + let(:node) { leaf } + + it 'produces the required attributes' do + expect(js_tree).to include(:icon, :id, :text) + end + + it 'is enabled' do + expect(js_tree[:state][:disabled]).to be false + end + + it 'is closed' do + expect(js_tree[:state][:opened]).to be false + end + end + + context 'for a non-leaf node' do + let(:node) { root } + + it "traverses the node's children" do + node.children.each do |child| + expect(file_tree).to receive(:map_to_js_tree).at_least(:once).with(child).and_call_original + end + js_tree + end + + it 'produces the required attributes' do + expect(js_tree).to include(:icon, :id, :text) + end + + it 'is disabled' do + expect(js_tree[:state][:disabled]).to be true + end + + it 'is opened' do + expect(js_tree[:state][:opened]).to be true + end + end + end + describe '#node_icon' do let(:node_icon) { file_tree.send(:node_icon, node) } let(:root) { Tree::TreeNode.new('') }