From 527c5464c739f9ebd5323a79eeadf5b942dc771d Mon Sep 17 00:00:00 2001 From: Chris Van Date: Tue, 10 Apr 2012 23:35:09 -0700 Subject: [PATCH] add language switcher drop-down to Marketplace (bug 740717) --- media/js/mkt/utils.js | 6 ++++++ .../templates/site/includes/languages.html | 13 ++++++++++++ mkt/site/tests/test_views.py | 21 +++++++++++++++++++ mkt/templates/mkt/base.html | 1 + 4 files changed, 41 insertions(+) create mode 100644 mkt/site/templates/site/includes/languages.html diff --git a/media/js/mkt/utils.js b/media/js/mkt/utils.js index a98d12ffe0..907d022de4 100644 --- a/media/js/mkt/utils.js +++ b/media/js/mkt/utils.js @@ -53,3 +53,9 @@ $('html').ajaxSend(function(event, xhr, ajaxSettings) { }).ajaxSuccess(function(event, xhr, ajaxSettings) { $(window).trigger('resize'); // Redraw what needs to be redrawn. }); + + +// If any field changes, submit the form. +$('form.go').change(function() { + this.submit(); +}); diff --git a/mkt/site/templates/site/includes/languages.html b/mkt/site/templates/site/includes/languages.html new file mode 100644 index 0000000000..7d38842b9f --- /dev/null +++ b/mkt/site/templates/site/includes/languages.html @@ -0,0 +1,13 @@ +
+ + + {% for key, value in request.GET.items() %} + + {% endfor %} + +
diff --git a/mkt/site/tests/test_views.py b/mkt/site/tests/test_views.py index 4c3c0662ce..af26227dc1 100644 --- a/mkt/site/tests/test_views.py +++ b/mkt/site/tests/test_views.py @@ -4,6 +4,8 @@ from django.conf import settings import mock from nose.tools import eq_ +from pyquery import PyQuery as pq +import waffle import amo import amo.tests @@ -42,3 +44,22 @@ class TestRobots(amo.tests.TestCase): def test_do_not_engage_robots(self): rs = self.client.get('/robots.txt') self.assertContains(rs, 'Disallow: /') + + +class TestFooter(amo.tests.TestCase): + + def test_language_selector(self): + waffle.models.Switch.objects.create(name='unleash-consumer', + active=True) + r = self.client.get(reverse('home')) + eq_(r.status_code, 200) + eq_(pq(r.content)('#lang-form option[selected]').attr('value'), + 'en-us') + + def test_language_selector_variables(self): + waffle.models.Switch.objects.create(name='unleash-consumer', + active=True) + r = self.client.get(reverse('home'), {'x': 'xxx', 'y': 'yyy'}) + doc = pq(r.content)('#lang-form') + eq_(doc('input[type=hidden][name=x]').attr('value'), 'xxx') + eq_(doc('input[type=hidden][name=y]').attr('value'), 'yyy') diff --git a/mkt/templates/mkt/base.html b/mkt/templates/mkt/base.html index 61c8e58355..d9cd92361f 100644 --- a/mkt/templates/mkt/base.html +++ b/mkt/templates/mkt/base.html @@ -69,6 +69,7 @@ {% else %} {{ _('Log in / Register') }} {% endif %} + {% include 'site/includes/languages.html' %} {% endblock %}