mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 06:53:15 +00:00
Add application tests
This commit is contained in:

committed by
Romain Neutron

parent
ac6c9970e2
commit
f886874f8d
@@ -1,5 +1,270 @@
|
||||
define(function(require) {
|
||||
it("should run", function () {
|
||||
expect(true).to.equal(true);
|
||||
define([
|
||||
'chai',
|
||||
'fixtures',
|
||||
'jquery',
|
||||
'app',
|
||||
'models/field',
|
||||
'apps/admin/fields/collections/fields',
|
||||
'apps/admin/fields/collections/dcFields',
|
||||
'apps/admin/fields/collections/vocabularies',
|
||||
'apps/admin/fields/views/listRow',
|
||||
'apps/admin/fields/views/list',
|
||||
'apps/admin/fields/views/alert',
|
||||
'apps/admin/fields/views/edit',
|
||||
'apps/admin/fields/views/fieldError',
|
||||
'apps/admin/fields/views/modal',
|
||||
'apps/admin/fields/views/save',
|
||||
'apps/admin/fields/views/dcField'
|
||||
], function(
|
||||
chai,
|
||||
fixtures,
|
||||
$,
|
||||
App,
|
||||
FieldModel,
|
||||
FieldCollection,
|
||||
DcFieldCollection,
|
||||
VocabularyCollection,
|
||||
SingleItemView,
|
||||
ListItemView,
|
||||
AlertView,
|
||||
EditView,
|
||||
FieldErrorView,
|
||||
ModalView,
|
||||
SaveView,
|
||||
DcFieldView
|
||||
) {
|
||||
var expect = chai.expect;
|
||||
var assert = chai.assert;
|
||||
var should = chai.should();
|
||||
|
||||
// load fixtures in dom
|
||||
fixtures.path = 'fixtures';
|
||||
$("body").append(fixtures.read('admin/fields/dom', 'admin/fields/templates'));
|
||||
var sbasId = 1;
|
||||
|
||||
App.initialize();
|
||||
|
||||
describe("Application", function() {
|
||||
describe("Initialization", function() {
|
||||
it("should create a global variable", function() {
|
||||
should.exist(AdminFieldApp);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Collections", function() {
|
||||
describe("DcField Collection", function() {
|
||||
beforeEach(function() {
|
||||
this.collection = new DcFieldCollection([]);
|
||||
});
|
||||
|
||||
it("should set collection url according to provided 'sbas-id'", function() {
|
||||
this.collection.url().should.equal("/admin/fields/dc-fields");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Vocabulary Collection", function() {
|
||||
beforeEach(function() {
|
||||
this.collection = new VocabularyCollection([]);
|
||||
});
|
||||
|
||||
it("should set collection url according to provided 'sbas-id'", function() {
|
||||
this.collection.url().should.equal("/admin/fields/vocabularies");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Field Collection", function() {
|
||||
beforeEach(function() {
|
||||
this.collection = new FieldCollection([
|
||||
{"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"},
|
||||
{"id": 2, "sbas-id": sbasId, "name": "Object", "tag": "XMP:Object"},
|
||||
], {
|
||||
"sbas_id": sbasId
|
||||
});
|
||||
});
|
||||
|
||||
describe("Initialization", function() {
|
||||
it("should throw an exception if 'sbas_id' is missing", function() {
|
||||
expect(function() {
|
||||
new FieldCollection([]);
|
||||
}).to.throw("You must set a sbas id");
|
||||
});
|
||||
|
||||
it("should set collection url according to provided 'sbas-id'", function() {
|
||||
this.collection.url().should.equal("/admin/fields/"+sbasId+"/fields");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Methods", function() {
|
||||
it("should retrieve categorie item if searching terms begins with 'cat'", function() {
|
||||
this.collection.search('Cat').length.should.equal(1);
|
||||
});
|
||||
|
||||
it("should retrieve previous and next index for given model", function() {
|
||||
expect(this.collection.previousIndex(this.collection.first())).to.be.null;
|
||||
this.collection.nextIndex(this.collection.first()).should.equal(1);
|
||||
this.collection.previousIndex(this.collection.last()).should.equal(0);
|
||||
expect(this.collection.nextIndex(this.collection.last())).to.be.null;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Views", function() {
|
||||
describe("Single Item Views", function() {
|
||||
beforeEach(function() {
|
||||
this.field = new FieldModel({"sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
|
||||
this.view = new SingleItemView({model: this.field});
|
||||
});
|
||||
|
||||
it("render() should return the view object", function() {
|
||||
this.view.render().should.equal(this.view);
|
||||
});
|
||||
|
||||
it("should render as a LI element", function() {
|
||||
this.view.render().el.nodeName.should.equal("LI");
|
||||
});
|
||||
|
||||
it("should render as a LI element with proper properties", function() {
|
||||
this.view.render().$el.find('.field-name').html().should.equal("Categorie");
|
||||
this.view.render().$el.find('.field-tag').html().should.equal("XMP:Categorie");
|
||||
});
|
||||
});
|
||||
|
||||
describe("List Item Views", function() {
|
||||
beforeEach(function() {
|
||||
this.collection = new FieldCollection([
|
||||
{"sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"},
|
||||
{"sbas-id": sbasId, "name": "Object", "tag": "XMP:Object"}
|
||||
], {
|
||||
"sbas_id": sbasId
|
||||
});
|
||||
|
||||
this.view = new ListItemView({
|
||||
collection: this.collection,
|
||||
el: AdminFieldApp.$leftBlock
|
||||
});
|
||||
});
|
||||
|
||||
it("render() should return the view object", function() {
|
||||
this.view.render().should.equal(this.view);
|
||||
});
|
||||
|
||||
it("should render as a DIV block", function() {
|
||||
this.view.render().el.nodeName.should.equal("DIV");
|
||||
});
|
||||
|
||||
it("should include list items for all models in collection", function() {
|
||||
this.view.render();
|
||||
this.view.$el.find("li").should.have.length(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Alert Views", function() {
|
||||
beforeEach(function() {
|
||||
this.view = new AlertView({alert: "info", message: "Hello world!"});
|
||||
});
|
||||
|
||||
it("render() should return the view object", function() {
|
||||
this.view.render().should.equal(this.view);
|
||||
});
|
||||
|
||||
it("should render as a DIV element", function() {
|
||||
this.view.render().el.nodeName.should.equal("DIV");
|
||||
});
|
||||
});
|
||||
|
||||
describe("DcField Views", function() {
|
||||
beforeEach(function() {
|
||||
this.collection = new DcFieldCollection([ {
|
||||
"label": "Contributor",
|
||||
"definition": "An entity responsible for making contributions to the resource.",
|
||||
"URI": "http://dublincore.org/documents/dces/#contributor"
|
||||
}, {
|
||||
"label": "Coverage",
|
||||
"definition": "The spatial or temporal topic of the resource, the spatial applicability of the resource,\n or the jurisdiction under which the resource\n is relevant.",
|
||||
"URI": "http://dublincore.org/documents/dces/#coverage"
|
||||
}
|
||||
]);
|
||||
|
||||
var model = new FieldModel({"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
|
||||
|
||||
this.view = new DcFieldView({
|
||||
"collection": this.collection,
|
||||
"field": model
|
||||
});
|
||||
});
|
||||
|
||||
it("render() should return the view object", function() {
|
||||
this.view.render().should.equal(this.view);
|
||||
});
|
||||
|
||||
it("should render as a DIV element", function() {
|
||||
this.view.render().el.nodeName.should.equal("DIV");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Edit Views", function() {
|
||||
beforeEach(function() {
|
||||
var model = new FieldModel({"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
|
||||
|
||||
this.view = new EditView({"model": model}).render();
|
||||
});
|
||||
|
||||
it("render() should return the view object", function() {
|
||||
this.view.render().should.equal(this.view);
|
||||
});
|
||||
|
||||
it("should render as a DIV element", function() {
|
||||
this.view.render().el.nodeName.should.equal("DIV");
|
||||
});
|
||||
});
|
||||
|
||||
describe("FieldError Views", function() {
|
||||
beforeEach(function() {
|
||||
this.view = new FieldErrorView();
|
||||
});
|
||||
|
||||
it("render() should return the view object", function() {
|
||||
this.view.render().should.equal(this.view);
|
||||
});
|
||||
|
||||
it("should render as a DIV element", function() {
|
||||
this.view.render().el.nodeName.should.equal("DIV");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Modal Views", function() {
|
||||
beforeEach(function() {
|
||||
var model = new FieldModel({"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
|
||||
|
||||
this.view = new ModalView({
|
||||
model: model,
|
||||
message: "hellow world!"
|
||||
});
|
||||
});
|
||||
|
||||
it("render() should return the view object", function() {
|
||||
this.view.render().should.equal(this.view);
|
||||
});
|
||||
|
||||
it("should render as a DIV element", function() {
|
||||
this.view.render().el.nodeName.should.equal("DIV");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Save Views", function() {
|
||||
beforeEach(function() {
|
||||
this.view = new SaveView();
|
||||
});
|
||||
|
||||
it("render() should return the view object", function() {
|
||||
this.view.render().should.equal(this.view);
|
||||
});
|
||||
|
||||
it("should render as a DIV element", function() {
|
||||
this.view.render().el.nodeName.should.equal("DIV");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
115
www/scripts/tests/specs/models.js
Normal file
115
www/scripts/tests/specs/models.js
Normal file
@@ -0,0 +1,115 @@
|
||||
define([
|
||||
'chai',
|
||||
'models/field',
|
||||
'models/dcField',
|
||||
'models/vocabulary'
|
||||
], function(chai, Field, DcField, Vocabulary) {
|
||||
var expect = chai.expect;
|
||||
var assert = chai.assert;
|
||||
var should = chai.should();
|
||||
describe("Models", function(){
|
||||
describe("Field Model", function(){
|
||||
describe("Initialization", function() {
|
||||
var sbasId = 1;
|
||||
|
||||
beforeEach(function() {
|
||||
this.field = new Field({
|
||||
"sbas-id" : sbasId
|
||||
});
|
||||
});
|
||||
|
||||
it("should throw an exception if 'sbas-id' is missing", function() {
|
||||
expect(function() {
|
||||
new Field();
|
||||
}).to.throw("You must set a sbas id");
|
||||
});
|
||||
|
||||
it("should set model url according to provided 'sbas-id'", function() {
|
||||
this.field.urlRoot().should.equal("/admin/fields/"+sbasId+"/fields");
|
||||
});
|
||||
|
||||
it("should default business property to 'false'", function() {
|
||||
this.field.get('business').should.be.false;
|
||||
});
|
||||
|
||||
it("should default type property to 'string'", function() {
|
||||
this.field.get('type').should.equal("string");
|
||||
});
|
||||
|
||||
it("should default thumbtitle property to '0'", function() {
|
||||
this.field.get('thumbtitle').should.equal("0");
|
||||
});
|
||||
|
||||
it("should default tbranch property to 'empty'", function() {
|
||||
this.field.get('tbranch').should.equal("");
|
||||
});
|
||||
|
||||
it("should default separator property to 'empty'", function() {
|
||||
this.field.get('separator').should.equal("");
|
||||
});
|
||||
|
||||
it("should default required property to 'false'", function() {
|
||||
this.field.get('required').should.be.false;
|
||||
});
|
||||
|
||||
it("should default readonly property to 'false'", function() {
|
||||
this.field.get('readonly').should.be.false;
|
||||
});
|
||||
|
||||
it("should default multi property to 'false'", function() {
|
||||
this.field.get('multi').should.be.false;
|
||||
});
|
||||
|
||||
it("should default vocabulary-restricted property to 'false'", function() {
|
||||
this.field.get('vocabulary-restricted').should.be.false;
|
||||
});
|
||||
|
||||
it("should default vocabulary-restricted property to 'false'", function() {
|
||||
this.field.get('vocabulary-restricted').should.be.false;
|
||||
});
|
||||
|
||||
it("should default report property to 'true'", function() {
|
||||
this.field.get('report').should.be.true;
|
||||
});
|
||||
|
||||
it("should default indexable property to 'true'", function() {
|
||||
this.field.get('indexable').should.be.true;
|
||||
});
|
||||
|
||||
it("should default dces-element property to 'null'", function() {
|
||||
expect(this.field.get('dces-element')).to.be.null;
|
||||
});
|
||||
|
||||
it("should default vocabulary-type property to 'null'", function() {
|
||||
expect(this.field.get('vocabulary-type')).to.be.null;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DcField Model", function(){
|
||||
describe("Initialization", function() {
|
||||
beforeEach(function() {
|
||||
this.dcField = new DcField();
|
||||
});
|
||||
|
||||
it("should set proper model url", function() {
|
||||
this.dcField.urlRoot().should.equal("/admin/fields/dc-fields");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DcField Model", function(){
|
||||
describe("Initialization", function() {
|
||||
beforeEach(function() {
|
||||
this.vocabulary = new Vocabulary();
|
||||
});
|
||||
|
||||
it("should set proper model url", function() {
|
||||
this.vocabulary.urlRoot().should.equal("/admin/fields/vocabularies");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user