Skip to content

Commit

Permalink
Added new badge secondary for option like drafting
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvaiyanidhi committed Aug 16, 2023
1 parent 50bb423 commit f633d58
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
success: 'bg-green-500',
danger: 'bg-red-500',
warning: 'bg-yellow-500',
secondary: 'bg-gray-500',
}

label = @value
Expand Down
2 changes: 1 addition & 1 deletion db/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
factory :project do
name { Faker::App.name }
status { ['closed', :rejected, :failed, 'loading', :running, :waiting].sample }
stage { ["Discovery", "Idea", "Done", "On hold", "Cancelled"].sample }
stage { ["Discovery", "Idea", "Done", "On hold", "Cancelled", "Drafting"].sample }
budget { Faker::Number.decimal(l_digits: 4) }
country { Faker::Address.country_code }
description { Faker::Markdown.sandwich(sentences: 5) }
Expand Down
2 changes: 1 addition & 1 deletion lib/avo/fields/badge_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(id, **args, &block)

hide_on [:edit, :new]

default_options = {info: :info, success: :success, danger: :danger, warning: :warning}
default_options = {info: :info, success: :success, danger: :danger, warning: :warning, secondary: :secondary}
@options = args[:options].present? ? default_options.merge(args[:options]) : default_options
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/avo/resources/project_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ProjectResource < Avo::BaseResource
placeholder: "Choose the stage",
display_value: true,
include_blank: false
field :stage, as: :badge, options: {info: ["Discovery", "Idea"], success: "Done", warning: "On hold", danger: "Cancelled"}
field :stage, as: :badge, options: {info: ["Discovery", "Idea"], success: "Done", warning: "On hold", danger: "Cancelled", secondary: "Drafting"}
field :country,
as: :country,
index_text_align: :left,
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# progress :integer
#
class Project < ApplicationRecord
enum stage: {Discovery: "discovery", Idea: "idea", Done: "done", "On hold": "on hold", Cancelled: "cancelled"}
enum stage: {Discovery: "discovery", Idea: "idea", Done: "done", "On hold": "on hold", Cancelled: "cancelled", Drafting: "drafting"}

validates :name, presence: true
validates :users_required, numericality: {greater_than: 9, less_than: 1000000}
Expand Down
27 changes: 27 additions & 0 deletions spec/features/avo/badge_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,31 @@
it { is_expected.not_to have_css ".bg-blue-500" }
end
end

describe "with a secondary status" do
let!(:project) { create :project, stage: "drafting" }

subject {
visit url
find_field_element(:stage)
}

context "index" do
let!(:url) { "/admin/resources/projects" }

it { is_expected.to have_text "Drafting" }
it { is_expected.to have_css ".rounded-md" }
it { is_expected.to have_css ".bg-gray-500" }
it { is_expected.not_to have_css ".bg-blue-500" }
end

context "show" do
let!(:url) { "/admin/resources/projects/#{project.id}" }

it { is_expected.to have_text "Drafting" }
it { is_expected.to have_css ".rounded-md" }
it { is_expected.to have_css ".bg-gray-500" }
it { is_expected.not_to have_css ".bg-blue-500" }
end
end
end
22 changes: 22 additions & 0 deletions spec/features/avo/badge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@
is_expected.to have_css ".bg-red-500"
}
end

describe "with secondary value" do
let(:stage) { "Drafting" }
let!(:project) { create :project, users_required: 15, stage: stage }

it {
is_expected.to have_text stage
is_expected.to have_css ".rounded-md"
is_expected.to have_css ".bg-gray-500"
}
end
end

context "show" do
Expand Down Expand Up @@ -123,5 +134,16 @@
is_expected.to have_css ".bg-red-500"
}
end

describe "with secondary value" do
let(:stage) { "Drafting" }
let!(:project) { create :project, users_required: 15, stage: stage }

it {
is_expected.to have_text stage
is_expected.to have_css ".rounded-md"
is_expected.to have_css ".bg-gray-500"
}
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
end
end

let(:stages_without_placeholder) { ["discovery", "idea", "done", "on hold", "cancelled"] }
let(:stages_without_placeholder) { ["discovery", "idea", "done", "on hold", "cancelled", "Drafting"] }
let(:placeholder) { "Choose the stage" }
let(:stages_with_placeholder) { stages_without_placeholder.prepend(placeholder) }

Expand Down

0 comments on commit f633d58

Please sign in to comment.