remove empty list
[fnpeditor.git] / src / wlxml / extensions / edumed / edumed.test.js
1 define(function(require) {
2     
3 'use strict';
4 /* globals describe, it */
5
6 var chai = require('libs/chai'),
7     wlxml = require('wlxml/wlxml');
8     //edumedExtension = require('./edumed.js');
9
10 var expect = chai.expect;
11
12
13 var getDocumentFromXML = function(xml, options) {
14     var doc = wlxml.WLXMLDocumentFromXML(xml, options || {});
15     //doc.registerExtension(edumedExtension);
16     return doc;
17 };
18
19
20 describe('Setting answer', function() {
21     it('sets answer (1)', function() {
22         /* jshint multistr:true */
23         var doc = getDocumentFromXML('\
24                 <div class="exercise.order">\
25                     <div class="list.orderable">\
26                         <div class="item.answer" answer="3">Element 3</div>\
27                         <div class="item.answer" answer="1">Element 1</div>\
28                         <div class="item.answer" answer="2">Element 2</div>\
29                     </div>\
30                 </div>');
31
32         doc.root.object.getItems()[2].setAnswer(1);
33
34         var items = doc.root.object.getItems();
35
36         expect(items[0].getAnswer()).to.equal(3);
37         expect(items[1].getAnswer()).to.equal(2);
38         expect(items[2].getAnswer()).to.equal(1);
39
40     });
41     it('sets answer (2)', function() {
42         /* jshint multistr:true */
43         var doc = getDocumentFromXML('\
44                 <div class="exercise.order">\
45                     <div class="list.orderable">\
46                         <div class="item.answer" answer="1">Element 1</div>\
47                         <div class="item.answer" answer="2">Element 2</div>\
48                         <div class="item.answer" answer="3">Element 3</div>\
49                     </div>\
50                 </div>');
51         doc.transaction(function() {
52             doc.root.object.getItems()[2].setAnswer(2);
53         }, {
54             error: function(e) { throw e;}
55         });
56         
57
58         var items = doc.root.object.getItems();
59
60         expect(items[0].getAnswer()).to.equal(1);
61         expect(items[1].getAnswer()).to.equal(3);
62         expect(items[2].getAnswer()).to.equal(2);
63
64     });
65 });
66
67
68
69
70 });