Skip to content

Commit

Permalink
Test that we have proper singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Mar 9, 2011
1 parent 554499f commit 48484f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions test/rdfa.js
Expand Up @@ -24,6 +24,28 @@ exports['test inheriting subject'] = function(test) {
test.done();
};

exports['test subject singletons'] = function(test) {
var html = jQuery('<div about="http://dbpedia.org/resource/Albert_Einstein"><span property="foaf:name">Albert Einstein</span><span property="dbp:dateOfBirth" datatype="xsd:date">1879-03-14</span><div rel="dbp:birthPlace" resource="http://dbpedia.org/resource/Germany" /><span about="http://dbpedia.org/resource/Germany" property="dbp:conventionalLongName">Federal Republic of Germany</span></div>');

var backboneEntities = VIE.RDFaEntities.getInstances(html);

test.equal(backboneEntities[1].get('foaf:name'), 'Albert Einstein');

var individualInstance = VIE.EntityManager.getBySubject('http://dbpedia.org/resource/Albert_Einstein');
test.equal(individualInstance.get('foaf:name'), 'Albert Einstein');

individualInstance.set({'foaf:name': 'Al Einstein'});
test.equal(backboneEntities[1].get('foaf:name'), 'Al Einstein');

// And then the interesting bit, check that it changed in the HTML as well
jQuery('[property="foaf:name"]', html).each(function() {
test.equal(jQuery(this).html(), 'Al Einstein', 'Check that the change actually affected the HTML');
});

VIE.cleanup();
test.done();
};

exports['test updating views'] = function(test) {
var html = jQuery('<div about="http://dbpedia.org/resource/Albert_Einstein"><span property="foaf:name">Albert Einstein</span><span property="dbp:dateOfBirth" datatype="xsd:date">1879-03-14</span><div rel="dbp:birthPlace" resource="http://dbpedia.org/resource/Germany" /><span about="http://dbpedia.org/resource/Germany" property="dbp:conventionalLongName">Federal Republic of Germany</span></div>');

Expand Down
4 changes: 2 additions & 2 deletions vie.js
Expand Up @@ -88,7 +88,7 @@

Types: {},

getById: function(id) {
getBySubject: function(id) {
if (typeof VIE.EntityManager.Entities[id] === 'undefined') {
return null;
}
Expand All @@ -102,7 +102,7 @@
properties = VIE.EntityManager._JSONtoProperties(jsonld);

if (typeof jsonld['@'] !== 'undefined') {
entityInstance = VIE.EntityManager.getById(jsonld['@']);
entityInstance = VIE.EntityManager.getBySubject(jsonld['@']);
if (entityInstance) {
entityInstance.set(properties);
return entityInstance;
Expand Down

0 comments on commit 48484f5

Please sign in to comment.