Skip to content

Commit

Permalink
Tests: add browser tests for xtheme language forms
Browse files Browse the repository at this point in the history
POS-2510
  • Loading branch information
chessbr committed Jul 20, 2018
1 parent 39a5ec3 commit 79d642a
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 2 deletions.
11 changes: 11 additions & 0 deletions shuup/testing/browser_utils.py
Expand Up @@ -121,3 +121,14 @@ def click_element(browser, css_selector, timeout=10, frequency=1.0, header_heigh
timeout=timeout,
frequency=frequency)
browser.find_by_css(css_selector).click()


def page_has_loaded(browser):
"""
Returns whether the page has loaded
:param browser:
:type browser: splinter.browser.Browser
:rtype bool
"""
return browser.evaluate_script("document.readyState") == "complete"
4 changes: 2 additions & 2 deletions shuup/testing/utils.py
Expand Up @@ -111,7 +111,7 @@ def initialize_front_browser_test(browser, live_server):


def initialize_admin_browser_test(
browser, live_server, settings, username="admin", password="password", onboarding=False):
browser, live_server, settings, username="admin", password="password", onboarding=False, language="en"):
if not onboarding:
settings.SHUUP_SETUP_WIZARD_PANE_SPEC = []
activate("en")
Expand All @@ -126,6 +126,6 @@ def initialize_admin_browser_test(
if not onboarding:
# set shop language to eng
browser.find_by_id("dropdownMenu").click()
browser.find_by_xpath('//a[@data-value="en"]').first.click()
browser.find_by_xpath('//a[@data-value="%s"]' % language).first.click()

return browser
132 changes: 132 additions & 0 deletions shuup_tests/browser/front/test_xtheme_plugin_form.py
@@ -0,0 +1,132 @@
# -*- coding: utf-8 -*-
# This file is part of Shuup.
#
# Copyright (c) 2012-2018, Shuup Inc. All rights reserved.
#
# This source code is licensed under the OSL-3.0 license found in the
# LICENSE file in the root directory of this source tree.
import os

import time
import pytest
from django.test.utils import override_settings

from django.utils.translation import get_language, activate
from shuup.testing.browser_utils import (
click_element, page_has_loaded, wait_until_appeared,
wait_until_condition
)
from shuup.testing.utils import initialize_admin_browser_test

pytestmark = pytest.mark.skipif(os.environ.get("SHUUP_BROWSER_TESTS", "0") != "1", reason="No browser tests run.")



@pytest.mark.parametrize("default_language", ["it", "pt-br", "fi"])
@pytest.mark.browser
@pytest.mark.djangodb
def test_xtheme_plugin_form_language_order(admin_user, browser, live_server, settings, default_language):
"""
Test that the first language option is the Parler default
As you can see, we check for that the page has loaded and we use a sleep of 1 second.
This is necessary specially into iframes. On this test, when we click to add a new plugin row
or after a row selection, the iframe content is changed through a request,
like a internal link when user clicks on a anchor. We have to make sure the NEW content is loaded
before doing any element check, because it looks like the iframe won't find the correct elements
if you start checking that before the new content gets loaded.
"""
with override_settings(PARLER_DEFAULT_LANGUAGE_CODE=default_language):
browser = initialize_admin_browser_test(browser, live_server, settings)
browser.visit(live_server + "/")

# Start edit
wait_until_condition(browser, lambda x: page_has_loaded(x), timeout=20)
wait_until_appeared(browser, ".xt-edit-toggle button[type='submit']")
click_element(browser, ".xt-edit-toggle button[type='submit']")

placeholder_selector = "#xt-ph-front_content-xtheme-person-contact-layout"
placeholder_name = "front_content"
wait_until_condition(browser, lambda x: x.is_element_present_by_css(placeholder_selector))
click_element(browser, placeholder_selector)

with browser.get_iframe("xt-edit-sidebar-iframe") as iframe:
# make sure all scripts are loaded
wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

wait_until_condition(iframe, lambda x: x.is_text_present("Edit Placeholder: %s" % placeholder_name))
wait_until_appeared(iframe, "button.layout-add-row-btn")
time.sleep(1)
wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

# click to add a new row
click_element(iframe, "button.layout-add-row-btn")
time.sleep(1)
wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

# select the last row (the added one)
click_element(iframe, "button.layout-add-row-btn")
iframe.find_by_css("div.layout-cell").last.click()
time.sleep(1)
wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

# select the TextPlugin
wait_until_appeared(iframe, "select[name='general-plugin']")
iframe.select("general-plugin", "text")
time.sleep(1)
wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)
wait_until_appeared(iframe, "ul.editor-tabs")

# check the languages order
languages = [el.text for el in iframe.find_by_css("ul.editor-tabs li a")]
assert languages[0] == default_language


@pytest.mark.parametrize("language", ["it", "pt-br", "fi", "en"])
@pytest.mark.browser
@pytest.mark.djangodb
def test_xtheme_plugin_form_selected_language_pane(admin_user, browser, live_server, settings, language):
"""
Test that the current language is selected by default
"""
browser = initialize_admin_browser_test(browser, live_server, settings, language=language)
browser.visit(live_server + "/")

# Start edit
wait_until_condition(browser, lambda x: page_has_loaded(x), timeout=20)
wait_until_appeared(browser, ".xt-edit-toggle button[type='submit']")
click_element(browser, ".xt-edit-toggle button[type='submit']")

placeholder_selector = "#xt-ph-front_content-xtheme-person-contact-layout"
wait_until_condition(browser, lambda x: x.is_element_present_by_css(placeholder_selector))
click_element(browser, placeholder_selector)

with browser.get_iframe("xt-edit-sidebar-iframe") as iframe:
# make sure all scripts are loaded
wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

wait_until_condition(iframe, lambda x: x.is_text_present("front_content"))
wait_until_appeared(iframe, "button.layout-add-row-btn")
time.sleep(1)
wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

# click to add a new row
click_element(iframe, "button.layout-add-row-btn")
time.sleep(1)
wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

# select the last row (the added one)
click_element(iframe, "button.layout-add-row-btn")
iframe.find_by_css("div.layout-cell").last.click()
time.sleep(1)
wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)

# select the TextPlugin
wait_until_appeared(iframe, "select[name='general-plugin']")
iframe.select("general-plugin", "text")
time.sleep(1)
wait_until_condition(iframe, lambda x: page_has_loaded(x), timeout=20)
wait_until_appeared(iframe, "ul.editor-tabs")

# check the active language
assert language == iframe.find_by_css("ul.editor-tabs li.active a").first.text

0 comments on commit 79d642a

Please sign in to comment.