Blame view

framework/thirdparty/jquery-metadata/test/test.js 2.29 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  function testData(index) {
  	var data = jQuery.metadata.get(this);
  	switch(index) {
  	case 0:
  		ok( data.foo == "bar", "Check foo property" );
  		ok( data.bar == "baz", "Check baz property" );
  		ok( data.arr[0] == 1, "Check arr[0] property" );
  		ok( data.arr[1] == 2, "Check arr[1] property" );
  		break;
  	case 1:
  		ok( data.test == "bar", "Check test property" );
  		ok( data.bar == "baz", "Check bar property" );
  		break;
  	case 2:
  		ok( data.zoooo == "bar", "Check zoooo property" );
  		ok( data.bar.test == "baz", "Check bar.test property" );
  		break;
  	case 3:
  		ok( data.number, "Check number property" );
  		ok( data.stuff[0] == 2, "Check stuff[0] property" );
  		ok( data.stuff[1] == 8, "Check stuff[1] property" );
  		break;
  	default:
  		ok( false, ["Assertion failed on index ", index, ", with data ", data].join('') );
  	}
  }
  
  // check if set can be intercepted without breaking metadata plugin
  var oldSet = jQuery.fn.set;
  jQuery.fn.set = function() {
  	ok( true, "set was interecepted" );
  	oldSet.apply(this, arguments);
  };
  
  //jQuery.meta.single = "";
  
  test("meta: type attr - from data attribute", function() {
  	expect(11);
  	jQuery.metadata.setType("attr", "data");
  	jQuery("#one li").each(testData);
  });
  
  test("meta: type class - from className", function() {
  	expect(11);
  	jQuery.metadata.setType( "class" );
  	jQuery("#two li").each(testData);
  });
  
  test("meta: children script element - get data from child script element", function() {
  	expect(11);
  	jQuery.metadata.setType( "elem", "script" );
  	jQuery("#three li").each(testData);
  });
  
  test("check if window doesn't break anything", function() {
  	jQuery(window).get();
  });
  
  test("meta: default with single data object", function() {
  	expect(11);
  	jQuery.metadata.setType("attr","data");
  	jQuery.metadata.defaults.single = "data";
  	jQuery("#four li").each(testData);
  });
  
  test("meta with select and class", function() {
  	expect(2);
  	jQuery.metadata.setType("class");
  	jQuery.metadata.single = "stuff";
  	var e = $('#meal').metadata();
  	ok( e, "data property" );
  	ok( e.required, "property on data property" );
  });
  
  test("try to add and remove classes on metadata elements", function() {
  	$("#two li").addClass("foobar").addClass("foo bar").removeClass("foobar");
  	ok( $("#two li").is(".foo"), 'Check class foo was added.' );
  	ok( $("#two li").is(".bar"), 'Check class bar was added.' );
  });