Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Added more specs, added cart utilities
Damian Legawieccadb0cdd5e87
diff --git a/storefront/lib/spree/storefront/testing_support/cart_utils.rb b/storefront/lib/spree/storefront/testing_support/cart_utils.rbnew file mode 100644index 0000000000..95f252ae55--- /dev/null+++ b/storefront/lib/spree/storefront/testing_support/cart_utils.rb@@ -0,0 +1,30 @@+module Spree+ module Storefront+ module TestingSupport+ module CartUtils+ def add_to_cart(product, goto_checkout = false)+ visit spree.product_path(product)++ click_button Spree.t(:add_to_cart)+ wait_for_turbo+ expect(page).to have_link('Checkout')++ def view_cart+ visit spree.cart_path+ end++ def click_checkout+ click_link 'Checkout'+ expect(page).to have_content('Contact information').and have_content('Shipping Address')+ end++ if block_given?+ yield+ else+ goto_checkout ? click_checkout : view_cart+ end+ end+ end+ end+ end+enddiff --git a/storefront/spec/features/account/store_credits_spec.rb b/storefront/spec/features/account/store_credits_spec.rbindex cf1a57f87f..68fd7d543b 100644--- a/storefront/spec/features/account/store_credits_spec.rb+++ b/storefront/spec/features/account/store_credits_spec.rb@@ -1,5 +1,4 @@require 'spec_helper'-RSpec.describe 'Account store credits', type: :feature dolet(:user) { create(:user) }let!(:store_credit) { create(:store_credit, user: user, amount: 100.00) }diff --git a/storefront/spec/features/cart_spec.rb b/storefront/spec/features/cart_spec.rbnew file mode 100644index 0000000000..ba5e5fe5d3--- /dev/null+++ b/storefront/spec/features/cart_spec.rb@@ -0,0 +1,109 @@+require 'spec_helper'++describe 'Cart', type: :feature do+ let(:store) { Spree::Store.default }+ let(:product) { create(:product, stores: [store]) }+ let!(:variant) { create(:variant, product: product) }+ let(:line_item) { order.line_items.first }++ shared_examples 'renders cart page' do+ it 'shows total' do+ expect(page).to have_content('Total')+ expect(page).to have_content(order.display_item_total.to_html)+ end++ it 'shows line items' do+ expect(page).to have_content(line_item.name)+ expect(page).to have_content(line_item.display_total.to_html)+ end+ end++ shared_examples 'updates cart' do+ it 'can update line item quantity', js: true do+ within '#line-items:first-child' do+ find('.quantity-increase-button').click+ end++ wait_for_turbo++ within '#line-items:first-child' do+ expect(page).to have_field('line_item_quantity', with: '2')+ end+ expect(page).to have_content(line_item.price * 2)+ expect(order.reload.item_total).to eq(line_item.price * 2)++ within '#line-items:first-child' do+ find('.quantity-decrease-button').click+ end++ wait_for_turbo+ within '#line-items:first-child' do+ expect(page).to have_field('line_item_quantity', with: '1')+ end+ expect(page).to have_content(line_item.price)+ expect(order.reload.item_total).to eq(line_item.price)+ end++ it 'can remove line item' do+ line_item_name = line_item.name++ within '#line-items:first-child' do+ find('.remove-line-item-button').click+ end++ wait_for_turbo++ expect(page).to have_content('Your cart is empty')+ expect(page).not_to have_content(line_item_name)+ end+ end++ shared_examples 'renders empty cart page' do+ it 'renders empty cart page' do+ expect(page).to have_content('Your cart is empty')+ end+ end++ context 'order by token' do+ context 'order exists' do+ let(:order) { create(:order_with_line_items, store: store) }+ let(:order_token) { order.token }++ before do+ visit spree.cart_path(order_token: order_token)+ end++ it_behaves_like 'renders cart page'+ it_behaves_like 'updates cart'+ end++ context 'order does not exist' do+ before do+ visit spree.cart_path(order_token: 'invalid')+ end++ it_behaves_like 'renders empty cart page'+ end+ end++ context 'order by cookie' do+ context 'order exists', js: true do+ before do+ add_to_cart(product)+ end++ let(:order) { Spree::Order.last }++ it_behaves_like 'renders cart page'+ it_behaves_like 'updates cart'+ end++ context 'order does not exist' do+ before do+ visit spree.cart_path+ end++ it_behaves_like 'renders empty cart page'+ end+ end+enddiff --git a/storefront/spec/features/order_status_page_spec.rb b/storefront/spec/features/order_status_page_spec.rbnew file mode 100644index 0000000000..8b7d4d899e--- /dev/null+++ b/storefront/spec/features/order_status_page_spec.rb@@ -0,0 +1,26 @@+require 'spec_helper'++describe 'Order Status Page', type: :feature do+ let!(:order) { create(:order_ready_to_ship, number: 'R1234567', email: '[email protected]', user: nil, store: Spree::Store.default, ship_address: create(:address), bill_address: create(:bill_address)) }++ context 'when order is not found' do+ it 'shows error message' do+ visit spree.new_order_status_path+ fill_in 'email', with: '[email protected]'+ fill_in 'number', with: 'R1234568'+ click_button 'Find your order'+ expect(page).to have_content("We couldn't find your order")+ end+ end++ context 'when order is found' do+ it 'shows order details' do+ visit spree.new_order_status_path+ fill_in 'email', with: order.email+ fill_in 'number', with: order.number+ click_button 'Find your order'+ expect(page).to have_content('Order R1234567')+ expect(page).to have_current_path(spree.order_path(order, token: order.token))+ end+ end+enddiff --git a/storefront/spec/features/search_spec.rb b/storefront/spec/features/search_spec.rbnew file mode 100644index 0000000000..a0de649edc--- /dev/null+++ b/storefront/spec/features/search_spec.rb@@ -0,0 +1,23 @@+require 'spec_helper'++RSpec.describe 'Search results page', type: :feature, js: true, job: true do+ context 'with query' do+ before do+ visit spree.search_path(q: 'Test')+ end++ it 'displays search results page' do+ expect(page).to have_current_path(spree.search_path(q: 'Test'))+ end+ end++ context 'without query' do+ before do+ visit spree.search_path+ end++ it 'redirects to collection page' do+ expect(page).to have_current_path(spree.search_path)+ end+ end+enddiff --git a/storefront/spec/spec_helper.rb b/storefront/spec/spec_helper.rbindex ec606d96d8..f94787d47e 100644--- a/storefront/spec/spec_helper.rb+++ b/storefront/spec/spec_helper.rb@@ -44,6 +44,7 @@ require 'spree/testing_support/controller_requests'require 'spree/testing_support/url_helpers'require 'spree/testing_support/order_walkthrough'require 'spree/storefront/testing_support/capybara_utils'+require 'spree/storefront/testing_support/cart_utils'require 'spree/testing_support/capybara_config'require 'spree/testing_support/rspec_retry_config'require 'spree/testing_support/image_helpers'@@ -87,6 +88,7 @@ RSpec.configure do |config|config.include FactoryBot::Syntax::Methodsconfig.include Spree::Storefront::TestingSupport::CapybaraUtils+ config.include Spree::Storefront::TestingSupport::CartUtilsconfig.include Spree::TestingSupport::Preferencesconfig.include Spree::TestingSupport::UrlHelpersconfig.include Spree::TestingSupport::ControllerRequests, type: :controller