Sha256: 00b2ff73ec0f982c89c6c21f955400486530866eed00d8f1f1bf26bf2b09725d

Contents?: true

Size: 1.9 KB

Versions: 25

Compression:

Stored size: 1.9 KB

Contents

require 'rails_helper'
require 'active_admin/menu'
require 'active_admin/menu_item'

include ActiveAdmin

describe ActiveAdmin::Menu do

  context "with no items" do
    it "should have an empty item collection" do
      menu = Menu.new
      expect(menu.items).to be_empty
    end

    it "should accept new items" do
      menu = Menu.new
      menu.add label: "Dashboard"
      expect(menu.items.first.label).to eq "Dashboard"
    end
  end

  context "with many items" do
    let(:menu) do
      Menu.new do |m|
        m.add label: "Dashboard"
        m.add label: "Blog"
      end
    end

    it "should give access to the menu item as an array" do
      expect(menu['Dashboard'].label).to eq 'Dashboard'
    end
  end

  describe "adding items with children" do
    it "should add an empty item if the parent does not exist" do
      menu = Menu.new
      menu.add parent: "Admin", label: "Users"

      expect(menu["Admin"]["Users"]).to be_an_instance_of(ActiveAdmin::MenuItem)
    end

    it "should add a child to a parent if it exists" do
      menu = Menu.new
      menu.add parent: "Admin", label: "Users"
      menu.add parent: "Admin", label: "Projects"

      expect(menu["Admin"]["Projects"]).to be_an_instance_of(ActiveAdmin::MenuItem)
    end

    it "should assign children regardless of resource file load order" do
      menu = Menu.new
      menu.add parent: "Users", label: "Posts"
      menu.add label: "Users", url: "/some/url"

      expect(menu["Users"].url).to eq "/some/url"
      expect(menu["Users"]["Posts"]).to be_a ActiveAdmin::MenuItem
    end
  end

  describe "sorting items" do
    it "should sort children by the result of their label proc" do
      menu = Menu.new
      menu.add label: proc{ "G" }, id: "not related 1"
      menu.add label: proc{ "B" }, id: "not related 2"
      menu.add label: proc{ "A" }, id: "not related 3"

      expect(menu.items.map(&:label)).to eq %w[A B G]
    end
  end
end

Version data entries

25 entries across 25 versions & 4 rubygems

Version Path
activeadmin_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/menu_spec.rb
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/menu_spec.rb
yousty-activeadmin-1.0.17.pre spec/unit/menu_spec.rb
yousty-activeadmin-1.0.16.pre spec/unit/menu_spec.rb
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/menu_spec.rb
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/menu_spec.rb
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/menu_spec.rb
yousty-activeadmin-1.0.15.pre spec/unit/menu_spec.rb
activeadmin-orac-1.0.0.pre4 spec/unit/menu_spec.rb
activeadmin-orac-1.0.0 spec/unit/menu_spec.rb
activeadmin-orac-1.0.0.pre.orac spec/unit/menu_spec.rb
yousty-activeadmin-1.0.14.pre spec/unit/menu_spec.rb
yousty-activeadmin-1.0.13.pre spec/unit/menu_spec.rb
yousty-activeadmin-1.0.12.pre spec/unit/menu_spec.rb
yousty-activeadmin-1.0.11.pre spec/unit/menu_spec.rb
yousty-activeadmin-1.0.10.pre spec/unit/menu_spec.rb
yousty-activeadmin-1.0.9.pre spec/unit/menu_spec.rb
yousty-activeadmin-1.0.8.pre spec/unit/menu_spec.rb
activeadmin-1.0.0.pre4 spec/unit/menu_spec.rb
activeadmin-1.0.0.pre3 spec/unit/menu_spec.rb