BPE: Switch column toggle to dropdown, clean up specs

This commit is contained in:
Rob H
2014-08-01 11:47:11 +10:00
parent 9922dc6e79
commit b9f49344b4
5 changed files with 205 additions and 334 deletions

View File

@@ -28,7 +28,6 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [
$scope.optionTabs =
filters: { title: "Filter Products", visible: false }
column_toggle: { title: "Toggle Columns", visible: false }
$scope.products = []
$scope.filteredProducts = []
@@ -277,7 +276,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [
filters: $scope.currentFilters
).success((data) ->
DirtyProducts.clear()
#$scope.updateVariantLists(data)
$scope.updateVariantLists(data)
$timeout -> $scope.displaySuccess()
).error (data, status) ->
$scope.displayFailure "Server returned with error status: " + status

View File

@@ -31,7 +31,7 @@ Spree::Admin::ProductsController.class_eval do
end
if product_set.save
redirect_to "/api/products/managed?template=bulk_index;page=1;per_page=500;#{bulk_index_query}"
redirect_to "/api/products/bulk_products?page=1;per_page=500;#{bulk_index_query}"
else
render :nothing => true, :status => 418
end

View File

@@ -4,7 +4,7 @@ class Spree::Api::ProductSerializer < ActiveModel::Serializer
attributes :taxon_ids, :on_hand, :price, :available_on, :permalink_live
has_one :supplier, key: :producer, embed: :id
has_many :variants, key: :variants, embed: :ids#, serializer: Spree::Api::VariantSerializer
has_many :variants, key: :variants, serializer: Spree::Api::VariantSerializer # embed: ids
has_one :master, serializer: Spree::Api::VariantSerializer
# Infinity is not a valid JSON object, but Rails encodes it anyway

View File

@@ -46,10 +46,6 @@
{{ filter.value }}
%div{ :class => "two columns omega" }
%a{ :href => "#", 'ng-click' => "removeFilter(filter)" } Remove Filter
%div.column_toggle{ :class => "sixteen columns alpha", "ng-show" => 'optionTabs.column_toggle.visible' }
%ul.column-list{ :class => "sixteen columns alpha" }
%li.column-list-item{ :class => "three columns alpha", 'ofn-toggle-column' => 'column', 'ng-repeat' => 'column in columns' }
{{ column.name }}
%hr
%div.sixteen.columns.alpha.loading{ 'ng-show' => 'loading' }
%h4 Loading Products...
@@ -60,33 +56,41 @@
%div.sixteen.columns.alpha{ 'ng-hide' => 'loading || products.length == 500 || products.length == 0' }
%div.quick_search{ :class => "five columns omega" }
%input.search{ :class => "four columns alpha", 'ng-model' => 'query', :name => "quick_filter", :type => 'text', 'placeholder' => 'Quick Search' }
%div.spacer{ :class => "nine columns omega" } &nbsp;
%div{ :class => "eight columns" } &nbsp;
%div{ :class => "three columns omega" }
%div.ofn_drop_down{ 'ng-controller' => "DropDownCtrl", :id => "columns_dropdown", 'ofn-drop-down' => true, :style => 'float:right;' }
%span{ :class => 'icon-reorder' } &nbsp; Columns
%span{ 'ng-class' => "expanded && 'icon-caret-up' || !expanded && 'icon-caret-down'" }
%div.menu{ 'ng-show' => "expanded" }
%div.menu_item{ :class => "three columns alpha", 'ng-repeat' => "column in columns", 'ofn-toggle-column' => true }
%span{ :class => 'one column alpha', :style => 'text-align: center'} {{ column.visible && "&#10003;" || !column.visible && "&nbsp;" }}
%span{ :class => 'two columns omega' } {{column.name }}
%table.index#listing_products.bulk{ "infinite-scroll" => "incrementLimit()", "infinite-scroll-distance" => "1" }
%colgroup
%col
%col
%col{'style' => 'width: 20%;'}
%col{'style' => 'width: 12%;'}
%col{'style' => 'width: 12%;'}
%col{'style' => 'width: 12%;'}
%col
%col
%col
%col
%col
%col
%col.actions
%col.producer{ 'style' => 'width: 14%;', 'ng-show' => 'columns.producer.visible' }
%col.name{ 'style' => 'width: 20%;', 'ng-show' => 'columns.name.visible' }
%col.unit{ 'style' => 'width: 14%;', 'ng-show' => 'columns.unit.visible' }
%col.display_as{ 'style' => 'width: 12%;', 'ng-show' => 'columns.unit.visible' }
%col.price{ 'style' => 'width: 10%;', 'ng-show' => 'columns.price.visible'}
%col.on_hand{ 'style' => 'width: 10%;', 'ng-show' => 'columns.on_hand.visible' }
%col.taxons{ 'ng-show' => 'columns.taxons.visible' }
%col.available_on{ 'ng-show' => 'columns.available_on.visible' }
%col.actions
%col.actions
%col.actions
%thead
%tr
%th.left-actions
%th{ 'ng-show' => 'columns.producer.visible' } Supplier
%th{ 'ng-show' => 'columns.name.visible' } Name
%th{ 'ng-show' => 'columns.unit.visible' } Unit / Value
%th{ 'ng-show' => 'columns.unit.visible' } Display As
%th{ 'ng-show' => 'columns.price.visible' } Price
%th{ 'ng-show' => 'columns.on_hand.visible' } On Hand
%th{ 'ng-show' => 'columns.taxons.visible' } Taxons
%th{ 'ng-show' => 'columns.available_on.visible' } Av. On
%th.producer{ 'ng-show' => 'columns.producer.visible' } Producer
%th.name{ 'ng-show' => 'columns.name.visible' } Name
%th.unit{ 'ng-show' => 'columns.unit.visible' } Unit / Value
%th.display_as{ 'ng-show' => 'columns.unit.visible' } Display As
%th.price{ 'ng-show' => 'columns.price.visible' } Price
%th.on_hand{ 'ng-show' => 'columns.on_hand.visible' } On Hand
%th.taxons{ 'ng-show' => 'columns.taxons.visible' } Taxons
%th.available_on{ 'ng-show' => 'columns.available_on.visible' } Av. On
%th.actions
%th.actions
%th.actions
@@ -97,7 +101,7 @@
%a{ :class => "add-variant icon-plus-sign", 'ng-click' => "addVariant(product)", 'ng-show' => "!hasVariants(product) && hasUnit(product)" }
%td.producer{ 'ng-show' => 'columns.producer.visible' }
%select.select2{ 'ng-model' => 'product.producer', :name => 'producer', 'ofn-track-product' => 'producer', 'ng-options' => 'producer.name for producer in producers' }
%td{ 'ng-show' => 'columns.name.visible' }
%td.name{ 'ng-show' => 'columns.name.visible' }
%input{ 'ng-model' => "product.name", :name => 'product_name', 'ofn-track-product' => 'name', :type => 'text' }
%td.unit{ 'ng-show' => 'columns.unit.visible' }
%select.select2{ 'ng-model' => 'product.variant_unit_with_scale', :name => 'variant_unit_with_scale', 'ofn-track-product' => 'variant_unit_with_scale', 'ng-options' => 'unit[1] as unit[0] for unit in variant_unit_options' }
@@ -106,14 +110,14 @@
%input{ 'ng-model' => 'product.variant_unit_name', :name => 'variant_unit_name', 'ofn-track-product' => 'variant_unit_name', :placeholder => 'unit', 'ng-show' => "product.variant_unit_with_scale == 'items'", :type => 'text' }
%td.display_as{ 'ng-show' => 'columns.unit.visible' }
%input{ 'ofn-display-as' => 'product.master', name: 'display_as', 'ofn-track-master' => 'display_as', type: 'text', placeholder: '{{ placeholder_text }}', ng: { hide: 'hasVariants(product)', model: 'product.master.display_as' } }
%td{ 'ng-show' => 'columns.price.visible' }
%td.price{ 'ng-show' => 'columns.price.visible' }
%input{ 'ng-model' => 'product.price', 'ofn-decimal' => :true, :name => 'price', 'ofn-track-product' => 'price', :type => 'text', 'ng-hide' => 'hasVariants(product)' }
%td{ 'ng-show' => 'columns.on_hand.visible' }
%td.on_hand{ 'ng-show' => 'columns.on_hand.visible' }
%span{ 'ng-bind' => 'product.on_hand', :name => 'on_hand', 'ng-show' => '!hasOnDemandVariants(product) && (hasVariants(product) || product.on_demand)' }
%input.field{ 'ng-model' => 'product.on_hand', :name => 'on_hand', 'ofn-track-product' => 'on_hand', 'ng-hide' => 'hasVariants(product) || product.on_demand', :type => 'number' }
%td{ 'ng-if' => 'columns.taxons.visible' }
%input.fullwidth{ :type => 'text', 'ng-model' => 'product.taxon_ids', 'ofn-taxon-autocomplete' => '', 'ofn-track-product' => 'taxon_ids' }
%td{ 'ng-show' => 'columns.available_on.visible' }
%td.available_on{ 'ng-show' => 'columns.available_on.visible' }
%input{ 'ng-model' => 'product.available_on', :name => 'available_on', 'ofn-track-product' => 'available_on', 'datetimepicker' => 'product.available_on', type: "text" }
%td.actions
%a{ 'ng-click' => 'editWarn(product)', :class => "edit-product icon-edit no-text" }
@@ -121,7 +125,7 @@
%a{ 'ng-click' => 'cloneProduct(product)', :class => "clone-product icon-copy no-text" }
%td.actions
%a{ 'ng-click' => 'deleteProduct(product)', :class => "delete-product icon-trash no-text" }
%tr.variant{ 'ng-repeat' => 'variant in product.variants', 'ng-show' => 'displayProperties[product.id].showVariants', 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'" }
%tr.variant{ :id => "v_{{variant.id}}", 'ng-repeat' => 'variant in product.variants', 'ng-show' => 'displayProperties[product.id].showVariants', 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'" }
%td.left-actions
%a{ :class => "variant-item icon-caret-right", 'ng-hide' => "$last" }
%a{ :class => "add-variant icon-plus-sign", 'ng-click' => "addVariant(product)", 'ng-show' => "$last" }

View File

@@ -18,14 +18,14 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_field "product_name", with: p1.name, :visible => true
page.should have_field "product_name", with: p2.name, :visible => true
expect(page).to have_field "product_name", with: p1.name, :visible => true
expect(page).to have_field "product_name", with: p2.name, :visible => true
end
it "displays a message when number of products is zero" do
visit '/admin/products/bulk_edit'
page.should have_text "No matching products found."
expect(page).to have_text "No matching products found."
end
pending "displays a message when number of products is too great" do
@@ -33,16 +33,7 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_text "Search returned too many products to display (500+), please apply more search filters to reduce the number of matching products"
end
it "displays pagination information" do
p1 = FactoryGirl.create(:product)
p2 = FactoryGirl.create(:product)
visit '/admin/products/bulk_edit'
page.should have_text "Displaying 1-2 of 2 products"
expect(page).to have_text "Search returned too many products to display (500+), please apply more search filters to reduce the number of matching products"
end
it "displays a select box for suppliers, with the appropriate supplier selected" do
@@ -54,8 +45,8 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_select "supplier", with_options: [s1.name,s2.name,s3.name], selected: s2.name
page.should have_select "supplier", with_options: [s1.name,s2.name,s3.name], selected: s3.name
expect(page).to have_select "producer", with_options: [s1.name,s2.name,s3.name], selected: s2.name
expect(page).to have_select "producer", with_options: [s1.name,s2.name,s3.name], selected: s3.name
end
it "displays a date input for available_on for each product, formatted to yyyy-mm-dd hh:mm:ss" do
@@ -63,11 +54,11 @@ feature %q{
p2 = FactoryGirl.create(:product, available_on: Date.today-1)
visit '/admin/products/bulk_edit'
first("div.option_tab_titles h6", :text => "Toggle Columns").click
first("li.column-list-item", text: "Available On").click
first("div#columns_dropdown", :text => "COLUMNS").click
first("div#columns_dropdown div.menu div.menu_item", text: "Available On").click
page.should have_field "available_on", with: p1.available_on.strftime("%F %T")
page.should have_field "available_on", with: p2.available_on.strftime("%F %T")
expect(page).to have_field "available_on", with: p1.available_on.strftime("%F %T")
expect(page).to have_field "available_on", with: p2.available_on.strftime("%F %T")
end
it "displays a price input for each product without variants (ie. for master variant)" do
@@ -82,9 +73,9 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_field "price", with: "22.0"
page.should have_field "price", with: "44.0"
page.should_not have_field "price", with: "66.0", visible: true
expect(page).to have_field "price", with: "22.0"
expect(page).to have_field "price", with: "44.0"
expect(page).to have_no_field "price", with: "66.0", visible: true
end
it "displays an on hand count input for each product (ie. for master variant) if no regular variants exist" do
@@ -97,9 +88,9 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should_not have_selector "span[name='on_hand']", text: "0"
page.should have_field "on_hand", with: "15"
page.should have_field "on_hand", with: "12"
expect(page).to have_no_selector "span[name='on_hand']", text: "0"
expect(page).to have_field "on_hand", with: "15"
expect(page).to have_field "on_hand", with: "12"
end
it "displays an on hand count in a span for each product (ie. for master variant) if other variants exist" do
@@ -113,9 +104,9 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should_not have_field "on_hand", with: "15"
page.should have_selector "span[name='on_hand']", text: "4"
page.should have_field "on_hand", with: "12"
expect(page).to have_no_field "on_hand", with: "15"
expect(page).to have_selector "span[name='on_hand']", text: "4"
expect(page).to have_field "on_hand", with: "12"
end
it "displays 'on demand' for the on hand count when the product is available on demand" do
@@ -124,8 +115,8 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_selector "span[name='on_hand']", text: "On demand"
page.should_not have_field "on_hand", visible: true
expect(page).to have_selector "span[name='on_hand']", text: "On demand"
expect(page).to have_no_field "on_hand", visible: true
end
it "displays 'on demand' for any variant that is available on demand" do
@@ -136,10 +127,10 @@ feature %q{
visit '/admin/products/bulk_edit'
first("a.view-variants").trigger('click')
page.should_not have_selector "span[name='on_hand']", text: "On demand", visible: true
page.should have_field "variant_on_hand", with: "4"
page.should_not have_field "variant_on_hand", with: "", visible: true
page.should have_selector "span[name='variant_on_hand']", text: "On demand"
expect(page).to have_no_selector "span[name='on_hand']", text: "On demand", visible: true
expect(page).to have_field "variant_on_hand", with: "4"
expect(page).to have_no_field "variant_on_hand", with: "", visible: true
expect(page).to have_selector "span[name='variant_on_hand']", text: "On demand"
end
it "displays a select box for the unit of measure for the product's variants" do
@@ -147,7 +138,7 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_select "variant_unit_with_scale", selected: "Weight (g)"
expect(page).to have_select "variant_unit_with_scale", selected: "Weight (g)"
end
it "displays a text field for the item name when unit is set to 'Items'" do
@@ -155,8 +146,8 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_select "variant_unit_with_scale", selected: "Items"
page.should have_field "variant_unit_name", with: "packet"
expect(page).to have_select "variant_unit_with_scale", selected: "Items"
expect(page).to have_field "variant_unit_name", with: "packet"
end
end
@@ -170,13 +161,13 @@ feature %q{
v2 = FactoryGirl.create(:variant, display_name: "something2" )
visit '/admin/products/bulk_edit'
page.should have_selector "a.view-variants"
expect(page).to have_selector "a.view-variants"
all("a.view-variants").each { |e| e.trigger('click') }
page.should have_field "product_name", with: v1.product.name
page.should have_field "product_name", with: v2.product.name
page.should have_field "variant_display_name", with: v1.display_name
page.should have_field "variant_display_name", with: v2.display_name
expect(page).to have_field "product_name", with: v1.product.name
expect(page).to have_field "product_name", with: v2.product.name
expect(page).to have_field "variant_display_name", with: v1.display_name
expect(page).to have_field "variant_display_name", with: v2.display_name
end
it "displays an on_hand input (for each variant) for each product" do
@@ -187,9 +178,9 @@ feature %q{
visit '/admin/products/bulk_edit'
all("a.view-variants").each { |e| e.trigger('click') }
page.should have_selector "span[name='on_hand']", text: "21"
page.should have_field "variant_on_hand", with: "15"
page.should have_field "variant_on_hand", with: "6"
expect(page).to have_selector "span[name='on_hand']", text: "21"
expect(page).to have_field "variant_on_hand", with: "15"
expect(page).to have_field "variant_on_hand", with: "6"
end
@@ -201,9 +192,9 @@ feature %q{
visit '/admin/products/bulk_edit'
all("a.view-variants").each { |e| e.trigger('click') }
page.should have_field "price", with: "2.0", visible: false
page.should have_field "variant_price", with: "12.75"
page.should have_field "variant_price", with: "2.5"
expect(page).to have_field "price", with: "2.0", visible: false
expect(page).to have_field "variant_price", with: "12.75"
expect(page).to have_field "variant_price", with: "2.5"
end
it "displays a unit value field (for each variant) for each product" do
@@ -214,10 +205,10 @@ feature %q{
visit '/admin/products/bulk_edit'
all("a.view-variants").each { |e| e.trigger('click') }
page.should have_field "variant_unit_value_with_description", with: "1.2 (small bag)"
page.should have_field "variant_unit_value_with_description", with: "4.8 (large bag)"
page.should have_field "variant_display_as", with: "bag"
page.should have_field "variant_display_as", with: "bin"
expect(page).to have_field "variant_unit_value_with_description", with: "1.2 (small bag)"
expect(page).to have_field "variant_unit_value_with_description", with: "4.8 (large bag)"
expect(page).to have_field "variant_display_as", with: "bag"
expect(page).to have_field "variant_display_as", with: "bin"
end
end
@@ -232,7 +223,7 @@ feature %q{
visit '/admin/products/bulk_edit'
find("a", text: "NEW PRODUCT").click
page.should have_content 'NEW PRODUCT'
expect(page).to have_content 'NEW PRODUCT'
fill_in 'product_name', :with => 'Big Bag Of Apples'
select(s.name, :from => 'product_supplier_id')
@@ -240,9 +231,9 @@ feature %q{
select taxon.name, from: 'product_primary_taxon_id'
click_button 'Create'
URI.parse(current_url).path.should == '/admin/products/bulk_edit'
flash_message.should == 'Product "Big Bag Of Apples" has been successfully created!'
page.should have_field "product_name", with: 'Big Bag Of Apples'
expect(URI.parse(current_url).path).to eq '/admin/products/bulk_edit'
expect(flash_message).to eq 'Product "Big Bag Of Apples" has been successfully created!'
expect(page).to have_field "product_name", with: 'Big Bag Of Apples'
end
@@ -253,13 +244,13 @@ feature %q{
visit '/admin/products/bulk_edit'
# I should not see an add variant button
page.should_not have_selector 'a.add-variant', visible: true
expect(page).to have_no_selector 'a.add-variant', visible: true
# When I set the unit
select "Weight (kg)", from: "variant_unit_with_scale"
# I should see an add variant button
page.should have_selector 'a.add-variant', visible: true
expect(page).to have_selector 'a.add-variant', visible: true
# When I add three variants
page.find('a.add-variant', visible: true).trigger('click')
@@ -267,13 +258,15 @@ feature %q{
page.find('a.add-variant', visible: true).trigger('click')
# They should be added, and should see no edit buttons
page.all("tr.variant").count.should == 3
page.should_not have_selector "a.edit-variant", visible: true
variant_count = page.all("tr.variant").count
expect(variant_count).to eq 3
expect(page).to have_no_selector "a.edit-variant", visible: true
# When I remove two, they should be removed
page.all('a.delete-variant').first.click
page.all('a.delete-variant').first.click
page.all("tr.variant").count.should == 1
variant_count = page.all("tr.variant").count
expect(variant_count).to eq 1
# When I fill out variant details and hit update
fill_in "variant_display_name", with: "Case of 12 Bottles"
@@ -282,18 +275,18 @@ feature %q{
fill_in "variant_price", with: "4.0"
fill_in "variant_on_hand", with: "10"
click_button 'Update'
page.find("span#update-status-message").should have_content "Update complete"
expect(page.find("span#update-status-message")).to have_content "Update complete"
updated_variant = Spree::Variant.where(deleted_at: nil).last
updated_variant.display_name.should == "Case of 12 Bottles"
updated_variant.unit_value.should == 3000
updated_variant.unit_description.should == "(12x250 mL bottles)"
updated_variant.display_as.should == "Case"
updated_variant.price.should == 4.0
updated_variant.on_hand.should == 10
expect(updated_variant.display_name).to eq "Case of 12 Bottles"
expect(updated_variant.unit_value).to eq 3000
expect(updated_variant.unit_description).to eq "(12x250 mL bottles)"
expect(updated_variant.display_as).to eq "Case"
expect(updated_variant.price).to eq 4.0
expect(updated_variant.on_hand).to eq 10
# Then I should see edit buttons for the new variant
page.should have_selector "a.edit-variant", visible: true
expect(page).to have_selector "a.edit-variant", visible: true
end
@@ -309,18 +302,18 @@ feature %q{
visit '/admin/products/bulk_edit'
first("div.option_tab_titles h6", :text => "Toggle Columns").click
first("li.column-list-item", text: "Available On").click
first("div#columns_dropdown", :text => "COLUMNS").click
first("div#columns_dropdown div.menu div.menu_item", text: "Available On").click
page.should have_field "product_name", with: p.name
page.should have_select "supplier", selected: s1.name
page.should have_field "available_on", with: p.available_on.strftime("%F %T")
page.should have_field "price", with: "10.0"
page.should have_select "variant_unit_with_scale", selected: "Volume (L)"
page.should have_field "on_hand", with: "6"
expect(page).to have_field "product_name", with: p.name
expect(page).to have_select "producer", selected: s1.name
expect(page).to have_field "available_on", with: p.available_on.strftime("%F %T")
expect(page).to have_field "price", with: "10.0"
expect(page).to have_select "variant_unit_with_scale", selected: "Volume (L)"
expect(page).to have_field "on_hand", with: "6"
fill_in "product_name", with: "Big Bag Of Potatoes"
select(s2.name, :from => 'supplier')
select(s2.name, :from => 'producer')
fill_in "available_on", with: (Date.today-3).strftime("%F %T")
fill_in "price", with: "20"
select "Weight (kg)", from: "variant_unit_with_scale"
@@ -328,17 +321,17 @@ feature %q{
fill_in "display_as", with: "Big Bag"
click_button 'Update'
page.find("span#update-status-message").should have_content "Update complete"
expect(page.find("span#update-status-message")).to have_content "Update complete"
p.reload
p.name.should == "Big Bag Of Potatoes"
p.supplier.should == s2
p.variant_unit.should == "weight"
p.variant_unit_scale.should == 1000 # Kg
p.available_on.should == 3.days.ago.beginning_of_day
p.master.display_as.should == "Big Bag"
p.price.should == 20.0
p.on_hand.should == 18
expect(p.name).to eq "Big Bag Of Potatoes"
expect(p.supplier).to eq s2
expect(p.variant_unit).to eq "weight"
expect(p.variant_unit_scale).to eq 1000 # Kg
expect(p.available_on).to eq 3.days.ago.beginning_of_day
expect(p.master.display_as).to eq "Big Bag"
expect(p.price).to eq 20.0
expect(p.on_hand).to eq 18
end
scenario "updating a product with a variant unit of 'items'" do
@@ -348,7 +341,7 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_select "variant_unit_with_scale", selected: "Weight (kg)"
expect(page).to have_select "variant_unit_with_scale", selected: "Weight (kg)"
select "Items", from: "variant_unit_with_scale"
fill_in "variant_unit_name", with: "loaf"
@@ -370,7 +363,7 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_select "variant_unit_with_scale", selected: ''
expect(page).to have_select "variant_unit_with_scale", selected: ''
select "Weight (kg)", from: "variant_unit_with_scale"
first("a.view-variants").trigger('click')
@@ -395,8 +388,8 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_select "variant_unit_with_scale", selected: ''
page.should_not have_field "master_unit_value_with_description", visible: true
expect(page).to have_select "variant_unit_with_scale", selected: ''
expect(page).to have_no_field "master_unit_value_with_description", visible: true
select "Weight (kg)", from: "variant_unit_with_scale"
fill_in "master_unit_value_with_description", with: '123 abc'
@@ -420,7 +413,7 @@ feature %q{
visit '/admin/products/bulk_edit'
select "Weight (kg)", from: "variant_unit_with_scale"
page.should_not have_field "master_unit_value_with_description", visible: true
expect(page).to have_no_field "master_unit_value_with_description", visible: true
end
end
@@ -434,20 +427,20 @@ feature %q{
login_to_admin_section
visit '/admin/products/bulk_edit'
page.should have_selector "a.view-variants"
expect(page).to have_selector "a.view-variants"
first("a.view-variants").trigger('click')
page.should have_field "variant_price", with: "3.0"
page.should have_field "variant_unit_value_with_description", with: "250 (bottle)"
page.should have_field "variant_on_hand", with: "9"
page.should have_selector "span[name='on_hand']", text: "9"
expect(page).to have_field "variant_price", with: "3.0"
expect(page).to have_field "variant_unit_value_with_description", with: "250 (bottle)"
expect(page).to have_field "variant_on_hand", with: "9"
expect(page).to have_selector "span[name='on_hand']", text: "9"
select "Volume (L)", from: "variant_unit_with_scale"
fill_in "variant_price", with: "4.0"
fill_in "variant_on_hand", with: "10"
fill_in "variant_unit_value_with_description", with: "2 (8x250 mL bottles)"
page.should have_selector "span[name='on_hand']", text: "10"
expect(page).to have_selector "span[name='on_hand']", text: "10"
click_button 'Update'
page.find("span#update-status-message").should have_content "Update complete"
@@ -466,10 +459,10 @@ feature %q{
login_to_admin_section
visit '/admin/products/bulk_edit'
page.should have_selector "a.view-variants"
expect(page).to have_selector "a.view-variants"
first("a.view-variants").trigger('click')
page.should have_field "variant_price", with: "3.0"
expect(page).to have_field "variant_price", with: "3.0"
fill_in "variant_price", with: "10.0"
@@ -486,7 +479,7 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_field "product_name", with: "original name"
expect(page).to have_field "product_name", with: "original name"
fill_in "product_name", with: "new name 1"
@@ -545,14 +538,14 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_selector "div.option_tab_titles h6", :text => "Filter Products"
expect(page).to have_selector "div.option_tab_titles h6", :text => "Filter Products"
first("div.option_tab_titles h6", :text => "Filter Products").click
select2_select "Name", from: "filter_property"
select2_select "Contains", from: "filter_predicate"
fill_in "filter_value", :with => "1"
click_button "Apply Filter"
page.should_not have_field "product_name", with: p2.name
expect(page).to have_no_field "product_name", with: p2.name
fill_in "product_name", :with => "new product1"
click_on 'Update'
@@ -561,22 +554,6 @@ feature %q{
p1.name.should == "new product1"
end
scenario "updating a product when there are more products than the default API page size" do
p = FactoryGirl.create(:simple_product)
25.times { FactoryGirl.create(:simple_product) }
login_to_admin_section
visit '/admin/products/bulk_edit'
within "tr#p_#{p.id}" do
fill_in 'product_name', with: "new name"
end
click_button 'Update'
page.find("span#update-status-message").should have_content "Update complete"
p.reload
p.name.should == "new name"
end
describe "using action buttons" do
describe "using delete buttons" do
it "shows a delete button for products, which deletes the appropriate product when clicked" do
@@ -587,15 +564,15 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_selector "a.delete-product", :count => 3
expect(page).to have_selector "a.delete-product", :count => 3
first("a.delete-product").click
page.should have_selector "a.delete-product", :count => 2
expect(page).to have_selector "a.delete-product", :count => 2
visit '/admin/products/bulk_edit'
page.should have_selector "a.delete-product", :count => 2
expect(page).to have_selector "a.delete-product", :count => 2
end
it "shows a delete button for variants, which deletes the appropriate variant when clicked" do
@@ -605,20 +582,20 @@ feature %q{
login_to_admin_section
visit '/admin/products/bulk_edit'
page.should have_selector "a.view-variants"
expect(page).to have_selector "a.view-variants"
all("a.view-variants").each { |e| e.trigger('click') }
page.should have_selector "a.delete-variant", :count => 3
expect(page).to have_selector "a.delete-variant", :count => 3
first("a.delete-variant").click
page.should have_selector "a.delete-variant", :count => 2
expect(page).to have_selector "a.delete-variant", :count => 2
visit '/admin/products/bulk_edit'
page.should have_selector "a.view-variants"
expect(page).to have_selector "a.view-variants"
all("a.view-variants").select { |e| e.visible? }.each { |e| e.trigger('click') }
page.should have_selector "a.delete-variant", :count => 2
expect(page).to have_selector "a.delete-variant", :count => 2
end
end
@@ -631,7 +608,7 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_selector "a.edit-product", :count => 3
expect(page).to have_selector "a.edit-product", :count => 3
first("a.edit-product").click
@@ -645,12 +622,14 @@ feature %q{
login_to_admin_section
visit '/admin/products/bulk_edit'
page.should have_selector "a.view-variants"
expect(page).to have_selector "a.view-variants"
all("a.view-variants").each { |e| e.trigger('click') }
page.should have_selector "a.edit-variant", :count => 3
expect(page).to have_selector "a.edit-variant", :count => 3
first("a.edit-variant").click
within "tr#v_#{v1.id}" do
first("a.edit-variant").click
end
URI.parse(current_url).path.should == "/admin/products/#{v1.product.permalink}/variants/#{v1.id}/edit"
end
@@ -665,159 +644,48 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_selector "a.clone-product", :count => 3
expect(page).to have_selector "a.clone-product", :count => 3
first("a.clone-product").click
page.should have_selector "a.clone-product", :count => 4
page.should have_field "product_name", with: "COPY OF #{p1.name}"
page.should have_select "supplier", selected: "#{p1.supplier.name}"
within "tr#p_#{p1.id}" do
first("a.clone-product").click
end
expect(page).to have_selector "a.clone-product", :count => 4
expect(page).to have_field "product_name", with: "COPY OF #{p1.name}"
expect(page).to have_select "producer", selected: "#{p1.supplier.name}"
visit '/admin/products/bulk_edit'
page.should have_selector "a.clone-product", :count => 4
page.should have_field "product_name", with: "COPY OF #{p1.name}"
page.should have_select "supplier", selected: "#{p1.supplier.name}"
expect(page).to have_selector "a.clone-product", :count => 4
expect(page).to have_field "product_name", with: "COPY OF #{p1.name}"
expect(page).to have_select "producer", selected: "#{p1.supplier.name}"
end
end
end
describe "using the page" do
describe "using tabs to hide and display page controls" do
it "shows a column display toggle button, which shows a list of columns when clicked" do
FactoryGirl.create(:simple_product)
login_to_admin_section
visit '/admin/products/bulk_edit'
page.should have_selector "div.column_toggle", :visible => false
page.should have_selector "div.option_tab_titles h6.unselected", :text => "Toggle Columns"
first("div.option_tab_titles h6", :text => "Toggle Columns").click
page.should have_selector "div.option_tab_titles h6.selected", :text => "Toggle Columns"
page.should have_selector "div.column_toggle", :visible => true
page.should have_selector "li.column-list-item", text: "Available On"
page.should have_selector "div.filters", :visible => false
page.should have_selector "div.option_tab_titles h6.unselected", :text => "Filter Products"
first("div.option_tab_titles h6", :text => "Filter Products").click
page.should have_selector "div.option_tab_titles h6.unselected", :text => "Toggle Columns"
page.should have_selector "div.option_tab_titles h6.selected", :text => "Filter Products"
page.should have_selector "div.filters", :visible => true
first("div.option_tab_titles h6", :text => "Filter Products").click
page.should have_selector "div.option_tab_titles h6.unselected", :text => "Filter Products"
page.should have_selector "div.option_tab_titles h6.unselected", :text => "Toggle Columns"
page.should have_selector "div.filters", :visible => false
page.should have_selector "div.column_toggle", :visible => false
end
end
describe "using column display toggle" do
it "shows a column display toggle button, which shows a list of columns when clicked" do
describe "using column display dropdown" do
it "shows a column display dropdown, which shows a list of columns when clicked" do
FactoryGirl.create(:simple_product)
login_to_admin_section
visit '/admin/products/bulk_edit'
first("div.option_tab_titles h6", :text => "Toggle Columns").click
first("li.column-list-item", text: "Available On").click
first("div#columns_dropdown", :text => "COLUMNS").click
first("div#columns_dropdown div.menu div.menu_item", text: "Available On").click
page.should have_selector "th", :text => "NAME"
page.should have_selector "th", :text => "SUPPLIER"
page.should have_selector "th", :text => "PRICE"
page.should have_selector "th", :text => "ON HAND"
page.should have_selector "th", :text => "AV. ON"
expect(page).to have_selector "th", :text => "NAME"
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"
expect(page).to have_selector "th", :text => "AV. ON"
page.should have_selector "div.option_tab_titles h6", :text => "Toggle Columns"
first("div#columns_dropdown div.menu div.menu_item", text: /.{0,1}Producer/).click
page.should have_selector "div ul.column-list li.column-list-item", text: "Supplier"
first("li.column-list-item", text: "Supplier").click
page.should_not have_selector "th", :text => "SUPPLIER"
page.should have_selector "th", :text => "NAME"
page.should have_selector "th", :text => "PRICE"
page.should have_selector "th", :text => "ON HAND"
page.should have_selector "th", :text => "AV. ON"
end
end
describe "using pagination controls" do
it "shows pagination controls" do
27.times { FactoryGirl.create(:product) }
login_to_admin_section
visit '/admin/products/bulk_edit'
page.should have_select 'perPage', :selected => '25'
within '.pagination' do
page.should have_text "1 2"
page.should have_text "Next"
page.should have_text "Last"
end
end
it "allows the number of visible products to be altered" do
27.times { FactoryGirl.create(:product) }
login_to_admin_section
visit '/admin/products/bulk_edit'
select '25', :from => 'perPage'
page.all("input[name='product_name']").select{ |e| e.visible? }.length.should == 25
select '50', :from => 'perPage'
page.all("input[name='product_name']").select{ |e| e.visible? }.length.should == 27
end
it "displays the correct products when changing pages" do
25.times { FactoryGirl.create(:product, :name => "page1product") }
5.times { FactoryGirl.create(:product, :name => "page2product") }
login_to_admin_section
visit '/admin/products/bulk_edit'
select '25', :from => 'perPage'
page.all("input[name='product_name']").select{ |e| e.visible? }.all?{ |e| e.value == "page1product" }.should == true
find("a", text: "2").click
page.all("input[name='product_name']").select{ |e| e.visible? }.all?{ |e| e.value == "page2product" }.should == true
end
it "moves the user to the last available page when changing the number of pages in any way causes user to become orphaned" do
50.times { FactoryGirl.create(:product) }
FactoryGirl.create(:product, :name => "fancy_product_name")
login_to_admin_section
visit '/admin/products/bulk_edit'
select '25', :from => 'perPage'
find("a", text: "3").click
select '50', :from => 'perPage'
page.first("div.pagenav span.page.current").should have_text "2"
page.all("input[name='product_name']", :visible => true).length.should == 1
select '25', :from => 'perPage'
fill_in "quick_filter", :with => "fancy_product_name"
page.first("div.pagenav span.page.current").should have_text "1"
page.all("input[name='product_name']", :visible => true).length.should == 1
end
it "paginates the filtered product list rather than all products" do
25.times { FactoryGirl.create(:product, :name => "product_name") }
3.times { FactoryGirl.create(:product, :name => "test_product_name") }
login_to_admin_section
visit '/admin/products/bulk_edit'
select '25', :from => 'perPage'
page.should have_text "1 2"
fill_in "quick_filter", :with => "test_product_name"
page.all("input[name='product_name']", :visible => true).length.should == 3
page.all("input[name='product_name']", :visible => true).all?{ |e| e.value == "test_product_name" }.should == true
page.should_not have_text "1 2"
page.should have_text "1"
expect(page).to have_no_selector "th", :text => "PRODUCER"
expect(page).to have_selector "th", :text => "NAME"
expect(page).to have_selector "th", :text => "PRICE"
expect(page).to have_selector "th", :text => "ON HAND"
expect(page).to have_selector "th", :text => "AV. ON"
end
end
@@ -828,12 +696,12 @@ feature %q{
login_to_admin_section
visit '/admin/products/bulk_edit'
page.should have_selector "div.option_tab_titles h6", :text => "Filter Products"
expect(page).to have_selector "div.option_tab_titles h6", :text => "Filter Products"
first("div.option_tab_titles h6", :text => "Filter Products").click
page.should have_select "filter_property", visible: false
page.should have_select "filter_predicate", visible: false
page.should have_field "filter_value"
expect(page).to have_select "filter_property", visible: false
expect(page).to have_select "filter_predicate", visible: false
expect(page).to have_field "filter_value"
end
describe "clicking the 'Apply Filter' Button" do
@@ -853,16 +721,16 @@ feature %q{
end
it "adds a new filter to the list of applied filters" do
page.should have_text "Name Equals Product1"
expect(page).to have_text "Name Equals Product1"
end
it "displays the 'loading' splash" do
page.should have_selector "div.loading", :text => "Loading Products..."
expect(page).to have_selector "div.loading", :text => "Loading Products..."
end
it "loads appropriate products" do
page.should have_field "product_name", :with => "Product1"
page.should_not have_field "product_name", :with => "Product2"
expect(page).to have_field "product_name", :with => "Product1"
expect(page).to have_no_field "product_name", :with => "Product2"
end
describe "clicking the 'Remove Filter' link" do
@@ -871,12 +739,12 @@ feature %q{
end
it "removes the filter from the list of applied filters" do
page.should_not have_text "Name Equals Product1"
expect(page).to have_no_text "Name Equals Product1"
end
it "loads appropriate products" do
page.should have_field "product_name", :with => "Product1"
page.should have_field "product_name", :with => "Product2"
expect(page).to have_field "product_name", :with => "Product1"
expect(page).to have_field "product_name", :with => "Product2"
end
end
end
@@ -905,15 +773,15 @@ feature %q{
it "shows only products that I supply" do
visit '/admin/products/bulk_edit'
page.should have_field 'product_name', with: product_supplied.name
page.should_not have_field 'product_name', with: product_not_supplied.name
expect(page).to have_field 'product_name', with: product_supplied.name
expect(page).to have_no_field 'product_name', with: product_not_supplied.name
end
it "shows only suppliers that I manage" do
visit '/admin/products/bulk_edit'
page.should have_select 'supplier', with_options: [s1.name, s2.name], selected: s1.name
page.should_not have_select 'supplier', with_options: [s3.name]
expect(page).to have_select 'producer', with_options: [s1.name, s2.name], selected: s1.name
expect(page).to have_no_select 'producer', with_options: [s3.name]
end
it "shows inactive products that I supply" do
@@ -921,24 +789,24 @@ feature %q{
visit '/admin/products/bulk_edit'
page.should have_field 'product_name', with: product_supplied_inactive.name
expect(page).to have_field 'product_name', with: product_supplied_inactive.name
end
it "allows me to update a product" do
p = product_supplied
visit '/admin/products/bulk_edit'
first("div.option_tab_titles h6", :text => "Toggle Columns").click
first("li.column-list-item", text: "Available On").click
first("div#columns_dropdown", :text => "COLUMNS").click
first("div#columns_dropdown div.menu div.menu_item", text: "Available On").click
page.should have_field "product_name", with: p.name
page.should have_select "supplier", selected: s1.name
page.should have_field "available_on", with: p.available_on.strftime("%F %T")
page.should have_field "price", with: "10.0"
page.should have_field "on_hand", with: "6"
expect(page).to have_field "product_name", with: p.name
expect(page).to have_select "producer", selected: s1.name
expect(page).to have_field "available_on", with: p.available_on.strftime("%F %T")
expect(page).to have_field "price", with: "10.0"
expect(page).to have_field "on_hand", with: "6"
fill_in "product_name", with: "Big Bag Of Potatoes"
select(s2.name, :from => 'supplier')
select(s2.name, :from => 'producer')
fill_in "available_on", with: (Date.today-3).strftime("%F %T")
fill_in "price", with: "20"
select "Weight (kg)", from: "variant_unit_with_scale"
@@ -946,17 +814,17 @@ feature %q{
fill_in "display_as", with: "Big Bag"
click_button 'Update'
page.find("span#update-status-message").should have_content "Update complete"
expect(page.find("span#update-status-message")).to have_content "Update complete"
p.reload
p.name.should == "Big Bag Of Potatoes"
p.supplier.should == s2
p.variant_unit.should == "weight"
p.variant_unit_scale.should == 1000 # Kg
p.available_on.should == 3.days.ago.beginning_of_day
p.master.display_as.should == "Big Bag"
p.price.should == 20.0
p.on_hand.should == 18
expect(p.name).to eq "Big Bag Of Potatoes"
expect(p.supplier).to eq s2
expect(p.variant_unit).to eq "weight"
expect(p.variant_unit_scale).to eq 1000 # Kg
expect(p.available_on).to eq 3.days.ago.beginning_of_day
expect(p.master.display_as).to eq "Big Bag"
expect(p.price).to eq 20.0
expect(p.on_hand).to eq 18
end
end
end