xonecas.io
142
St

startsInvasion / files

startsInvasion / libs / node_modules / bonzo / build / qwery / tests / tests.js

6.3 KB
1sink('no conflict', function (test, ok) {
2  test('should return old qwery back to context', 1, function () {
3    ok(qwery() == 'success', 'old qwery called');
4  });
5});
6
7sink('Contexts', function (test, ok) {
8  test('should be able to pass optional context', 2, function () {
9    ok(Q('.a').length === 3, 'no context found 3 elements (.a)');
10    ok(Q('.a', Q('#boosh')[0]).length === 2, 'context found 2 elements (#boosh .a)');
11  });
12  test('should be able to pass string as context', 5, function() {
13    ok(Q('.a', '#boosh').length == 2, 'context found 2 elements(.a, #boosh)');
14    ok(Q('.a', '.a').length == 0, 'context found 0 elements(.a, .a)');
15    ok(Q('.a', '.b').length == 1, 'context found 1 elements(.a, .b)');
16    ok(Q('.a', '#boosh .b').length == 1, 'context found 1 elements(.a, #boosh .b)');
17    ok(Q('.b', '#boosh .b').length == 0, 'context found 0 elements(.b, #boosh .b)');
18  });
19  test('should not return duplicates from combinators', 1, function () {
20    ok(Q('#boosh,#boosh').length == 1, 'two booshes dont make a thing go right');
21  });
22});
23
24sink('CSS 1', function (test, ok) {
25  test('get element by id', 2, function () {
26    var result = Q('#boosh');
27    ok(!!result[0], 'found element with id=boosh');
28    ok(!!Q('h1')[0], 'found 1 h1');
29  });
30
31  test('get element by class', 5, function () {
32    ok(Q('#boosh .a').length == 2, 'found two elements');
33    ok(!!Q('#boosh div.a')[0], 'found one element');
34    ok(Q('#boosh div').length == 2, 'found two {div} elements');
35    ok(!!Q('#boosh span')[0], 'found one {span} element');
36    ok(!!Q('#boosh div div')[0], 'found a single div');
37  });
38
39  test('combos', 1, function () {
40    ok(Q('#boosh div,#boosh span').length == 3, 'found 2 divs and 1 span');
41  });
42
43  test('class with dashes', 1, function() {
44    ok(Q('.class-with-dashes').length == 1, 'found something');
45  });
46});
47
48sink('CSS 2', function (test, ok) {
49
50  test('get elements by attribute', 4, function () {
51    var wanted = Q('#boosh div[test]')[0];
52    var expected = document.getElementById('booshTest');
53    ok(wanted == expected, 'found attribute');
54    ok(Q('#boosh div[test=fg]')[0] == expected, 'found attribute with value');
55    ok(Q('em[rel~="copyright"]').length == 1, 'found em[rel~="copyright"]');
56    ok(Q('em[nopass~="copyright"]').length == 0, 'found em[nopass~="copyright"]');
57  });
58
59  test('should not throw error by attribute selector', 1, function () {
60    ok(Q('[foo^="bar"]').length === 1, 'found 1 element');
61  });
62
63  test('crazy town', 1, function () {
64    var el = document.getElementById('attr-test3');
65    ok(Q('div#attr-test3.found.you[title="whatup duders"]')[0] == el, 'found the right element');
66  });
67
68});
69
70sink('attribute selectors', function (test, ok) {
71
72  /* CSS 2 SPEC */
73
74  test('[attr]', 1, function () {
75    var expected = document.getElementById('attr-test-1');
76    ok(Q('#attributes div[unique-test]')[0] == expected, 'found attribute with [attr]');
77  });
78
79  test('[attr=val]', 3, function () {
80    var expected = document.getElementById('attr-test-2');
81    ok(Q('#attributes div[test="two-foo"]')[0] == expected, 'found attribute with =');
82    ok(Q("#attributes div[test='two-foo']")[0] == expected, 'found attribute with =');
83    ok(Q('#attributes div[test=two-foo]')[0] == expected, 'found attribute with =');
84  });
85
86  test('[attr~=val]', 1, function () {
87    var expected = document.getElementById('attr-test-3');
88    ok(Q('#attributes div[test~=three]')[0] == expected, 'found attribute with ~=');
89  });
90
91  test('[attr|=val]', 2, function () {
92    var expected = document.getElementById('attr-test-2');
93    ok(Q('#attributes div[test|="two-foo"]')[0] == expected, 'found attribute with |=');
94    ok(Q('#attributes div[test|=two]')[0] == expected, 'found attribute with |=');
95  });
96
97  /* CSS 3 SPEC */
98
99  test('[attr^=val]', 1, function () {
100    var expected = document.getElementById('attr-test-2');
101    ok(Q('#attributes div[test^=two]')[0] == expected, 'found attribute with ^=');
102  });
103
104  test('[attr$=val]', 1, function () {
105    var expected = document.getElementById('attr-test-2');
106    ok(Q('#attributes div[test$=foo]')[0] == expected, 'found attribute with $=');
107  });
108
109  test('[attr*=val]', 1, function () {
110    var expected = document.getElementById('attr-test-3');
111    ok(Q('#attributes div[test*=hree]')[0] == expected, 'found attribute with *=');
112  });
113
114});
115
116
117sink('tokenizer', function (test, ok) {
118
119  test('should not get weird tokens', 5, function () {
120    ok(Q('div .tokens[title="one"]')[0] == document.getElementById('token-one'), 'found div .tokens[title="one"]');
121    ok(Q('div .tokens[title="one two"]')[0] == document.getElementById('token-two'), 'found div .tokens[title="one two"]');
122    ok(Q('div .tokens[title="one two three #%"]')[0] == document.getElementById('token-three'), 'found div .tokens[title="one two three #%"]');
123    ok(Q("div .tokens[title='one two three #%'] a")[0] == document.getElementById('token-four'), 'found div .tokens[title=\'one two three #%\'] a');
124    ok(Q('div .tokens[title="one two three #%"] a[href=foo] div')[0] == document.getElementById('token-five'), 'found div .tokens[title="one two three #%"] a[href=foo] div');
125  });
126
127});
128
129sink('order matters', function (test, ok) {
130
131  function tag(el) {
132    return el.tagName.toLowerCase();
133  }
134
135  // <div id="order-matters">
136  //   <p class="order-matters"></p>
137  //   <a class="order-matters">
138  //     <em class="order-matters"></em><b class="order-matters"></b>
139  //   </a>
140  // </div>
141
142  test('the order of elements return matters', 4, function () {
143    var els = Q('#order-matters .order-matters');
144    ok(tag(els[0]) == 'p', 'first element matched is a {p} tag');
145    ok(tag(els[1]) == 'a', 'first element matched is a {a} tag');
146    ok(tag(els[2]) == 'em', 'first element matched is a {em} tag');
147    ok(tag(els[3]) == 'b', 'first element matched is a {b} tag');
148  });
149
150});
151
152sink('argument types', function (test, ok) {
153  test('should be able to pass in nodes as arguments', 6, function () {
154    var el = document.getElementById('boosh');
155    ok(Q(el)[0] == el, 'Q(el)[0] == el');
156    ok(Q(el, 'body')[0] == el, "Q(el, 'body')[0] == el");
157    ok(Q(el, document)[0] == el, "Q(el, document)[0] == el");
158    ok(Q(window, document)[0] == null, 'Q(window, document)[0] == null');
159    ok(Q(window)[0] == window, 'Q(window)[0] == window');
160    ok(Q(document)[0] == document, 'Q(document)[0] == document');
161  });
162});
163
164start();