Skip to content

Commit

Permalink
Merge remote-tracking branch 'Dinuka2013513/FLUID-5689'
Browse files Browse the repository at this point in the history
* Dinuka2013513/FLUID-5689:
  FLUID-5689: update the copyright sections
  FLUID-5689: Updated the test message in assertNode
  FLUID-5689: Removed the additional message appending to the length verification of nodes
  FLUID-5689: Changed the test case message
  FLUID-5689: Separated the pager tooltip tests to another grade.
  FLUID-5689: Code refactoring in pager test cases
  FLUID-5689: Code Refactoring
  FLUID-5689: Added test cases which are related to the bug fix in FLUID-5689
  FLUID-5689: Updated the pager size dropdown in the pager table test file
  FLUID-5689: Code Refatoring
  FLUID-5689: Changed the message of the test case
  FLUID-5689: Updated unwanted modelListeners
  FLUID-5689: Updated test cases of pager
  FLUID-5689: Pager demo tooltips out of sync with table
  • Loading branch information
jobara committed Jul 14, 2016
2 parents 3f148ee + dcd1a8a commit dacc70f
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 65 deletions.
3 changes: 2 additions & 1 deletion src/components/pager/js/PagedTable.js
Expand Up @@ -3,6 +3,7 @@ Copyright 2008-2009 University of Cambridge
Copyright 2008-2009 University of Toronto
Copyright 2010-2013 OCAD University
Copyright 2010-2011 Lucendo Development Ltd.
Copyright 2016 Dinuka De Silva
Licensed under the Educational Community License (ECL), Version 2.0 or the New
BSD license. You may not use this file except in compliance with one these
Expand Down Expand Up @@ -47,7 +48,7 @@ var fluid_2_0_0 = fluid_2_0_0 || {};
var tooltipInfo = {};

fluid.each(tree, function (cell) {
if (cell.ID === "page-link:link" && !cell.current) {
if (cell.ID === "page-link:link") {
var page = cell.pageIndex;
var start = page * tModel.pageSize;
tModel.pageIndex = page;
Expand Down
6 changes: 5 additions & 1 deletion tests/component-tests/pager/html/PagedTable-test.html
Expand Up @@ -148,7 +148,11 @@ <h2 id="qunit-userAgent"></h2>
</div>
<!-- Presence of these two controls tests an obscure FLUID-5082 bug, do not remove -->
<span class="flc-pager-summary"></span>
<select class="flc-pager-page-size"></select>
<select class="flc-pager-page-size">
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>

<table class="flc-pager-body-template">
<thead>
Expand Down
183 changes: 121 additions & 62 deletions tests/component-tests/pager/js/PagedTableTests.js
Expand Up @@ -2,6 +2,7 @@
Copyright 2008-2009 University of Cambridge
Copyright 2008-2009 University of Toronto
Copyright 2010-2014 OCAD University
Copyright 2016 Dinuka De Silva
Licensed under the Educational Community License (ECL), Version 2.0 or the New
BSD license. You may not use this file except in compliance with one these
Expand Down Expand Up @@ -59,6 +60,15 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
},
{
animal: "fish"
},
{
animal: "camel"
},
{
animal: "dragon"
},
{
animal: "ant"
}
]
},
Expand Down Expand Up @@ -149,63 +159,6 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
return pager;
};

fluid.tests.tooltipModuleSource = function (pager) {
var pageLinksTop = $("a", pager.pagerBar.locate("pageLinks"));
var pageLinksBottom = $("a", pager["pagerBar-1"].locate("pageLinks"));

var tooltipContents = [
[
{nodeName: "b", nodeText: "bird"},
{nodeName: "b", nodeText: "fish"}
]
];

var sequence = [];

var assertVisibleTips = function (message, targetIds) {
sequence.push({
event: "{trackTooltips}.events.notifyFocusChange",
listener: function () {
fluid.tests.tooltip.assertVisible(message, pager, targetIds, null, function (tooltip) {
jqUnit.assertNode("The contents of the tooltip should be set", tooltipContents[0], $("b", tooltip));
});
}
});
};

var tooltipTest = function (location) {
return function (idx, linkEl) {
var linkId = linkEl.id;
var link = $(linkEl);
sequence.push({
element: link,
jQueryTrigger: "focus"
});

if (link.hasClass(pager.pagerBar.options.styles.currentPage)) { // assumption that this will not change between now and then!
assertVisibleTips("There shouldn't be any tooltips visible when the currentPage is focused", []);
} else {
assertVisibleTips("Only the tooltip for page link " + (idx + 1) + ", in the " + location + " page bar is visible", [linkId]);
}
sequence.push({
element: link,
jQueryTrigger: "blur"
});
assertVisibleTips("There shouldn't be any tooltips visible when none of the pageLinks are focused", []);
};
};

pageLinksTop.each(tooltipTest("top"));
pageLinksBottom.each(tooltipTest("bottom"));
return {
name: "Pager tooltip tests",
tests: {
name: "Tooltip visibility",
sequence: sequence
}
};
};

fluid.defaults("fluid.tests.pagerTooltipEnv", {
gradeNames: ["fluid.test.testEnvironment"],
markupFixture: "#rendered-ioc",
Expand All @@ -218,17 +171,123 @@ https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt
}
},
fixtures: {
type: "fluid.test.testCaseHolder",
type: "fluid.tests.pagerTooltipTests",
options: {
moduleSource: {
func: "fluid.tests.tooltipModuleSource",
args: "{pager}"
}
sequenceOfPageSizes: [2, 3, 4]
}
}
}
});

fluid.defaults("fluid.tests.pagerTooltipTests", {
gradeNames: ["fluid.test.testCaseHolder"],
sequenceOfPageSizes: [],
moduleSource: {
func: "fluid.tests.getTooltipModuleSource",
args: ["{pager}", "{that}.options.sequenceOfPageSizes"]
}
});

fluid.tests.getTooltipModuleSource = function (pager, sequencesOfPageSizes) {
var sequence = [];
var linksList = fluid.transform(pager.dataModel, function (data) {
return {text: data.animal};
});

/* Change the page size and verify whether the tooltips and links are synced accordingly */
fluid.each(sequencesOfPageSizes, function (pageSize) {
var expectedTooltips = fluid.tests.getTooltipContents(linksList, pageSize);
$.merge(sequence, [
{
func: "fluid.changeElementValue",
args: ["{pager}.dom.pageSize", pageSize]
},
{
func: "fluid.tests.verifyPagerBar",
args: ["{pager}", "top", pageSize]
},
{
func: "fluid.tests.verifyPagerBar",
args: ["{pager}", "bottom", pageSize]
},
{
func: "fluid.tests.verifyToolTipsOfPagerBar",
args: ["{pager}", "top", pageSize, expectedTooltips]
},
{
func: "fluid.tests.verifyToolTipsOfPagerBar",
args: ["{pager}", "bottom", pageSize, expectedTooltips]
}
]);
});

return {
name: "Pager tooltip tests",
tests: [
{
name: "Tooltip visibility and contents",
sequence: sequence
}
]
};
};

fluid.tests.getTooltipContents = function (listOfData, pageSize) {
var tooltipContents = [];
for (var i = 0; i < listOfData.length; i += pageSize) {
var tooltipContent = [];
var pageStartIndex = i;
var pageEndIndex = Math.min(pageStartIndex + pageSize - 1, listOfData.length - 1);
tooltipContent.push({nodeName: "b", nodeText: listOfData[pageStartIndex].text});
tooltipContent.push({nodeName: "b", nodeText: listOfData[pageEndIndex].text});
tooltipContents.push(tooltipContent);
}

return tooltipContents;
};

fluid.tests.getPagerBar = function (pager, location) {
return pager[location === "top" ? "pagerBar" : "pagerBar-1"];
};

fluid.tests.verifyPagerBar = function (pager, location, pageSize) {
var expectedNumberOfLinks = Math.ceil(pager.dataModel.length / pageSize);

//Verify the number of links in the pager bar
jqUnit.assertEquals("The number of links in the pager should be according to the page size",
expectedNumberOfLinks,
fluid.tests.getPagerBar(pager, location).locate("pageLinks").length);
};

fluid.tests.assertVisibleTips = function (pager, message, targetIds, expectedTooltip) {
fluid.tests.tooltip.assertVisible(message, pager, targetIds, null, function (tooltip) {
jqUnit.assertNode("The contents of the tooltip should be set", expectedTooltip, $("b", tooltip));
});
};

fluid.tests.verifyToolTipsOfPagerBar = function (pager, location, pageSize, expectedTooltips) {
var expectedNumberOfLinks = Math.ceil(pager.dataModel.length / pageSize);
for (var x = 0; x < expectedNumberOfLinks; x++) {
fluid.tests.verifyPagerToolTip(pager, location, x, expectedTooltips[x]);
}
};

fluid.tests.verifyPagerToolTip = function (pager, location, index, expectedTooltip) {
var link = fluid.tests.getPagerBar(pager, location).locate("pageLinks").find("a").eq(index);
var linkNumber = index + 1;
var linkId = "page-link:link" + linkNumber + (location === "bottom" ? "-1" : "");

link.trigger("focus");
fluid.tests.assertVisibleTips(pager,
"The tooltip of page link " + linkNumber + ", in " + location + " page bar is visible",
[linkId], expectedTooltip);

link.trigger("blur");
fluid.tests.assertVisibleTips(pager,
"There should not be any tooltips visible when no pageLinks are focused.",
[], expectedTooltip);
};

fluid.tests.runPagedTableTests = function () {

// This IoC-enabled test must come first, as a result of an undiagnosed Firefox issue which causes the running
Expand Down
3 changes: 2 additions & 1 deletion tests/test-core/jqUnit/js/jqUnit-browser.js
Expand Up @@ -3,6 +3,7 @@ Copyright 2008-2009 University of Cambridge
Copyright 2008-2010 University of Toronto
Copyright 2010-2011 OCAD University
Copyright 2010-2011 Lucendo Development Ltd.
Copyright 2016 Dinuka De Silva
Licensed under the Educational Community License (ECL), Version 2.0 or the New
BSD license. You may not use this file except in compliance with one these
Expand Down Expand Up @@ -134,7 +135,7 @@ var jqUnit = jqUnit || {};
node = node[0];
}
else if (node.length !== undefined) {
jqUnit.assertEquals("Expected number of nodes " + message, expected.length, node.length);
jqUnit.assertEquals(message + ": Expected number of nodes ", expected.length, node.length);
for (var i = 0; i < node.length; ++i) {
jqUnit.assertNode(message + ": node " + i + ": ", expected[i], node[i]);
}
Expand Down

0 comments on commit dacc70f

Please sign in to comment.