Add unit tests

This commit is contained in:
Nicolas Le Goff
2013-05-24 12:22:37 +02:00
committed by Romain Neutron
parent f146d6725a
commit 848413dead
3 changed files with 56 additions and 7 deletions

View File

@@ -209,7 +209,6 @@ class ControllerFieldsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
foreach($fieldObjects as $field) {
$field->delete();
}
}
public function testCreateField()

View File

@@ -4,6 +4,10 @@ require.config({
specs: "tests/specs",
chai: "../assets/chai/chai",
fixtures: "../assets/js-fixtures/fixtures",
sinon: "../assets/sinon/lib/sinon",
sinonSpy: "../assets/sinon/lib/sinon/spy",
sinonMock: "../assets/sinon/lib/sinon/mock",
sinonStub: "../assets/sinon/lib/sinon/stub",
app: "apps/admin/fields/app",
jquery: "../include/jslibs/jquery-1.7.1",
jqueryui: "../include/jslibs/jquery-ui-1.8.17/js/jquery-ui-1.8.17.custom.min",
@@ -14,12 +18,17 @@ require.config({
bootstrap: "../skins/html5/bootstrap/js/bootstrap.min"
},
shim: {
twig: {
exports: "Twig"
},
bootstrap : ["jquery"],
jqueryui: {
deps: [ "jquery" ]
deps: ["jquery"]
},
sinonSpy: {
deps: ["sinon"],
exports: "sinon"
},
sinonMock: {
deps: ["sinon", "sinonSpy", "sinonStub"],
exports: "sinon"
}
}
});

View File

@@ -175,7 +175,7 @@ define([
describe("DcField Views", function() {
beforeEach(function() {
this.collection = new DcFieldCollection([ {
this.collection = new DcFieldCollection([{
"label": "Contributor",
"definition": "An entity responsible for making contributions to the resource.",
"URI": "http://dublincore.org/documents/dces/#contributor"
@@ -207,7 +207,7 @@ define([
beforeEach(function() {
var model = new FieldModel({"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
this.view = new EditView({"model": model}).render();
this.view = new EditView({"model": model});
});
it("render() should return the view object", function() {
@@ -266,5 +266,46 @@ define([
});
});
});
describe("Edge cases", function() {
beforeEach(function() {
AdminFieldApp.fieldsCollection.add({"sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
AdminFieldApp.dcFieldsCollection.add({
"label": "Contributor",
"definition": "An entity responsible for making contributions to the resource.",
"URI": "http://dublincore.org/documents/dces/#contributor"
});
AdminFieldApp.saveView = new SaveView();
AdminFieldApp.fieldErrorView = new FieldErrorView();
AdminFieldApp.fieldListView = new ListItemView({
collection: AdminFieldApp.fieldsCollection,
el: AdminFieldApp.$leftBlock
});
// render views
AdminFieldApp.saveView.render();
AdminFieldApp.fieldListView.render();
});
it("should update edit view when clicking on single element", function() {
AdminFieldApp.fieldListView.itemViews[0].clickAction();
should.exist(AdminFieldApp.fieldEditView);
assert.equal(AdminFieldApp.fieldEditView.model, AdminFieldApp.fieldListView.collection.first(), 'model is updated');
});
it("should reorder collection on drop action", function() {
var ui = {item: {index: function() {return 2;}}};
AdminFieldApp.fieldListView.itemViews[0].dropAction({},ui);
assert.equal(AdminFieldApp.fieldListView.collection.last().get('sorter'), 2, 'model is updated');
});
it("should update collection when model change", function() {
AdminFieldApp.fieldListView.itemViews[0].clickAction();
AdminFieldApp.fieldEditView.model.set({
"name": "new name"
});
assert.equal(AdminFieldApp.fieldListView.collection.first().get('name'), "new name", 'model is updated');
});
});
});
});