2023-05-27 22:25:52 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Sidebars::StaticMenu, feature_category: :navigation do
|
|
|
|
let(:context) { {} }
|
|
|
|
|
|
|
|
subject { described_class.new(context) }
|
|
|
|
|
|
|
|
describe '#serialize_for_super_sidebar' do
|
|
|
|
it 'returns flat list of all menu items' do
|
2023-06-20 00:43:36 +05:30
|
|
|
subject.add_item(Sidebars::MenuItem.new(item_id: 'id1', title: 'Is active', link: 'foo2',
|
|
|
|
active_routes: { controller: 'fooc' }))
|
|
|
|
subject.add_item(Sidebars::MenuItem.new(item_id: 'id2', title: 'Not active', link: 'foo3',
|
|
|
|
active_routes: { controller: 'barc' }))
|
2023-05-27 22:25:52 +05:30
|
|
|
subject.add_item(Sidebars::NilMenuItem.new(item_id: 'nil_item'))
|
|
|
|
|
|
|
|
allow(context).to receive(:route_is_active).and_return(->(x) { x[:controller] == 'fooc' })
|
|
|
|
|
|
|
|
expect(subject.serialize_for_super_sidebar).to eq(
|
|
|
|
[
|
|
|
|
{
|
2023-06-20 00:43:36 +05:30
|
|
|
id: 'id1',
|
2023-05-27 22:25:52 +05:30
|
|
|
title: "Is active",
|
|
|
|
icon: nil,
|
|
|
|
link: "foo2",
|
|
|
|
is_active: true,
|
2023-07-09 08:55:56 +05:30
|
|
|
pill_count: nil,
|
|
|
|
link_classes: nil
|
2023-05-27 22:25:52 +05:30
|
|
|
},
|
|
|
|
{
|
2023-06-20 00:43:36 +05:30
|
|
|
id: 'id2',
|
2023-05-27 22:25:52 +05:30
|
|
|
title: "Not active",
|
|
|
|
icon: nil,
|
|
|
|
link: "foo3",
|
|
|
|
is_active: false,
|
2023-07-09 08:55:56 +05:30
|
|
|
pill_count: nil,
|
|
|
|
link_classes: nil
|
2023-05-27 22:25:52 +05:30
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|