mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-14 21:43:18 +00:00
Add tests
This commit is contained in:
@@ -41,6 +41,8 @@ class JsFixtures extends Command
|
||||
$this->writeResponse($output, 'GET', '/login/', '/home/login/index.html');
|
||||
$this->writeResponse($output, 'GET', '/admin/fields/'.$sbasId , '/admin/fields/index.html', true);
|
||||
$this->writeResponse($output, 'GET', '/admin/task-manager/tasks', '/admin/task-manager/index.html', true);
|
||||
$this->writeResponse($output, 'GET', '/admin/', '/admin/main/left-panel.html', true);
|
||||
$this->writeResponse($output, 'GET', '/admin/databoxes/', '/admin/main/right-panel.html', true);
|
||||
|
||||
$this->copy($output, [
|
||||
['source' => 'login/common/templates.html.twig', 'target' => 'home/login/templates.html'],
|
||||
|
@@ -56,7 +56,7 @@
|
||||
resize();
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript" src="{{ path('minifier', { 'f' : '/assets/requirejs/require.js, /scripts/apps/admin/require.config.js /scripts/apps/admin/main/main.js' }) }}"></script>
|
||||
<script type="text/javascript" src="{{ path('minifier', { 'f' : '/assets/requirejs/require.js,/scripts/apps/admin/require.config.js,/scripts/apps/admin/main/main.js' }) }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
@@ -16,11 +16,16 @@ define([
|
||||
], function ($, _, Backbone, SubscriberManager) {
|
||||
var LeftPanelView = Backbone.View.extend({
|
||||
initialize: function (options) {
|
||||
if (false === "eventManager" in options) {
|
||||
throw "You must set en event manager";
|
||||
options = options || {};
|
||||
if (false === ("eventManager" in options)) {
|
||||
throw "You must set an event manager";
|
||||
}
|
||||
if (false === ("treeUrl" in options)) {
|
||||
throw "You must set the tree url";
|
||||
}
|
||||
this.delegateEvents(this.events);
|
||||
this.eventManager = options.eventManager;
|
||||
this.treeUrl = options.treeUrl;
|
||||
this.$treeview = $("#FNDR", this.$el);
|
||||
|
||||
var $this = this;
|
||||
@@ -39,7 +44,6 @@ define([
|
||||
"click a[target=right]": "clickAction"
|
||||
},
|
||||
activeTree: function() {
|
||||
// tree view jquery module is not loaded as a module
|
||||
this.$treeview.treeview({
|
||||
collapsed: true,
|
||||
animated: "medium"
|
||||
@@ -89,7 +93,6 @@ define([
|
||||
});
|
||||
|
||||
if ("undefined" !== typeof link.data("ws-topic")) {
|
||||
console.log(link.data("ws-topic"));
|
||||
SubscriberManager.register(link.data("ws-topic"));
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,8 @@ define([
|
||||
], function ($, _, Backbone) {
|
||||
var RightPanelView = Backbone.View.extend({
|
||||
initialize: function (options) {
|
||||
if (false === "eventManager" in options) {
|
||||
options = options || {};
|
||||
if (false === ("eventManager" in options)) {
|
||||
throw "You must set en event manager";
|
||||
}
|
||||
this.delegateEvents(this.events);
|
||||
|
@@ -6,17 +6,48 @@ require.config({
|
||||
fixtures: "../../tmp-assets/js-fixtures/fixtures",
|
||||
jquery: "../assets/jquery/jquery",
|
||||
jqueryui: "../assets/jquery.ui/jquery-ui",
|
||||
underscore: "../assets/underscore-amd/underscore",
|
||||
backbone: "../assets/backbone-amd/backbone",
|
||||
i18n: "../assets/i18next/i18next.amd-1.6.3",
|
||||
bootstrap: "../assets/bootstrap/js/bootstrap.min",
|
||||
sinonchai: "../../tmp-assets/sinon-chai/lib/sinon-chai",
|
||||
squire: "../../tmp-assets/squire/src/Squire"
|
||||
squire: "../../tmp-assets/squire/src/Squire",
|
||||
"jquery.ui": "../assets/jquery.ui/jquery-ui",
|
||||
underscore: "../assets/underscore-amd/underscore",
|
||||
"jquery.ui.widget": "../assets/jquery-file-upload/jquery.ui.widget",
|
||||
"jquery.cookie": "../assets/jquery.cookie/jquery.cookie",
|
||||
"jquery.treeview": "../assets/jquery.treeview/jquery.treeview",
|
||||
"jquery.tooltip": "../assets/jquery.tooltip/jquery.tooltip",
|
||||
"blueimp.loadimage" : "../assets/blueimp-load-image/load-image",
|
||||
"jfu.iframe-transport": "../assets/jquery-file-upload/jquery.iframe-transport",
|
||||
"jfu.fileupload": "../assets/jquery-file-upload/jquery.fileupload",
|
||||
},
|
||||
shim: {
|
||||
bootstrap: ["jquery"],
|
||||
jqueryui: {
|
||||
deps: ["jquery"]
|
||||
},
|
||||
"jquery.treeview": {
|
||||
deps: ['jquery', 'jquery.cookie'],
|
||||
exports: '$.fn.treeview'
|
||||
},
|
||||
bootstrap:{
|
||||
deps: ['jquery']
|
||||
},
|
||||
"jquery.cookie": {
|
||||
deps: ["jquery"],
|
||||
exports: '$.fn.cookie'
|
||||
},
|
||||
"jquery.tooltip": {
|
||||
deps: ["jquery"],
|
||||
exports: '$.fn.tooltip'
|
||||
},
|
||||
"jquery.ui": {
|
||||
deps: ["jquery"]
|
||||
},
|
||||
"jquery.ui.widget": {
|
||||
deps: ["jquery"]
|
||||
},
|
||||
"jfu.fileupload": {
|
||||
deps: ["jquery.ui.widget"]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
105
www/scripts/tests/specs/admin/main.js
Normal file
105
www/scripts/tests/specs/admin/main.js
Normal file
@@ -0,0 +1,105 @@
|
||||
define([
|
||||
'chai',
|
||||
'fixtures',
|
||||
'jquery',
|
||||
'squire',
|
||||
'apps/admin/main/app',
|
||||
'apps/admin/main/views/leftPanel',
|
||||
'apps/admin/main/views/rightPanel'
|
||||
], function (chai, fixtures, $, Squire, App, LeftPanel, RightPanel) {
|
||||
var expect = chai.expect;
|
||||
var assert = chai.assert;
|
||||
var should = chai.should();
|
||||
|
||||
fixtures.path = 'fixtures';
|
||||
$("body").append(fixtures.read('admin/main/left-panel.html'));
|
||||
$("right-view").append(fixtures.read('admin/main/right-panel.html'));
|
||||
|
||||
App.create();
|
||||
|
||||
describe("Admin main", function () {
|
||||
describe("Initialization", function () {
|
||||
it("should create a global variable", function () {
|
||||
should.exist(AdminApp);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Views", function () {
|
||||
describe("leftView", function () {
|
||||
it("should throw an exception if 'event manager' is missing", function () {
|
||||
expect(function () {
|
||||
new LeftPanel();
|
||||
}).to.throw("You must set an event manager");
|
||||
|
||||
expect(function () {
|
||||
new LeftPanel({eventManager: null});
|
||||
}).to.throw("You must set the tree url");
|
||||
});
|
||||
|
||||
it("should make ajax request if we reload", function () {
|
||||
var xhr = sinon.useFakeXMLHttpRequest();
|
||||
var requests = [];
|
||||
xhr.onCreate = function (req) { requests.push(req); };
|
||||
|
||||
var leftP = new LeftPanel({eventManager : AdminApp.eventManager, treeUrl: "/admin/tree/"});
|
||||
leftP.reloadTree();
|
||||
|
||||
assert.equal(requests.length, 1);
|
||||
assert.equal(requests[0].url, "/admin/tree/");
|
||||
|
||||
xhr.restore();
|
||||
});
|
||||
|
||||
it("should make ajax request if we click link", function () {
|
||||
var xhr = sinon.useFakeXMLHttpRequest();
|
||||
var requests = [];
|
||||
xhr.onCreate = function (req) { requests.push(req); };
|
||||
|
||||
var leftP = new LeftPanel({eventManager : AdminApp.eventManager, el:$(".left-view"), treeUrl: "toto"});
|
||||
leftP.$('a[target=right]:first').trigger("click");
|
||||
assert.equal(requests.length, 1);
|
||||
xhr.restore();
|
||||
});
|
||||
|
||||
it("triggers right view", function () {
|
||||
var trigger = false;
|
||||
AdminApp.eventManager.on("panel:right:complete", function() {
|
||||
trigger = true;
|
||||
});
|
||||
var leftP = new LeftPanel({eventManager : AdminApp.eventManager, el:$(".left-view"), treeUrl: "toto"});
|
||||
var rightP = new RightPanel({eventManager : AdminApp.eventManager, el:$(".right-view")});
|
||||
var server = sinon.fakeServer.create();
|
||||
leftP.activeTree();
|
||||
leftP.$('a[target=right]:first').trigger("click");
|
||||
server.requests[0].respond(
|
||||
200,
|
||||
{ "Content-Type": "application/json" },
|
||||
''
|
||||
);
|
||||
|
||||
assert.ok(trigger);
|
||||
server.restore();
|
||||
});
|
||||
});
|
||||
|
||||
describe("rightView", function () {
|
||||
it("should throw an exception if 'event manager' is missing", function () {
|
||||
expect(function () {
|
||||
new RightPanel();
|
||||
}).to.throw("You must set en event manager");
|
||||
});
|
||||
|
||||
it("should make ajax request if we click link", function () {
|
||||
var xhr = sinon.useFakeXMLHttpRequest();
|
||||
var requests = [];
|
||||
xhr.onCreate = function (req) { requests.push(req); };
|
||||
|
||||
var rightP = new RightPanel({eventManager : AdminApp.eventManager, el:$(".right-view")});
|
||||
rightP.$('a:not(.no-ajax)').trigger("click");
|
||||
assert.equal(requests.length, 1);
|
||||
xhr.restore();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user