require 'spec_helper' describe 'Locomotive::Steam::Liquid::Tags::Nav' do let(:index) { instance_double('IndexPage', fullpath: 'index', published: true) } let(:depth_1) do [ instance_double('Child1', title: 'Child #1', slug: 'child-1', fullpath: 'child-1', published?: true, listed?: true, templatized?: false, localized_attributes: [], to_liquid: { 'title' => 'Child #1' }), instance_double('Child2', title: 'Child #2', slug: 'child-2', fullpath: 'child-2', published?: true, listed?: true, templatized?: false, localized_attributes: [], to_liquid: { 'title' => 'Child #2' }) ] end let(:depth_2) do [ instance_double('Child2_1', title: 'Child #2.1', slug: 'child-2-1', fullpath: 'child-2/child-2-1', published?: true, listed?: true, templatized?: false, localized_attributes: []), instance_double('Child2_2', title: 'Child #2.2', slug: 'child-2-2', fullpath: 'child-2/child-2-2', published?: true, listed?: true, templatized?: false, localized_attributes: []), instance_double('UnpublishedChild2_3', title: 'Child #2.3', slug: 'child-2-3', fullpath: 'child-2/child-2-3', published?: false, listed?: true, templatized?: false, localized_attributes: []), instance_double('TemplatizedChild2_4', title: 'Child #2.4', slug: 'child-2-4', fullpath: 'child-2/child-2-4', published?: true, listed?: true, templatized?: true, localized_attributes: []), instance_double('UnlistedChild2_4', title: 'Child #2.5', slug: 'child-2-5', fullpath: 'child-2/child-2-5', published?: true, listed?: false, templatized?: false, localized_attributes: []) ] end let(:source) { '{% nav site %}' } let(:site) { instance_double('Site', name: 'My portfolio', default_locale: 'en') } let(:page) { index } let(:services) { Locomotive::Steam::Services.build_instance } let(:repository) { services.repositories.page } let(:assigns) { {} } let(:registers) { { services: services, site: site, page: page } } let(:context) { ::Liquid::Context.new(assigns, {}, registers) } let(:options) { { services: services } } let(:output) { render_template(source, context, options) } before { allow(services).to receive(:current_site).and_return(site) } describe 'rendering' do subject { output } describe 'from a site' do before do allow(repository).to receive(:root).and_return(index) allow(repository).to receive(:children_of).with(index).and_return(depth_1) end it { is_expected.to eq %{} } end describe 'from a page' do let(:source) { '{% nav page %}' } before do allow(repository).to receive(:children_of).with(index).and_return(depth_1) end it { is_expected.to eq %{} } end describe 'from the parent page' do let(:source) { '{% nav parent %}' } describe 'no parent page, use the current page instead' do before do allow(repository).to receive(:parent_of).with(index).and_return(nil) allow(repository).to receive(:children_of).with(index).and_return(depth_1) end it { is_expected.to eq %{} } end end describe 'from a page' do let(:source) { '{% nav index %}' } describe 'no parent page, use the current page instead' do before do allow(repository).to receive(:by_fullpath).with('index').and_return(index) allow(repository).to receive(:children_of).with(index).and_return(depth_1) end it { is_expected.to eq %{} } end end describe 'no wrapper' do let(:source) { '{% nav site, no_wrapper: true %}' } before do allow(repository).to receive(:root).and_return(index) allow(repository).to receive(:children_of).with(index).and_return(depth_1) end it { is_expected.to eq %{