debian-mirror-gitlab/spec/models/work_items/widget_definition_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
3.2 KiB
Ruby
Raw Permalink Normal View History

2023-04-23 21:23:45 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe WorkItems::WidgetDefinition, feature_category: :team_planning do
let(:all_widget_classes) do
list = [
::WorkItems::Widgets::Description,
::WorkItems::Widgets::Hierarchy,
::WorkItems::Widgets::Labels,
::WorkItems::Widgets::Assignees,
::WorkItems::Widgets::StartAndDueDate,
::WorkItems::Widgets::Milestone,
2023-05-27 22:25:52 +05:30
::WorkItems::Widgets::Notes,
2023-06-20 00:43:36 +05:30
::WorkItems::Widgets::Notifications,
::WorkItems::Widgets::CurrentUserTodos,
::WorkItems::Widgets::AwardEmoji
2023-04-23 21:23:45 +05:30
]
if Gitlab.ee?
list += [
::WorkItems::Widgets::Iteration,
::WorkItems::Widgets::Weight,
::WorkItems::Widgets::Status,
::WorkItems::Widgets::HealthStatus,
::WorkItems::Widgets::Progress,
::WorkItems::Widgets::RequirementLegacy,
::WorkItems::Widgets::TestReports
]
end
list
end
describe 'associations' do
it { is_expected.to belong_to(:namespace) }
it { is_expected.to belong_to(:work_item_type) }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_uniqueness_of(:name).case_insensitive.scoped_to([:namespace_id, :work_item_type_id]) }
it { is_expected.to validate_length_of(:name).is_at_most(255) }
end
context 'with some widgets disabled' do
before do
described_class.global.where(widget_type: :notes).update_all(disabled: true)
end
describe '.available_widgets' do
subject { described_class.available_widgets }
it 'returns all global widgets excluding the disabled ones' do
# WorkItems::Widgets::Notes is excluded from widget class because:
# * although widget_definition below is enabled and uses notes widget, it's namespaced (has namespace != nil)
# * available_widgets takes into account only global definitions (which have namespace=nil)
namespace = create(:namespace)
create(:widget_definition, namespace: namespace, widget_type: :notes)
is_expected.to match_array(all_widget_classes - [::WorkItems::Widgets::Notes])
end
it 'returns all global widgets if there is at least one global widget definition which is enabled' do
create(:widget_definition, namespace: nil, widget_type: :notes)
is_expected.to match_array(all_widget_classes)
end
end
describe '.widget_classes' do
subject { described_class.widget_classes }
it 'returns all widget classes no matter if disabled or not' do
is_expected.to match_array(all_widget_classes)
end
end
end
describe '#widget_class' do
it 'returns widget class based on widget_type' do
expect(build(:widget_definition, widget_type: :description).widget_class).to eq(::WorkItems::Widgets::Description)
end
it 'returns nil if there is no class for the widget_type' do
described_class.first.update_column(:widget_type, -1)
expect(described_class.first.widget_class).to be_nil
end
it 'returns nil if there is no class for the widget_type' do
expect(build(:widget_definition, widget_type: nil).widget_class).to be_nil
end
end
end