diff --git a/common/test/acceptance/pages/lms/dashboard.py b/common/test/acceptance/pages/lms/dashboard.py index cd6aa199a852..ceee2e3ead9d 100644 --- a/common/test/acceptance/pages/lms/dashboard.py +++ b/common/test/acceptance/pages/lms/dashboard.py @@ -4,6 +4,7 @@ """ from bok_choy.page_object import PageObject +from bok_choy.promise import Promise, EmptyPromise, fulfill_after, fulfill from . import BASE_URL @@ -18,14 +19,6 @@ class DashboardPage(PageObject): def is_browser_on_page(self): return self.is_css_present('section.my-courses') - @property - def current_courses_text(self): - text_items = self.css_text('section#my-courses') - if len(text_items) > 0: - return text_items[0] - else: - return "" - @property def available_courses(self): """ @@ -38,6 +31,47 @@ def _get_course_name(el): return self.css_map('section.info > hgroup > h3 > a', _get_course_name) + def change_language(self, code): + """ + Change the language on the dashboard to the language corresponding with `code`. + """ + # Get the current section heading, so we can compare it to the heading + # when we change the language. + old_text = self.current_courses_text + + lang_changed = EmptyPromise( + lambda: old_text != self.current_courses_text, + "Current courses text changed" + ) + + with fulfill_after(lang_changed): + self.css_click(".edit-language") + self.select_option("language", code) + self.css_click("#submit-lang") + + @property + def is_dummy_lang(self): + """ + Return a boolean indicating whether dashboard is displaying dummy translation strings. + """ + return u"ÇÜRRÉNT".encode('utf-8') in self.current_courses_text.encode('utf-8') + + @property + def current_courses_text(self): + """ + Return the text of the "current courses" title. + """ + def _check_func(): + text_items = self.css_text('section#my-courses') + if len(text_items) < 1: + return (False, None) + elif not text_items[0]: + return (False, None) + else: + return (True, text_items[0]) + + return fulfill(Promise(_check_func, "Retrieved current courses title")) + def view_course(self, course_id): """ Go to the course with `course_id` (e.g. edx/Open_DemoX/edx_demo_course) @@ -68,11 +102,3 @@ def _link_css(self, course_id): return "a.enter-course:nth-of-type({0})".format(link_index + 1) else: return None - - def change_language(self, code): - """ - Change the language on the dashboard to the language corresponding with `code`. - """ - self.css_click(".edit-language") - self.select_option("language", code) - self.css_click("#submit-lang") diff --git a/common/test/acceptance/pages/lms/logout.py b/common/test/acceptance/pages/lms/logout.py new file mode 100644 index 000000000000..9302dec3a243 --- /dev/null +++ b/common/test/acceptance/pages/lms/logout.py @@ -0,0 +1,14 @@ +from bok_choy.page_object import PageObject +from . import BASE_URL + + +class LogoutPage(PageObject): + """ + Logout from the LMS by directly going to the logout URL. + """ + def is_browser_on_page(self): + return True + + @property + def url(self): + return BASE_URL + "/logout" diff --git a/common/test/acceptance/tests/test_language.py b/common/test/acceptance/tests/test_language.py new file mode 100644 index 000000000000..d3597fbfecc0 --- /dev/null +++ b/common/test/acceptance/tests/test_language.py @@ -0,0 +1,46 @@ +from bok_choy.web_app_test import WebAppTest +from bok_choy.promise import fulfill, Promise + +from .helpers import UniqueCourseTest +from ..pages.lms.dashboard import DashboardPage +from ..pages.lms.logout import LogoutPage +from ..pages.studio.auto_auth import AutoAuthPage + + +class LanguageTest(UniqueCourseTest): + """ + Tests that the change language functionality on the dashboard works. + """ + + def setUp(self): + """ + Visit the dashboard page. + """ + super(LanguageTest, self).setUp() + + # Log in and visit the dashboard page + self.auto_auth = AutoAuthPage( + self.browser, course_id=self.course_id, username=self.unique_id[0:10] + ).visit() + self.dashboard_page = DashboardPage(self.browser).visit() + + def test_change_lang(self): + # By default, should not be using the dummy language + self.assertFalse(self.dashboard_page.is_dummy_lang) + + # Change language to Dummy Esperanto + self.dashboard_page.change_language('eo') + self.assertTrue(self.dashboard_page.is_dummy_lang) + + def test_language_persists(self): + + # Change language to Dummy Esperanto + self.dashboard_page.change_language('eo') + + # Log out and log back in + LogoutPage(self.browser).visit() + self.auto_auth.visit() + + # Return to the dashboard and verify that we still see the dummy language + self.dashboard_page.visit() + self.assertTrue(self.dashboard_page.is_dummy_lang) diff --git a/common/test/acceptance/tests/test_lms.py b/common/test/acceptance/tests/test_lms.py index 13d82cff4a65..0419f7bc34d0 100644 --- a/common/test/acceptance/tests/test_lms.py +++ b/common/test/acceptance/tests/test_lms.py @@ -70,66 +70,6 @@ def test_register(self): self.assertIn(self.course_info['display_name'], course_names) -class LanguageTest(UniqueCourseTest): - """ - Tests that the change language functionality on the dashboard works - """ - - @property - def _changed_lang_promise(self): - def _check_func(): - text = self.dashboard_page.current_courses_text - return (len(text) > 0, text) - return Promise(_check_func, "language changed") - - def setUp(self): - """ - Initiailize dashboard page - """ - super(LanguageTest, self).setUp() - self.dashboard_page = DashboardPage(self.browser) - - self.test_new_lang = 'eo' - # This string is unicode for "ÇÜRRÉNT ÇØÜRSÉS", which should appear in our Dummy Esperanto page - # We store the string this way because Selenium seems to try and read in strings from - # the HTML in this format. Ideally we could just store the raw ÇÜRRÉNT ÇØÜRSÉS string here - self.current_courses_text = u'\xc7\xdcRR\xc9NT \xc7\xd6\xdcRS\xc9S' - - self.username = "test" - self.password = "testpass" - self.email = "test@example.com" - - def test_change_lang(self): - AutoAuthPage(self.browser, course_id=self.course_id).visit() - self.dashboard_page.visit() - # Change language to Dummy Esperanto - self.dashboard_page.change_language(self.test_new_lang) - - changed_text = fulfill(self._changed_lang_promise) - # We should see the dummy-language text on the page - self.assertIn(self.current_courses_text, changed_text) - - def test_language_persists(self): - auto_auth_page = AutoAuthPage(self.browser, username=self.username, password=self.password, email=self.email, course_id=self.course_id) - auto_auth_page.visit() - - self.dashboard_page.visit() - # Change language to Dummy Esperanto - self.dashboard_page.change_language(self.test_new_lang) - - # destroy session - self.browser._cookie_manager.delete() - - # log back in - auto_auth_page.visit() - - self.dashboard_page.visit() - - changed_text = fulfill(self._changed_lang_promise) - # We should see the dummy-language text on the page - self.assertIn(self.current_courses_text, changed_text) - - class HighLevelTabTest(UniqueCourseTest): """ Tests that verify each of the high-level tabs available within a course.