mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[jquery/findTestSubject] added tests
This commit is contained in:
parent
f1a9069b35
commit
465612c469
1 changed files with 59 additions and 0 deletions
59
src/ui/public/jquery/__tests__/findTestSubject.js
vendored
Normal file
59
src/ui/public/jquery/__tests__/findTestSubject.js
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
var $ = require('jquery');
|
||||
var expect = require('expect.js');
|
||||
|
||||
function $make(subject) {
|
||||
return $('<div>').attr('data-test-subj', subject);
|
||||
}
|
||||
|
||||
describe('jQuery.findTestSubject', function () {
|
||||
it('finds all of the element with a subject', function () {
|
||||
var $container = $('<div>');
|
||||
var $match = $make('subject').appendTo($container);
|
||||
var $noMatch = $make('notSubject').appendTo($container);
|
||||
|
||||
var $found = $container.findTestSubject('subject');
|
||||
expect($found.is($match)).to.be(true);
|
||||
expect($found.is($noMatch)).to.be(false);
|
||||
});
|
||||
|
||||
it('finds all of the elements with either "saveButton" or "cancelButton"', function () {
|
||||
var $container = $('<div>');
|
||||
var $match1 = $make('subject').appendTo($container);
|
||||
var $match2 = $make('alsoSubject').appendTo($container);
|
||||
var $noMatch = $make('notSubject').appendTo($container);
|
||||
|
||||
var $found = $container.findTestSubject('subject', 'alsoSubject');
|
||||
expect($found.filter($match1).size()).to.be(1);
|
||||
expect($found.filter($match2).size()).to.be(1);
|
||||
expect($found.filter($noMatch).size()).to.be(0);
|
||||
});
|
||||
|
||||
it('finds all of the elements with a decendant selector', function () {
|
||||
var $container = $('<div>');
|
||||
var $parent = $make('foo name').appendTo($container);
|
||||
var $bar = $make('bar othername').appendTo($parent);
|
||||
var $baz = $make('baz third name').appendTo($parent);
|
||||
|
||||
expect($container.findTestSubject('foo bar').is($bar)).to.be(true);
|
||||
expect($container.findTestSubject('foo bar').is($baz)).to.be(false);
|
||||
|
||||
expect($container.findTestSubject('foo baz').is($bar)).to.be(false);
|
||||
expect($container.findTestSubject('foo baz').is($baz)).to.be(true);
|
||||
});
|
||||
|
||||
it('finds elements with compound subjects', function () {
|
||||
var $container = $('<div>');
|
||||
var $bar = $make('button bar').appendTo($container);
|
||||
var $baz = $make('button baz').appendTo($container);
|
||||
|
||||
expect($container.findTestSubject('button&bar').is($bar)).to.be(true);
|
||||
expect($container.findTestSubject('button& bar').is($bar)).to.be(true);
|
||||
expect($container.findTestSubject('button & bar').is($bar)).to.be(true);
|
||||
expect($container.findTestSubject('button &bar').is($bar)).to.be(true);
|
||||
|
||||
expect($container.findTestSubject('button&baz').is($baz)).to.be(true);
|
||||
expect($container.findTestSubject('button& baz').is($baz)).to.be(true);
|
||||
expect($container.findTestSubject('button & baz').is($baz)).to.be(true);
|
||||
expect($container.findTestSubject('button &baz').is($baz)).to.be(true);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue