提交 cdbbc8cc 编写于 作者: T tfennelly

Added some finder tests

上级 cd604628
......@@ -102,6 +102,29 @@ ConfigSection.prototype.markRowsAsActive = function() {
this.updateRowGroupVisibility();
};
ConfigSection.prototype.hasText = function(text) {
var $ = jQD.getJQuery();
var selector = ":containsci('" + text + "')";
var sectionRows = this.getRows();
for (var i1 = 0; i1 < sectionRows.length; i1++) {
var row = sectionRows[i1];
var elementsWithText = $(selector, row);
if (elementsWithText.size() > 0) {
return true;
}
}
for (var i2 = 0; i2 < this.subSections.length; i2++) {
if (this.subSections[i2].hasText(text)) {
return true;
}
}
return false;
};
ConfigSection.prototype.activeRowCount = function() {
var activeRowCount = 0;
var rows = this.getRows();
......@@ -190,8 +213,8 @@ ConfigSection.prototype.highlightText = function(text) {
var selector = ":containsci('" + text + "')";
var rows = this.getRows();
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
for (var i1 = 0; i1 < rows.length; i1++) {
var row = rows[i1];
/*jshint loopfunc: true */
$('span.highlight-split', row).each(function() { // jshint ignore:line
......@@ -209,11 +232,16 @@ ConfigSection.prototype.highlightText = function(text) {
$this.contents().each(function () {
// We specifically only mess with text nodes
if (this.nodeType === 3) {
var highlightedMarkup = this.wholeText.replace(regex, '<span class="highlight">$1</span>');
$(this).replaceWith('<span class="highlight-split">' + highlightedMarkup + '</span>');
var $textNode = $(this);
var highlightedMarkup = $textNode.text().replace(regex, '<span class="highlight">$1</span>');
$textNode.replaceWith('<span class="highlight-split">' + highlightedMarkup + '</span>');
}
});
});
}
}
for (var i2 = 0; i2 < this.subSections.length; i2++) {
this.subSections[i2].highlightText(text);
}
};
......@@ -262,7 +262,7 @@ ConfigTableMetaData.prototype.showSections = function(withText) {
if (withText === '') {
if (this.hasSections()) {
for (var i1 = 0; i1 < this.sections.length; i1++) {
this.sections[i1].activator.show();
this.sections[i1].activator.removeClass('hidden');
}
var activeSection = this.activeSection();
if (!activeSection) {
......@@ -273,30 +273,16 @@ ConfigTableMetaData.prototype.showSections = function(withText) {
}
} else {
if (this.hasSections()) {
var $ = jQD.getJQuery();
var selector = ":containsci('" + withText + "')";
var sectionsWithText = [];
for (var i2 = 0; i2 < this.sections.length; i2++) {
var section = this.sections[i2];
var containsText = false;
var sectionRows = section.getRows();
for (var i3 = 0; i3 < sectionRows.length; i3++) {
var row = sectionRows[i3];
var elementsWithText = $(selector, row);
if (elementsWithText.size() > 0) {
containsText = true;
break;
}
}
if (containsText) {
section.activator.show();
if (section.hasText(withText)) {
section.activator.removeClass('hidden');
sectionsWithText.push(section);
} else {
section.activator.hide();
section.activator.addClass('hidden');
}
}
......
......@@ -10,4 +10,9 @@
/*
* Widget styles
*/
@import "config/tabbar";
\ No newline at end of file
@import "config/tabbar";
.hidden {
display: none;
}
\ No newline at end of file
......@@ -129,7 +129,8 @@
<tr class="optional-block-start row-group-start row-set-start" hashelp="true" ref="cb19">
<td colspan="3">
<input class="optional-block-control block-control "type="checkbox">
<label class="attach-previous">Build after other projects are built</label>
<!-- We added the text "Trigger" here for testing the finder -->
<label class="attach-previous">Build (Trigger) after other projects are built</label>
</td>
</tr>
<tr>
......
......@@ -71,6 +71,102 @@ describe("tabbar-spec tests", function () {
done();
}, 'widgets/config/freestyle-config.html');
});
it("- test finder - via handler triggering", function (done) {
jsTest.onPage(function() {
var configTabBarWidget = jsTest.requireSrcModule('widgets/config/tabbar');
var configTabBar = configTabBarWidget.addTabsOnFirst();
var jQD = require('jquery-detached');
var $ = jQD.getJQuery();
var tabBar = $('.tabBar');
// All tabs should be visible...
expect($('.tab', tabBar).size()).toBe(4);
expect($('.tab.hidden', tabBar).size()).toBe(0);
var finder = configTabBar.findInput;
expect(finder.size()).toBe(1);
// Find sections that have the text "trigger" in them...
keydowns('trigger', finder);
// Need to wait for the change to happen ... there's a 300ms delay.
// We could just call configTabBar.showSections(), but ...
setTimeout(function() {
expect($('.tab.hidden', tabBar).size()).toBe(3);
expect(textCleanup($('.tab.hidden', tabBar).text())).toBe('General|#Advanced Project Options|#Build');
var activeSection = configTabBar.activeSection();
expect(textCleanup(activeSection.title)).toBe('#Build Triggers');
expect($('.highlight-split .highlight').text()).toBe('Trigger');
done();
}, 600);
}, 'widgets/config/freestyle-config.html');
});
it("- test finder - via showSections()", function (done) {
jsTest.onPage(function() {
var configTabBarWidget = jsTest.requireSrcModule('widgets/config/tabbar');
var configTabBar = configTabBarWidget.addTabsOnFirst();
var jQD = require('jquery-detached');
var $ = jQD.getJQuery();
var tabBar = $('.tabBar');
configTabBar.showSections('quiet period');
expect($('.tab.hidden', tabBar).size()).toBe(3);
expect(textCleanup($('.tab.hidden', tabBar).text())).toBe('General|#Build Triggers|#Build');
var activeSection = configTabBar.activeSection();
expect(textCleanup(activeSection.title)).toBe('#Advanced Project Options');
done();
}, 'widgets/config/freestyle-config.html');
});
it("- test finder - via showSections() - in inner row-group", function (done) {
jsTest.onPage(function() {
var configTabBarWidget = jsTest.requireSrcModule('widgets/config/tabbar');
var configTabBar = configTabBarWidget.addTabsOnFirst();
var jQD = require('jquery-detached');
var $ = jQD.getJQuery();
var tabBar = $('.tabBar');
configTabBar.showSections('Strategy');
expect($('.tab.hidden', tabBar).size()).toBe(3);
expect(textCleanup($('.tab.hidden', tabBar).text())).toBe('#Advanced Project Options|#Build Triggers|#Build');
var activeSection = configTabBar.activeSection();
expect(textCleanup(activeSection.title)).toBe('General');
done();
}, 'widgets/config/freestyle-config.html');
});
function keydowns(text, onInput) {
var jQD = require('jquery-detached');
var $ = jQD.getJQuery();
// hmmm, for some reason, the key events do not result in the text being
// set in the input, so setting it manually.
onInput.val(text);
// Now fire a keydown event to trigger the handler
var e = $.Event("keydown");
e.which = 116;
onInput.trigger(e);
}
function textCleanup(text) {
return text.trim().replace(/(\r\n|\n|\r)/gm, "").replace(/ +/g, "|");
}
});
// TODO: lots more tests !!!
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册