mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-03 22:06:07 +00:00
11200: add specs
This commit is contained in:
@@ -10,8 +10,11 @@ module Admin
|
||||
end
|
||||
end
|
||||
|
||||
def prepare_new_variant(product)
|
||||
product.variants.build
|
||||
def prepare_new_variant(product, producer_options)
|
||||
# e.g producer_options = [['producer name', id]]
|
||||
product.variants.build do |new_variant|
|
||||
new_variant.supplier_id = producer_options.first.second if producer_options.one?
|
||||
end
|
||||
end
|
||||
|
||||
def unit_value_with_description(variant)
|
||||
|
||||
@@ -37,7 +37,7 @@ class ColumnPreference < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.valid_columns_for(action_name)
|
||||
__send__("#{action_name}_columns").keys.map(&:to_s)
|
||||
get_default_preferences(action_name, Spree::User.new).keys.map(&:to_s)
|
||||
end
|
||||
|
||||
def self.known_actions
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
%tr.condensed{ id: dom_id(variant), 'data-controller': "variant", 'class': "nested-form-wrapper", 'data-new-record': variant.new_record? ? "true" : false }
|
||||
= render partial: 'variant_row', locals: { variant:, f: variant_form, category_options:, tax_category_options:, producer_options: }
|
||||
|
||||
= form.fields_for("products][#{product_index}][variants_attributes][NEW_RECORD", prepare_new_variant(product)) do |new_variant_form|
|
||||
= form.fields_for("products][#{product_index}][variants_attributes][NEW_RECORD", prepare_new_variant(product, producer_options)) do |new_variant_form|
|
||||
%template{ 'data-nested-form-target': "template" }
|
||||
%tr.condensed{ 'data-controller': "variant", 'class': "nested-form-wrapper", 'data-new-record': "true" }
|
||||
= render partial: 'variant_row', locals: { variant: new_variant_form.object, f: new_variant_form, category_options:, tax_category_options:, producer_options: }
|
||||
|
||||
@@ -34,42 +34,59 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
|
||||
describe "column selector" do
|
||||
let!(:product) { create(:simple_product) }
|
||||
|
||||
before do
|
||||
visit admin_products_url
|
||||
context "with one producer only" do
|
||||
before do
|
||||
visit admin_products_url
|
||||
end
|
||||
|
||||
it "hides column and remembers saved preference" do
|
||||
# Name shows by default
|
||||
expect(page).to have_checked_field "Name"
|
||||
expect(page).to have_selector "th", text: "Name"
|
||||
expect_other_columns_visible
|
||||
|
||||
# Producer is hidden by if only one producer is present
|
||||
expect(page).not_to have_checked_field "Producer"
|
||||
expect(page).not_to have_selector "th", text: "Producer"
|
||||
|
||||
# Name is hidden
|
||||
ofn_drop_down("Columns").click
|
||||
within ofn_drop_down("Columns") do
|
||||
uncheck "Name"
|
||||
end
|
||||
expect(page).not_to have_selector "th", text: "Name"
|
||||
expect_other_columns_visible
|
||||
|
||||
# Preference saved
|
||||
click_on "Save as default"
|
||||
expect(page).to have_content "Column preferences saved"
|
||||
refresh
|
||||
|
||||
# Preference remembered
|
||||
ofn_drop_down("Columns").click
|
||||
within ofn_drop_down("Columns") do
|
||||
expect(page).to have_unchecked_field "Name"
|
||||
end
|
||||
expect(page).not_to have_selector "th", text: "Name"
|
||||
expect_other_columns_visible
|
||||
end
|
||||
|
||||
def expect_other_columns_visible
|
||||
expect(page).to have_selector "th", text: "Price"
|
||||
expect(page).to have_selector "th", text: "On Hand"
|
||||
end
|
||||
end
|
||||
|
||||
it "hides column and remembers saved preference" do
|
||||
# Name shows by default
|
||||
expect(page).to have_checked_field "Name"
|
||||
expect(page).to have_selector "th", text: "Name"
|
||||
expect_other_columns_visible
|
||||
context "with multiple producers" do
|
||||
let!(:producer2) { create(:supplier_enterprise, owner: user) }
|
||||
|
||||
# Name is hidden
|
||||
ofn_drop_down("Columns").click
|
||||
within ofn_drop_down("Columns") do
|
||||
uncheck "Name"
|
||||
before { visit admin_products_url }
|
||||
|
||||
it "has selected producer column by default" do
|
||||
# Producer shows by default
|
||||
expect(page).to have_checked_field "Producer"
|
||||
expect(page).to have_selector "th", text: "Producer"
|
||||
end
|
||||
expect(page).not_to have_selector "th", text: "Name"
|
||||
expect_other_columns_visible
|
||||
|
||||
# Preference saved
|
||||
click_on "Save as default"
|
||||
expect(page).to have_content "Column preferences saved"
|
||||
refresh
|
||||
|
||||
# Preference remembered
|
||||
ofn_drop_down("Columns").click
|
||||
within ofn_drop_down("Columns") do
|
||||
expect(page).to have_unchecked_field "Name"
|
||||
end
|
||||
expect(page).not_to have_selector "th", text: "Name"
|
||||
expect_other_columns_visible
|
||||
end
|
||||
|
||||
def expect_other_columns_visible
|
||||
expect(page).to have_selector "th", text: "Producer"
|
||||
expect(page).to have_selector "th", text: "Price"
|
||||
expect(page).to have_selector "th", text: "On Hand"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
|
||||
include WebHelper
|
||||
|
||||
let!(:supplier) { create(:supplier_enterprise) }
|
||||
let!(:supplier2) { create(:supplier_enterprise) }
|
||||
let!(:taxon) { create(:taxon) }
|
||||
|
||||
describe "creating a new product" do
|
||||
|
||||
@@ -36,7 +36,6 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
|
||||
expect(page).to have_selector "th", text: "Unit"
|
||||
expect(page).to have_selector "th", text: "Price"
|
||||
expect(page).to have_selector "th", text: "On Hand"
|
||||
expect(page).to have_selector "th", text: "Producer"
|
||||
expect(page).to have_selector "th", text: "Category"
|
||||
expect(page).to have_selector "th", text: "Tax Category"
|
||||
expect(page).to have_selector "th", text: "Inherits Properties?"
|
||||
|
||||
@@ -9,7 +9,8 @@ RSpec.describe 'As an enterprise user, I can update my products' do
|
||||
include FileHelper
|
||||
|
||||
let(:producer) { create(:supplier_enterprise) }
|
||||
let(:user) { create(:user, enterprises: [producer]) }
|
||||
let(:producer2) { create(:supplier_enterprise) }
|
||||
let(:user) { create(:user, enterprises: [producer, producer2]) }
|
||||
|
||||
before do
|
||||
login_as user
|
||||
|
||||
Reference in New Issue
Block a user