-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6101 from chaimann/admin-promotion-categories-add…
…-edit Admin promotion categories add/edit
- Loading branch information
Showing
37 changed files
with
488 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
admin/lib/solidus_admin/testing_support/shared_examples/promotion_categories_features.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_examples_for 'promotion categories features' do | ||
before { sign_in create(:admin_user, email: "[email protected]") } | ||
|
||
it "lists promotion categories" do | ||
create(factory_name, name: "test1", code: "code1") | ||
create(factory_name, name: "test2", code: "code2") | ||
|
||
visit index_path | ||
expect(page).to have_content("test1") | ||
expect(page).to have_content("test2") | ||
|
||
expect(page).to be_axe_clean | ||
end | ||
|
||
it 'allows to create new promo category' do | ||
visit index_path | ||
|
||
click_on "Add new" | ||
expect(turbo_frame_modal).to have_content("New Promotion Category") | ||
|
||
fill_in "Code", with: "ste.1" | ||
click_on "Add Promotion Category" | ||
|
||
expect(turbo_frame_modal).to have_content("can't be blank") | ||
|
||
fill_in "Name", with: "Soon to expire" | ||
click_on "Add Promotion Category" | ||
|
||
expect(page).to have_content("Promotion Category was successfully created.") | ||
expect(page).to have_content("Soon to expire") | ||
expect(page).to have_content("ste.1") | ||
expect(model_class.count).to eq(1) | ||
end | ||
|
||
it 'allows to update promo category' do | ||
create(factory_name, name: "Soon to expire", code: "ste.1") | ||
|
||
visit index_path | ||
|
||
click_on "Soon to expire" | ||
expect(turbo_frame_modal).to have_content("Edit Promotion Category") | ||
|
||
fill_in "Name", with: "Expired" | ||
fill_in "Code", with: "exp.2" | ||
click_on "Update Promotion Category" | ||
|
||
expect(page).to have_content("Promotion Category was successfully updated.") | ||
expect(page).to have_content("Expired") | ||
expect(page).to have_content("exp.2") | ||
end | ||
|
||
it 'allows to delete promo category' do | ||
create(factory_name, name: "Soon to expire", code: "ste.1") | ||
create(factory_name, name: "Expired", code: "exp.2") | ||
|
||
visit index_path | ||
|
||
select_row("Expired") | ||
click_on "Delete" | ||
expect(page).to have_content("Promotion Categories were successfully removed.") | ||
expect(page).not_to have_content("Expired") | ||
expect(model_class.count).to eq(1) | ||
end | ||
end |
126 changes: 126 additions & 0 deletions
126
admin/lib/solidus_admin/testing_support/shared_examples/promotion_categories_requests.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_examples_for 'promotion categories requests' do | ||
let(:admin_user) { create(:admin_user) } | ||
|
||
before do | ||
allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(admin_user) | ||
end | ||
|
||
describe "GET /index" do | ||
it "renders the index template with a 200 OK status" do | ||
get url_helpers.promotion_categories_path | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
|
||
describe "GET /new" do | ||
it "renders the new template with a 200 OK status" do | ||
get url_helpers.new_promotion_category_path | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
|
||
describe "POST /create" do | ||
context "with valid parameters" do | ||
let(:valid_attributes) { { name: "Expired", code: "exp.1" } } | ||
let(:run_request) { post url_helpers.promotion_categories_path, params: { promotion_category: valid_attributes } } | ||
|
||
it "creates a new promotion category" do | ||
expect { run_request }.to change(model_class, :count).by(1) | ||
end | ||
|
||
it "redirects to the index page with a 303 See Other status" do | ||
run_request | ||
expect(response).to redirect_to(url_helpers.promotion_categories_path) | ||
expect(response).to have_http_status(:see_other) | ||
end | ||
|
||
it "displays a success flash message" do | ||
run_request | ||
follow_redirect! | ||
expect(response.body).to include("Promotion Category was successfully created.") | ||
end | ||
end | ||
|
||
context "with invalid parameters" do | ||
let(:invalid_attributes) { { name: "", code: "" } } | ||
let(:run_request) { post url_helpers.promotion_categories_path, params: { promotion_category: invalid_attributes } } | ||
|
||
it "does not create a new promotion category" do | ||
expect { run_request }.not_to change(model_class, :count) | ||
end | ||
|
||
it "renders the new template with unprocessable_entity status" do | ||
run_request | ||
expect(response).to have_http_status(:unprocessable_entity) | ||
end | ||
end | ||
end | ||
|
||
describe "GET /edit" do | ||
it "renders the edit template with a 200 OK status" do | ||
get url_helpers.edit_promotion_category_path(promotion_category) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
|
||
describe "PATCH /update" do | ||
context "with valid parameters" do | ||
let(:valid_attributes) { { name: "Updated", code: "upd.1" } } | ||
let(:run_request) { patch url_helpers.promotion_category_path(promotion_category), params: { promotion_category: valid_attributes } } | ||
|
||
it "updates the promotion category" do | ||
run_request | ||
promotion_category.reload | ||
expect(promotion_category.name).to eq("Updated") | ||
expect(promotion_category.code).to eq("upd.1") | ||
end | ||
|
||
it "redirects to the index page with a 303 See Other status" do | ||
run_request | ||
expect(response).to redirect_to(url_helpers.promotion_categories_path) | ||
expect(response).to have_http_status(:see_other) | ||
end | ||
|
||
it "displays a success flash message" do | ||
run_request | ||
follow_redirect! | ||
expect(response.body).to include("Promotion Category was successfully updated.") | ||
end | ||
end | ||
|
||
context "with invalid parameters" do | ||
let(:invalid_attributes) { { name: "", code: "" } } | ||
let(:run_request) { patch url_helpers.promotion_category_path(promotion_category), params: { promotion_category: invalid_attributes } } | ||
|
||
it "does not update the promotion category" do | ||
expect { run_request }.not_to change { promotion_category.reload.name } | ||
end | ||
|
||
it "renders the edit template with unprocessable_entity status" do | ||
run_request | ||
expect(response).to have_http_status(:unprocessable_entity) | ||
end | ||
end | ||
end | ||
|
||
describe "DELETE /destroy" do | ||
before { promotion_category } | ||
|
||
let(:run_request) { delete url_helpers.promotion_category_path(promotion_category) } | ||
|
||
it "deletes the promotion category and redirects to the index page with a 303 See Other status" do | ||
expect { run_request }.to change(model_class, :count).by(-1) | ||
|
||
expect(response).to redirect_to(url_helpers.promotion_categories_path) | ||
expect(response).to have_http_status(:see_other) | ||
end | ||
|
||
it "displays a success flash message after deletion" do | ||
run_request | ||
follow_redirect! | ||
expect(response.body).to include("Promotion Categories were successfully removed.") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...romotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<%= turbo_frame_tag :resource_modal, target: "_top" do %> | ||
<%= render component("ui/modal").new(title: t(".title")) do |modal| %> | ||
<%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %> | ||
<div class="flex flex-col gap-6 pb-4"> | ||
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %> | ||
<%= render component("ui/forms/field").text_field(f, :code, class: "required") %> | ||
</div> | ||
<% modal.with_actions do %> | ||
<form method="dialog"> | ||
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %> | ||
</form> | ||
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% end %> |
4 changes: 4 additions & 0 deletions
4
legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::PromotionCategories::Edit::Component < SolidusAdmin::Resources::Edit::Component | ||
end |
4 changes: 4 additions & 0 deletions
4
legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
en: | ||
title: "Edit Promotion Category" | ||
cancel: "Cancel" | ||
submit: "Update Promotion Category" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<%= turbo_frame_tag :resource_modal, target: "_top" do %> | ||
<%= render component("ui/modal").new(title: t(".title")) do |modal| %> | ||
<%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %> | ||
<div class="flex flex-col gap-6 pb-4"> | ||
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %> | ||
<%= render component("ui/forms/field").text_field(f, :code, class: "required") %> | ||
</div> | ||
<% modal.with_actions do %> | ||
<form method="dialog"> | ||
<%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %> | ||
</form> | ||
<%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% end %> |
4 changes: 4 additions & 0 deletions
4
legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::PromotionCategories::New::Component < SolidusAdmin::Resources::New::Component | ||
end |
4 changes: 4 additions & 0 deletions
4
legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
en: | ||
title: "New Promotion Category" | ||
cancel: "Cancel" | ||
submit: "Add Promotion Category" |
Oops, something went wrong.