Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 4DB80E00AAF; Mon, 17 Aug 2015 09:48:02 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low * trust * [209.85.212.178 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id E57C6E0097F for ; Mon, 17 Aug 2015 09:47:56 -0700 (PDT) Received: by wijp15 with SMTP id p15so79750321wij.0 for ; Mon, 17 Aug 2015 09:47:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=azAhcbBNoF9yqxdVpVgP5C3yInwaw7pXMtDE25xds5o=; b=hMwn7vcG5RWQY1IRfFrdtHp9hnmTSvz30NYh1g97EvkmoQ2WXw+mKnAng2nnbGwfFV fg3ePVtuBeOfASmkliVmJVCBsioRSWQB6KxWI8M71bkOBLNdGJyfKFICXb46PesUj2pe k6nQ1XPMAADckwogBYQnXwS+i17AR2+H/p8KMg7RpgQmwWAW9CLXTzbEvl5p8JfQOjqn NQGxO3HlO8uY1+UpkC4SPo6cZlmdYfTnNK9sj0oH7f7k/QiaLF2YAd+9RVV8WYM92uSR MfPwQfmAh7ohrqybaLWNKf9rsNutRfuAUp/YrdSHtXoFJqCBU8thDysxM/Zv5zHjT6S+ tMtw== X-Gm-Message-State: ALoCoQm1Q0GCbouBgfVq5WvHIgzoXi+ctTAiL5tfUxlhn0IVK6ePbFeXxVt2AuINPPxwvZvWICAz X-Received: by 10.180.205.230 with SMTP id lj6mr36434386wic.82.1439830075830; Mon, 17 Aug 2015 09:47:55 -0700 (PDT) Received: from dorado.Home ([90.200.212.221]) by smtp.gmail.com with ESMTPSA id i6sm22612610wje.33.2015.08.17.09.47.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Aug 2015 09:47:55 -0700 (PDT) From: Michael Wood To: toaster@yoctoproject.org Date: Mon, 17 Aug 2015 17:47:47 +0100 Message-Id: <1439830067-7147-1-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.1.4 Subject: [review-request][PATCH] toastergui: Add frontend javascript unit tests X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Aug 2015 16:48:02 -0000 Use Jquery's Qunit tests to create some unit tests for javascript components used in toaster. Signed-off-by: Michael Wood --- .../lib/toaster/toastergui/static/js/tests/test.js | 175 +++++++++++++++++++++ .../toastergui/templates/js-unit-tests.html | 39 +++++ bitbake/lib/toaster/toastergui/urls.py | 3 + bitbake/lib/toaster/toastergui/views.py | 16 ++ 4 files changed, 233 insertions(+) create mode 100644 bitbake/lib/toaster/toastergui/static/js/tests/test.js create mode 100644 bitbake/lib/toaster/toastergui/templates/js-unit-tests.html diff --git a/bitbake/lib/toaster/toastergui/static/js/tests/test.js b/bitbake/lib/toaster/toastergui/static/js/tests/test.js new file mode 100644 index 0000000..d610113 --- /dev/null +++ b/bitbake/lib/toaster/toastergui/static/js/tests/test.js @@ -0,0 +1,175 @@ +"use strict"; +/* Unit tests for Toaster's JS */ + +/* libtoaster tests */ + +QUnit.test("Layer alert notification", function(assert) { + var layer = { + "layerdetailurl":"/toastergui/project/1/layer/22", + "vcs_url":"git://example.com/example.git", + "detail":"[ git://example.com/example.git | master ]", + "vcs_reference":"master", + "id": 22, + "name":"meta-example" + }; + + var correctResponse = "You have added 3 layers to your project: meta-example and its dependencies meta-example-two, meta-example-three"; + + var layerDepsList = [ + { + "layerdetailurl":"/toastergui/project/1/layer/9", + "vcs_url":"git://example.com/example.git", + "detail":"[ git://example.com/example.git | master ]", + "vcs_reference":"master", + "id": 9, + "name":"meta-example-two" + }, + { + "layerdetailurl":"/toastergui/project/1/layer/9", + "vcs_url":"git://example.com/example.git", + "detail":"[ git://example.com/example.git | master ]", + "vcs_reference":"master", + "id": 10, + "name":"meta-example-three" + }, + ]; + + var msg = libtoaster.makeLayerAddRmAlertMsg(layer, layerDepsList, true); + var test = $("
"); + + test.html(msg); + + assert.equal(test.children("strong").text(), "3"); + assert.equal(test.children("a").length, 3); +}); + +QUnit.test("Project info", function(assert){ + var done = assert.async(); + libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, function(prjInfo){ + assert.ok(prjInfo.machine.name); + assert.ok(prjInfo.releases.length > 0); + assert.ok(prjInfo.layers.length > 0); + assert.ok(prjInfo.freqtargets); + assert.ok(prjInfo.release); + done(); + }); +}); + +QUnit.test("Show notification", function(assert){ + var msg = "Testing"; + var element = $("#change-notification-msg"); + + libtoaster.showChangeNotification(msg); + + assert.equal(element.text(), msg); + assert.ok(element.is(":visible")); + + $("#change-notification").hide(); +}); + +var layer = { + "id": 91, + "name": "meta-crystalforest", + "layerdetailurl": "/toastergui/project/4/layer/91" +}; + +QUnit.test("Add layer", function(assert){ + var done = assert.async(); + + /* Wait for the modal to be added to the dom */ + var checkModal = setInterval(function(){ + if ($("#dependencies-modal").length > 0) { + $("#dependencies-modal .btn-primary").click(); + clearInterval(checkModal); + } + }, 200); + + libtoaster.addRmLayer(layer, true, function(deps){ + assert.equal(deps.length, 1); + done(); + }); + +}); + +QUnit.test("Rm layer", function(assert){ + var done = assert.async(); + + libtoaster.addRmLayer(layer, false, function(deps){ + assert.equal(deps.length, 0); + done(); + }); + +}); + +QUnit.test("Parse url params", function(assert){ + var params = libtoaster.parseUrlParams(); + assert.ok(params); +}); + +QUnit.test("Dump url params", function(assert){ + var params = libtoaster.dumpsUrlParams(); + assert.ok(params); +}); + +QUnit.test("Make typeaheads", function(assert){ + var layersT = $("#layers"); + var machinesT = $("#machines"); + var projectsT = $("#projects"); + var recipesT = $("#recipes"); + + libtoaster.makeTypeahead(layersT, + libtoaster.ctx.layersTypeAheadUrl, {}, function(){}); + + libtoaster.makeTypeahead(machinesT, + libtoaster.ctx.machinesTypeAheadUrl, {}, function(){}); + + libtoaster.makeTypeahead(projectsT, + libtoaster.ctx.projectsTypeAheadUrl, {}, function(){}); + + libtoaster.makeTypeahead(recipesT, + libtoaster.ctx.recipesTypeAheadUrl, {}, function(){}); + + assert.ok(recipesT.data('typeahead')); + assert.ok(layersT.data('typeahead')); + assert.ok(projectsT.data('typeahead')); + assert.ok(recipesT.data('typeahead')); +}); + + + +/* Page init functions */ + +QUnit.test("Import layer page init", function(assert){ + assert.throws(importLayerPageInit()); +}); + +QUnit.test("Project page init", function(assert){ + assert.throws(projectPageInit()); +}); + +QUnit.test("Layer details page init", function(assert){ + assert.throws(layerDetailsPageInit()); +}); + +QUnit.test("Layer btns init", function(assert){ + assert.throws(layerBtnsInit({ projectLayers : [] })); +}); + +QUnit.test("Table init", function(assert){ + assert.throws(tableInit({ url : tableUrl })); +}); + +$(document).ajaxError(function(event, jqxhr, settings, errMsg){ + if (errMsg === 'abort') + return; + + QUnit.test("Ajax error", function(assert){ + assert.notOk(jqxhr.responseText); + }); +}); + + + + + + diff --git a/bitbake/lib/toaster/toastergui/templates/js-unit-tests.html b/bitbake/lib/toaster/toastergui/templates/js-unit-tests.html new file mode 100644 index 0000000..5b8fd84 --- /dev/null +++ b/bitbake/lib/toaster/toastergui/templates/js-unit-tests.html @@ -0,0 +1,39 @@ +{% extends "base.html" %} +{% load projecttags %} +{% load humanize %} +{% load static %} +{% block pagecontent %} + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + +{% endblock %} + + diff --git a/bitbake/lib/toaster/toastergui/urls.py b/bitbake/lib/toaster/toastergui/urls.py index f74090b..46e5761 100644 --- a/bitbake/lib/toaster/toastergui/urls.py +++ b/bitbake/lib/toaster/toastergui/urls.py @@ -145,6 +145,9 @@ urlpatterns = patterns('toastergui.views', url(r'^xhr_importlayer/$', 'xhr_importlayer', name='xhr_importlayer'), url(r'^xhr_updatelayer/$', 'xhr_updatelayer', name='xhr_updatelayer'), + # JS Unit tests + url(r'^js-unit-tests/$', 'jsunittests', name='js-unit-tests'), + # default redirection url(r'^$', RedirectView.as_view( url= 'landing')), ) diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 889b6c6..e39baad 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py @@ -27,6 +27,7 @@ from django.shortcuts import render, redirect from orm.models import Build, Target, Task, Layer, Layer_Version, Recipe, LogMessage, Variable from orm.models import Task_Dependency, Recipe_Dependency, Package, Package_File, Package_Dependency from orm.models import Target_Installed_Package, Target_File, Target_Image_File, BuildArtifact +from orm.models import BitbakeVersion from bldcontrol import bbcontroller from django.views.decorators.cache import cache_control from django.core.urlresolvers import reverse @@ -2255,6 +2256,21 @@ if True: return context + def jsunittests(request): + """ Provides a page for the js unit tests """ + bbv = BitbakeVersion.objects.filter(branch="master").first() + release = Release.objects.filter(bitbake_version=bbv).first() + + name = "_js_unit_test_prj_" + + # If there is an existing project by this name delete it. We don't want + # Lots of duplicates cluttering up the projects. + Project.objects.filter(name=name).delete() + + new_project = Project.objects.create_project(name=name, release=release) + + context = { 'project' : new_project } + return render(request, "js-unit-tests.html", context) from django.views.decorators.csrf import csrf_exempt @csrf_exempt -- 2.1.4