Skip to content

Commit

Permalink
query tests
Browse files Browse the repository at this point in the history
  • Loading branch information
statianzo committed Aug 30, 2012
1 parent a4fdd7a commit b7018ae
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/runner.html
Expand Up @@ -16,6 +16,7 @@
<script type="text/javascript" src="spec/wrap.js"></script>
<script type="text/javascript" src="spec/attrs.js"></script>
<script type="text/javascript" src="spec/css.js"></script>
<script type="text/javascript" src="spec/find.js"></script>


<script type="text/javascript">
Expand Down
119 changes: 119 additions & 0 deletions test/spec/find.js
@@ -0,0 +1,119 @@
(function($){
var template = [
'<div class="outer">',
'<i id="i1" class="a">i1</i>',
'<i id="i2" class="b">i2</i>',
'<i id="i3" class="a">i3</i>',
'<i id="i4" class="b">i4</i>',
'<i id="i5" class="a c">i5</i>',
'<form id="f1" class="a">',
' <i id="i6" class="a b c d e">i6</i>',
' <i id="i7" class="b">i7</i>',
' <input name="a" value="a" id="in1" class="c" />',
' <input name="a" value="b" id="in2" class="c" />',
' <div id="d1" class="n" data-attr="meta">',
' <i id="i8" class="d">i8</i>',
' <i id="i9" class="d">i9</i>',
' </div>',
'</form>',
'<input name="a" value="b" id="in3" class="d" />',
'<input name="b" value="b" id="in4" class="d" />',
'<input value="b" id="in5" class="d" />',
'<input name="ball" value="b" id="in6" class="e" />',
'<i id="i10" class="b c d e f g">i10</i>',
'<textarea id="t1"></textarea>',
'<div id="append"></div>',
'</div>'
].join(''),
ids = function(els) {
return Array.prototype.slice.call(els.map(function() {
return this.id;
})).join(',');
};
describe('jquip.query', function() {
var el;
beforeEach(function() {
el = $(template).appendTo('body');
});

afterEach(function() {
el.remove();
});

it('is empty when not found', function() {
var res = $('#doesnotexist');

expect(ids(res)).toBe('');
});

it('finds elements by id', function() {
var res = $('#i1');

expect(ids(res)).toBe('i1');
});

it('finds elements by class', function() {
var res = $('.a');
expect(ids(res)).toBe('i1,i3,i5,f1,i6');
});

it('finds elements with two classes', function() {
var res = $('.a.c');
expect(ids(res)).toBe('i5,i6');
});

it('finds elements by tag name', function() {
var res = $('form');
expect(ids(res)).toBe('f1');
});

it('finds elements by tag name and id', function() {
var res = $('form#f1');
expect(ids(res)).toBe('f1');
});

it('finds elements by tag name and class', function() {
var res = $('input.d');
expect(ids(res)).toBe('in3,in4,in5');
});

it('finds elements by id and class', function() {
var res = $('#in4.d');
expect(ids(res)).toBe('in4');
});

it('finds elements by id and class', function() {
var res = $('#in4.d');
expect(ids(res)).toBe('in4');
});

it('finds elements by attribute existence', function() {
var res = $('input[name]');
expect(ids(res)).toBe('in1,in2,in3,in4,in6');
});

it('finds elements by attribute value', function() {
var res = $('input[name=a]');
expect(ids(res)).toBe('in1,in2,in3');

res2 = $('input[name="a"]');
expect(ids(res2)).toBe('in1,in2,in3');
});

it('finds elements by attribute value prefix', function() {
var res = $('input[name^=b]');
expect(ids(res)).toBe('in4,in6');
});

it('finds nested elements', function() {
var res = $('form i');
expect(ids(res)).toBe('i6,i7,i8,i9');
});

it('finds direct sibling elements', function() {
var res = $('form > i');
expect(ids(res)).toBe('i6,i7');
});

});
}(jquip));

0 comments on commit b7018ae

Please sign in to comment.