From 9340afd1963f049b69cc360d22a66beb830c6471 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 26 Sep 2019 00:28:44 -0400 Subject: [PATCH] Initial commit to support QUnit tests Signed-off-by: Roberto Rosario --- .../js/test/unit/partial_navigation.js | 31 +++++++++++++++++++ .../templates/appearance/base_plain.html | 1 + mayan/apps/common/dependencies.py | 7 ++++- mayan/apps/common/templates/common/qunit.html | 22 +++++++++++++ mayan/apps/common/urls.py | 6 +++- mayan/apps/common/views.py | 5 +++ 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 mayan/apps/appearance/static/appearance/js/test/unit/partial_navigation.js create mode 100644 mayan/apps/common/templates/common/qunit.html diff --git a/mayan/apps/appearance/static/appearance/js/test/unit/partial_navigation.js b/mayan/apps/appearance/static/appearance/js/test/unit/partial_navigation.js new file mode 100644 index 0000000000..ba13762bb0 --- /dev/null +++ b/mayan/apps/appearance/static/appearance/js/test/unit/partial_navigation.js @@ -0,0 +1,31 @@ +'use strict'; + +QUnit.test('partialNavigation.filterLocation', function (assert) { + var testPartialNavigation = new PartialNavigation({ + initialURL: '/testInitialURL', + }); + + /* + * For an empty newLocation we expect the fragment of the URL minus the + * query + */ + var expected = new URI(new URI(location).fragment()).path().toString(); + assert.strictEqual( + testPartialNavigation.filterLocation(''), expected, 'newLocation === ""'); + + /* + * For an empty root value we expect initialURL passed to the + * partialNavigation instance when initialized. + */ + assert.strictEqual( + testPartialNavigation.filterLocation('/'), testPartialNavigation.initialURL, 'newLocation === "/"' + ); + + /* + * For an empty root value we expect initialURL passed to the + * partialNavigation instance when initialized. + */ + assert.strictEqual( + testPartialNavigation.filterLocation('random'), 'random', 'newLocation === "random"' + ); +}); diff --git a/mayan/apps/appearance/templates/appearance/base_plain.html b/mayan/apps/appearance/templates/appearance/base_plain.html index 7a5b8e38a6..0573e5d1c9 100644 --- a/mayan/apps/appearance/templates/appearance/base_plain.html +++ b/mayan/apps/appearance/templates/appearance/base_plain.html @@ -38,6 +38,7 @@ + {% block javascript %}{% endblock %} {% endspaceless %} diff --git a/mayan/apps/common/dependencies.py b/mayan/apps/common/dependencies.py index 97bfb1b0d4..88a8d6c986 100644 --- a/mayan/apps/common/dependencies.py +++ b/mayan/apps/common/dependencies.py @@ -4,7 +4,12 @@ from django.utils.translation import ugettext_lazy as _ from mayan.apps.dependencies.classes import ( environment_build, environment_development, environment_testing, - PythonDependency + JavaScriptDependency, PythonDependency +) + +JavaScriptDependency( + environment=environment_testing, label=_('QUnit'), module=__name__, + name='qunit', version_string='=2.9.2' ) PythonDependency( diff --git a/mayan/apps/common/templates/common/qunit.html b/mayan/apps/common/templates/common/qunit.html new file mode 100644 index 0000000000..a427af1bdb --- /dev/null +++ b/mayan/apps/common/templates/common/qunit.html @@ -0,0 +1,22 @@ +{% extends 'appearance/base.html' %} + +{% load i18n %} +{% load static %} + +{% block base_title %}{% trans 'Qunit' %}{% endblock %} + +{% block project_name %}{% endblock %} + +{% block stylesheets %} + +{% endblock %} + +{% block content %} +
+
+{% endblock %} + +{% block javascript %} + + +{% endblock %} diff --git a/mayan/apps/common/urls.py b/mayan/apps/common/urls.py index 13fd7e3fac..6cf337d29c 100644 --- a/mayan/apps/common/urls.py +++ b/mayan/apps/common/urls.py @@ -10,7 +10,8 @@ from .views import ( AboutView, CurrentUserLocaleProfileDetailsView, CurrentUserLocaleProfileEditView, FaviconRedirectView, HomeView, LicenseView, ObjectErrorLogEntryListClearView, ObjectErrorLogEntryListView, - RootView, SetupListView, ToolsListView, multi_object_action_view + RootView, SetupListView, ToolsListView, QUnitView, + multi_object_action_view ) urlpatterns = [ @@ -43,6 +44,9 @@ urlpatterns = [ view=ObjectErrorLogEntryListClearView.as_view(), name='object_error_list_clear' ), + url( + regex=r'^qunit/', view=QUnitView.as_view(), name='qunit' + ) ] urlpatterns += [ diff --git a/mayan/apps/common/views.py b/mayan/apps/common/views.py index 426109fe1b..1d9527014a 100644 --- a/mayan/apps/common/views.py +++ b/mayan/apps/common/views.py @@ -276,3 +276,8 @@ def multi_object_action_view(request): action, urlencode({'id_list': id_list, 'next': next}) ) ) + + +class QUnitView(SimpleView): + extra_context = {'title': _('QUnit tests')} + template_name = 'common/qunit.html'