Skip to content

Commit

Permalink
Merge pull request #11645 from filipefurtad0/activate_buu_toggle_by_d…
Browse files Browse the repository at this point in the history
…efault_to_run_the_test_suite

[BUU] Activate admin_style_v3 for most system specs
  • Loading branch information
mkllnk authored Jul 2, 2024
2 parents d3e00cd + b1aafbf commit a83daae
Show file tree
Hide file tree
Showing 42 changed files with 631 additions and 343 deletions.
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3863,7 +3863,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
logout: "Logout"

date_range: "Date Range"
status: "status"
status: "Status"
new: "New"
start: "Start"
end: "End"
Expand Down
4 changes: 4 additions & 0 deletions spec/base_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
config.before(:each) do
Flipper.features.each(&:remove)
OpenFoodNetwork::FeatureToggle.setup!

# activate feature toggle admin_style_v3 to use new admin interface and run the build
Flipper.enable(:admin_style_v3)
end

config.before(:each, :feature) do |example|
Expand Down Expand Up @@ -284,6 +287,7 @@ def handle_webmock_error(exception)
config.include OpenFoodNetwork::PerformanceHelper
config.include ActiveJob::TestHelper
config.include ReportsHelper
config.include TomSelectHelper, type: :system

config.include ViewComponent::TestHelpers, type: :component

Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion spec/support/features/datepicker_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Features
module DatepickerHelper
def choose_today_from_datepicker
within(".flatpickr-calendar.open") do
find("button", text: "TODAY").click
find("button", text: "Today").click
end
end

Expand Down
11 changes: 11 additions & 0 deletions spec/support/overlapping_elements_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

def dismiss_warning
# Click dismiss on distributor warning
click_button 'Dismiss'
end

def trigger_click(id, text)
# replace node buy the elements node, for example
page.find(id, text).trigger("click")
end
39 changes: 39 additions & 0 deletions spec/support/tom_select_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

module TomSelectHelper
def tomselect_open(field_name)
page.find("##{field_name}-ts-control").click
end

def tomselect_multiselect(value, options)
tomselect_wrapper = page.find("[name='#{options[:from]}']").sibling(".ts-wrapper")
tomselect_wrapper.find(".ts-control").click
tomselect_wrapper.find(:css, '.ts-dropdown.multi .ts-dropdown-content .option',
text: value).click
end

def tomselect_search_and_select(value, options)
tomselect_wrapper = page.find("[name='#{options[:from]}']").sibling(".ts-wrapper")
tomselect_wrapper.find(".ts-control").click
# Use send_keys as setting the value directly doesn't trigger the search
tomselect_wrapper.find(:css, '.ts-dropdown input.dropdown-input').send_keys(value)
tomselect_wrapper.find(:css, '.ts-dropdown .ts-dropdown-content .option', text: value).click
end

def tomselect_select(value, options)
tomselect_wrapper = page.find("[name='#{options[:from]}']").sibling(".ts-wrapper")
tomselect_wrapper.find(".ts-control").click

tomselect_wrapper.find(:css, '.ts-dropdown .ts-dropdown-content .option', text: value).click
end

def select_tom_select(value, from:)
container = find(:id, from)

within(container) do
find('.ts-control').send_keys(value)
end

find('.ts-dropdown .ts-dropdown-content .option', text: /#{Regexp.quote(value)}/i).click
end
end
4 changes: 2 additions & 2 deletions spec/system/admin/authentication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_login_button
expect(page).to have_content "DASHBOARD"
expect(page).to have_content "Dashboard"
expect(page).to have_current_path spree.admin_dashboard_path
expect(page).not_to have_content "CONFIGURATION"
expect(page).not_to have_content "Configuration"
end

it "viewing my account" do
Expand Down
4 changes: 2 additions & 2 deletions spec/system/admin/bulk_order_cancellation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
expect(page).to have_selector('span', text: 'COMPLETE', count: 2)

page.find('#selectAll').trigger('click')
page.find("span.icon-reorder", text: "ACTIONS").click
page.find("span.icon-reorder", text: "Actions").click
within ".ofn-drop-down .menu" do
expect(page).to have_selector("span", text: "Cancel Orders")
page.find("span", text: "Cancel Orders").click
Expand All @@ -43,7 +43,7 @@
.and change { o2.reload.state }.from('complete').to('canceled')
end

# Verify that the orders have a STATE of CANCELLED
# Verify that the orders have a STATE of Cancelled
expect(page).to have_selector('span.canceled', text: 'CANCELLED', count: 2)
end
end
Expand Down
46 changes: 23 additions & 23 deletions spec/system/admin/bulk_order_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@
end

it "orders by completion date" do
find("a", text: 'COMPLETED AT').click # sets ascending ordering
find("a", text: 'Completed at').click # sets ascending ordering
expect(page).to have_content(
/#{li2.product.name}.*#{li1.product.name}.*#{li22.product.name}.*#{li21.product.name}/m
)
find("a", text: 'COMPLETED AT').click # sets descending ordering
find("a", text: 'Completed at').click # sets descending ordering
expect(page).to have_content(
/#{li21.product.name}.*#{li22.product.name}.*#{li1.product.name}.*#{li2.product.name}/m
)
Expand Down Expand Up @@ -155,9 +155,9 @@
expect(page).to have_content "Little Fish", count: 15
expect(page).not_to have_content "Big Fish"
end
find("a", text: "Clear").click # closes BOM box
expect(page).to have_content "Little Fish", count: 10
click_link "Clear" # closes BOM box
expect(page).to have_content "Big Fish", count: 5
expect(page).to have_content "Little Fish", count: 10
end
end

Expand Down Expand Up @@ -311,7 +311,7 @@
end

it "displays a column for user's full name" do
expect(page).to have_selector "th.full_name", text: "NAME"
expect(page).to have_selector "th.full_name", text: "Name"
expect(page)
.to have_selector "td.full_name",
text: "#{o1.bill_address.last_name}, #{o1.bill_address.first_name}"
Expand All @@ -320,33 +320,33 @@

it "displays a column for order date" do
expect(page).to have_selector "th.date",
text: 'Completed at'.upcase
text: 'Completed at'
expect(page).to have_selector "td.date", text: o1.completed_at.strftime('%B %d, %Y')
expect(page).to have_selector "td.date", text: o2.completed_at.strftime('%B %d, %Y')
end

it "displays a column for producer" do
expect(page).to have_selector "th.producer", text: "PRODUCER"
expect(page).to have_selector "th.producer", text: "Producer"
expect(page).to have_selector "td.producer", text: li1.product.supplier.name
expect(page).to have_selector "td.producer", text: li2.product.supplier.name
end

it "displays a column for variant description, which shows only product name " \
"when options text is blank" do
expect(page).to have_selector "th.variant", text: "PRODUCT: UNIT"
expect(page).to have_selector "th.variant", text: "Product: Unit"
expect(page).to have_selector "td.variant", text: li1.product.name
expect(page).to have_selector "td.variant",
text: "#{li2.product.name}: #{li2.variant.options_text}"
end

it "displays a field for quantity" do
expect(page).to have_selector "th.quantity", text: "QUANTITY"
expect(page).to have_selector "th.quantity", text: "Quantity"
expect(page).to have_field "quantity", with: li1.quantity.to_s
expect(page).to have_field "quantity", with: li2.quantity.to_s
end

it "displays a column for max quantity" do
expect(page).to have_selector "th.max", text: "MAX"
expect(page).to have_selector "th.max", text: "Max"
expect(page).to have_selector "td.max", text: li1.max_quantity.to_s
expect(page).to have_selector "td.max", text: li2.max_quantity.to_s
end
Expand Down Expand Up @@ -550,13 +550,13 @@

context "using column display toggle" do
it "displays the default selected columns" do
expect(page).to have_selector "th", text: "NAME"
expect(page).to have_selector "th", text: "Name"
expect(page).to have_selector "th",
text: 'Completed at'.upcase
expect(page).to have_selector "th", text: "PRODUCER"
expect(page).to have_selector "th", text: "PRODUCT: UNIT"
expect(page).to have_selector "th", text: "QUANTITY"
expect(page).to have_selector "th", text: "MAX"
text: 'Completed at'
expect(page).to have_selector "th", text: "Producer"
expect(page).to have_selector "th", text: "Product: Unit"
expect(page).to have_selector "th", text: "Quantity"
expect(page).to have_selector "th", text: "Max"
end

context "hiding a column, by de-selecting it from the drop-down" do
Expand All @@ -565,13 +565,13 @@
end

it "shows all default columns, except the de-selected column" do
expect(page).not_to have_selector "th", text: "PRODUCER"
expect(page).to have_selector "th", text: "NAME"
expect(page).not_to have_selector "th", text: "Producer"
expect(page).to have_selector "th", text: "Name"
expect(page).to have_selector "th",
text: 'Completed at'.upcase
expect(page).to have_selector "th", text: "PRODUCT: UNIT"
expect(page).to have_selector "th", text: "QUANTITY"
expect(page).to have_selector "th", text: "MAX"
text: 'Completed at'
expect(page).to have_selector "th", text: "Product: Unit"
expect(page).to have_selector "th", text: "Quantity"
expect(page).to have_selector "th", text: "Max"
end
end
end
Expand Down Expand Up @@ -1209,7 +1209,7 @@

context "clicking 'Clear' in group buy box" do
before :each do
find("a", text: "Clear").click
click_link "Clear" # closes BOM box
end

it "shows all products and clears group buy box" do
Expand Down
19 changes: 8 additions & 11 deletions spec/system/admin/bulk_product_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

RSpec.describe '
As an Administrator
I want to be able to manage products in bulk
I want to be able to manage products in bulk (with the old Products screen)
' do
include AdminHelper
include AuthenticationHelper
include WebHelper

before { Flipper.disable(:admin_style_v3) }

describe "listing products" do
before do
login_as_admin
Expand All @@ -18,19 +20,12 @@
it "displays a list of products" do
p1 = FactoryBot.create(:product)
p2 = FactoryBot.create(:product)

visit spree.admin_products_path

expect(page).to have_field "product_name", with: p1.name
expect(page).to have_field "product_name", with: p2.name
end

it "displays a message when number of products is zero" do
visit spree.admin_products_path

expect(page).to have_text "No products yet. Why don't you add some?"
end

it "displays a select box for suppliers, with the appropriate supplier selected" do
s1 = FactoryBot.create(:supplier_enterprise)
s2 = FactoryBot.create(:supplier_enterprise)
Expand Down Expand Up @@ -202,7 +197,7 @@
visit spree.admin_products_path

find("a", text: "NEW PRODUCT").click
expect(page).to have_content 'NEW PRODUCT'
expect(page).to have_content "NEW PRODUCT"

fill_in 'product_name', with: 'Big Bag Of Apples'
select supplier.name, from: 'product_supplier_id'
Expand Down Expand Up @@ -311,8 +306,10 @@
end

it "creating a variant with unit value is: '120g' and 'on_demand' checked" do
scroll_to(:bottom)

within "tr#v_#{v2.id}" do
page.find(".add-variant").trigger("click")
page.find(".add-variant").click
end

within "tr#v_-1" do
Expand Down Expand Up @@ -705,7 +702,7 @@

toggle_columns /^.{0,1}Producer$/i

expect(page).not_to have_selector "th", text: "PRODUCER"
expect(page).not_to have_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"
Expand Down
2 changes: 1 addition & 1 deletion spec/system/admin/configuration/general_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

context 'editing currency symbol position' do
it 'updates its position' do
expect(page).to have_content('CURRENCY SETTINGS')
expect(page).to have_content('Currency Settings')

within('.currency') do
find("[for='currency_symbol_position_after']").click
Expand Down
4 changes: 2 additions & 2 deletions spec/system/admin/customers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@
end

it 'updates the existing billing address' do
expect(page).to have_content 'BILLING ADDRESS'
expect(page).to have_content 'Billing Address'
first('#bill-address-link').click
wait_for_modal_fade_in

Expand All @@ -374,7 +374,7 @@
end

it 'creates a new shipping address' do
expect(page).to have_content 'SHIPPING ADDRESS'
expect(page).to have_content 'Shipping Address'

first('#ship-address-link').click
wait_for_modal_fade_in
Expand Down
2 changes: 1 addition & 1 deletion spec/system/admin/enterprise_roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
def navigate_to_enterprise_users
scroll_to(:bottom)
within ".side_menu" do
click_link "Users"
trigger_click(:link, "Users")
end
end

Expand Down
Loading

0 comments on commit a83daae

Please sign in to comment.