Use embedded shops example for tests

This commit is contained in:
Maikel Linke
2018-07-12 17:11:21 +10:00
parent 66980b247a
commit 599f1a966b
3 changed files with 34 additions and 17 deletions

View File

@@ -0,0 +1,20 @@
<html>
<head><title>Embedded Shop</title></head>
<body>
<p>
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: <code>embedded-shop-preview.html?bawbawfoodhub</code>
</p>
<iframe style="width:100%;min-height:35em"></iframe>
<script>
var unsafeName = window.location.search.substr(1);
var shop = unsafeName.replace(/[^a-z0-9_-]/g, '');
var iframe = document.querySelector("iframe");
iframe.src = "/" + shop + "/shop?embedded_shopfront=true";
</script>
</body>
</html>

View File

@@ -7,8 +7,6 @@ feature "Using embedded shopfront functionality", js: true do
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 +22,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 +31,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 +43,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 +92,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 +105,16 @@ feature "Using embedded shopfront functionality", js: true do
end
end
private
def on_embedded_page
expect(page).to have_selector "iframe"
within_frame :frame do
yield
end
end
def login_with_modal
expect(page).to have_selector 'div.login-modal', visible: true

View File

@@ -1,8 +0,0 @@
<html>
<head></head>
<body>
<iframe src="http://localhost:9999/test_enterprise/shop?embedded_shopfront=true" name="test_iframe" class="test_iframe" id="test_iframe" style="width:100%;min-height:35em"></iframe>
</body>
</html>