diff --git a/public/embedded-shop-preview.html b/public/embedded-shop-preview.html new file mode 100644 index 0000000000..a3c53f6440 --- /dev/null +++ b/public/embedded-shop-preview.html @@ -0,0 +1,20 @@ + + Embedded Shop + + +

+ This is a preview page for embedded shops. + Choose a shop to display by copying its permalink id into the URL after the question mark. + Example: embedded-shop-preview.html?bawbawfoodhub +

+ + + + + + diff --git a/spec/features/consumer/shopping/embedded_groups_spec.rb b/spec/features/consumer/shopping/embedded_groups_spec.rb index 4122fb30ce..b53f12c2eb 100644 --- a/spec/features/consumer/shopping/embedded_groups_spec.rb +++ b/spec/features/consumer/shopping/embedded_groups_spec.rb @@ -1,25 +1,22 @@ require 'spec_helper' feature "Using embedded shopfront functionality", js: true do - - Capybara.server_port = 9999 + include OpenFoodNetwork::EmbeddedPagesHelper describe 'embedded groups' do let(:enterprise) { create(:distributor_enterprise) } - let!(:group) { create(:enterprise_group, enterprises: [enterprise], permalink: 'group1', on_front_page: true) } + let(:group) { create(:enterprise_group, enterprises: [enterprise]) } before do Spree::Config[:enable_embedded_shopfronts] = true Spree::Config[:embedded_shopfronts_whitelist] = 'test.com' page.driver.browser.js_errors = false allow_any_instance_of(ActionDispatch::Request).to receive(:referer).and_return('https://www.test.com') - Capybara.current_session.driver.visit('spec/support/views/group_iframe_test.html') + visit "/embedded-group-preview.html?#{group.permalink}" end it "displays in an iframe" do - expect(page).to have_selector 'iframe#group_test_iframe' - - within_frame 'group_test_iframe' do + on_embedded_page do within 'div#group-page' do expect(page).to have_content 'About Us' end @@ -27,9 +24,7 @@ feature "Using embedded shopfront functionality", js: true do end it "displays powered by OFN text at bottom of page" do - expect(page).to have_selector 'iframe#group_test_iframe' - - within_frame 'group_test_iframe' do + on_embedded_page do within 'div#group-page' do expect(page).to have_selector 'div.powered-by-embedded' expect(page).to have_css "img[src*='favicon.ico']" @@ -40,9 +35,7 @@ feature "Using embedded shopfront functionality", js: true do end it "doesn't display contact details when embedded" do - expect(page).to have_selector 'iframe#group_test_iframe' - - within_frame 'group_test_iframe' do + on_embedded_page do within 'div#group-page' do expect(page).to have_no_selector 'div.contact-container' @@ -52,9 +45,7 @@ feature "Using embedded shopfront functionality", js: true do end it "does not display the header when embedded" do - expect(page).to have_selector 'iframe#group_test_iframe' - - within_frame 'group_test_iframe' do + on_embedded_page do within 'div#group-page' do expect(page).to have_no_selector 'header' expect(page).to have_no_selector 'img.group-logo' @@ -63,14 +54,17 @@ feature "Using embedded shopfront functionality", js: true do end end - it 'opens links to shops in a new window' do - expect(page).to have_selector 'iframe#group_test_iframe' - - within_frame 'group_test_iframe' do + it "opens links to shops in a new window" do + on_embedded_page do within 'div#group-page' do - enterprise_links = page.all(:xpath, "//*[contains(@href, 'enterprise-5/shop')]", :visible => :false).count - enterprise_links_with_target_blank = page.all(:xpath, "//*[contains(@href, 'enterprise-5/shop') and @target = '_blank']", :visible => :false).count - expect(enterprise_links).to equal(enterprise_links_with_target_blank) + shop_links_xpath = "//*[contains(@href, '#{enterprise.permalink}/shop')]" + + expect(page).to have_xpath shop_links_xpath, visible: false + + shop_links = page.all(:xpath, shop_links_xpath, visible: false) + shop_links.each do |link| + expect(link[:target]).to eq "_blank" + end end end end diff --git a/spec/features/consumer/shopping/embedded_shopfronts_spec.rb b/spec/features/consumer/shopping/embedded_shopfronts_spec.rb index 87b6a7e5ca..1b965db512 100644 --- a/spec/features/consumer/shopping/embedded_shopfronts_spec.rb +++ b/spec/features/consumer/shopping/embedded_shopfronts_spec.rb @@ -1,14 +1,13 @@ require 'spec_helper' feature "Using embedded shopfront functionality", js: true do + include OpenFoodNetwork::EmbeddedPagesHelper include AuthenticationWorkflow include WebHelper include ShopWorkflow include CheckoutWorkflow include UIComponentHelper - Capybara.server_port = 9999 - describe "using iframes" do let(:distributor) { create(:distributor_enterprise, name: 'My Embedded Hub', permalink: 'test_enterprise', with_payment_and_shipping: true) } let(:supplier) { create(:supplier_enterprise) } @@ -24,9 +23,8 @@ feature "Using embedded shopfront functionality", js: true do Spree::Config[:enable_embedded_shopfronts] = true Spree::Config[:embedded_shopfronts_whitelist] = 'test.com' - page.driver.browser.js_errors = false allow_any_instance_of(ActionDispatch::Request).to receive(:referer).and_return('https://www.test.com') - Capybara.current_session.driver.visit('spec/support/views/iframe_test.html') + visit "/embedded-shop-preview.html?#{distributor.permalink}" end after do @@ -34,9 +32,7 @@ feature "Using embedded shopfront functionality", js: true do end it "displays modified shopfront layout" do - expect(page).to have_selector 'iframe#test_iframe' - - within_frame 'test_iframe' do + on_embedded_page do within 'nav.top-bar' do expect(page).to have_selector 'ul.left', visible: false expect(page).to have_selector 'ul.center', visible: false @@ -48,7 +44,7 @@ feature "Using embedded shopfront functionality", js: true do end xit "allows shopping and checkout" do - within_frame 'test_iframe' do + on_embedded_page do fill_in "variants[#{variant.id}]", with: 1 wait_until_enabled 'input.add_to_cart' @@ -97,7 +93,7 @@ feature "Using embedded shopfront functionality", js: true do end it "redirects to embedded hub on logout when embedded" do - within_frame 'test_iframe' do + on_embedded_page do find('ul.right li#login-link a').click login_with_modal @@ -110,6 +106,8 @@ feature "Using embedded shopfront functionality", js: true do end end + private + def login_with_modal expect(page).to have_selector 'div.login-modal', visible: true diff --git a/spec/support/embedded_pages_helper.rb b/spec/support/embedded_pages_helper.rb new file mode 100644 index 0000000000..5eed420394 --- /dev/null +++ b/spec/support/embedded_pages_helper.rb @@ -0,0 +1,9 @@ +module OpenFoodNetwork + module EmbeddedPagesHelper + def on_embedded_page + within_frame :frame do + yield + end + end + end +end diff --git a/spec/support/views/group_iframe_test.html b/spec/support/views/group_iframe_test.html deleted file mode 100644 index dcb4abbceb..0000000000 --- a/spec/support/views/group_iframe_test.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/spec/support/views/iframe_test.html b/spec/support/views/iframe_test.html deleted file mode 100644 index fe71aa66e3..0000000000 --- a/spec/support/views/iframe_test.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - -