Refactored to remove duplicated code

This commit is contained in:
houseofyin 2013-04-02 13:49:15 -04:00
parent 858487f8c6
commit 6b97ab4424

View File

@ -127,8 +127,8 @@ QUnit.config.autostart = false;
}; };
var waitForViewer = function () { var waitForViewer = function () {
return function () { return function (handler, count, lastDisplayRegionLeft, lastDisplayWidth) {
return function (handler, count, lastDisplayRegionLeft, lastDisplayWidth) { // return function () {
var currentDisplayRegionLeft; var currentDisplayRegionLeft;
var currentDisplayWidth; var currentDisplayWidth;
if (displayRegion === null) if (displayRegion === null)
@ -178,7 +178,7 @@ QUnit.config.autostart = false;
handler(); handler();
} }
}; };
}(); // }();
}(); }();
var simulateNavigatorClick = function(viewer, locationX, locationY) { var simulateNavigatorClick = function(viewer, locationX, locationY) {
@ -208,6 +208,8 @@ QUnit.config.autostart = false;
var assessViewerInCorner = function(theContentCorner) var assessViewerInCorner = function(theContentCorner)
{ {
return function()
{
var expectedXCoordinate, expecteYCoordinate; var expectedXCoordinate, expecteYCoordinate;
if (theContentCorner === "TOPLEFT") if (theContentCorner === "TOPLEFT")
{ {
@ -237,6 +239,7 @@ QUnit.config.autostart = false;
{ {
assessNumericValueWithSomeVariance(expecteYCoordinate, viewer.viewport.getBounds().y,.04, ' Viewer at ' + theContentCorner + ', y coord'); assessNumericValueWithSomeVariance(expecteYCoordinate, viewer.viewport.getBounds().y,.04, ' Viewer at ' + theContentCorner + ', y coord');
} }
}
}; };
var assessViewerInCenter = function() var assessViewerInCenter = function()
@ -253,28 +256,31 @@ QUnit.config.autostart = false;
var clickOnNavigator = function(theContentCorner) var clickOnNavigator = function(theContentCorner)
{ {
var xPos, yPos; return function()
if (theContentCorner === "TOPLEFT")
{ {
xPos = spaceFromLeftEdgeOfViewerToContentStart; var xPos, yPos;
yPos = spaceFromTopEdgeOfViewerToContentStart; if (theContentCorner === "TOPLEFT")
{
xPos = spaceFromLeftEdgeOfViewerToContentStart;
yPos = spaceFromTopEdgeOfViewerToContentStart;
}
else if (theContentCorner === "TOPRIGHT")
{
xPos = spaceFromLeftEdgeOfViewerToContentStart + widthOfViewerContentOnNavigator;
yPos = spaceFromTopEdgeOfViewerToContentStart;
}
else if (theContentCorner === "BOTTOMRIGHT")
{
xPos = spaceFromLeftEdgeOfViewerToContentStart + widthOfViewerContentOnNavigator;
yPos = spaceFromTopEdgeOfViewerToContentStart + heightOfViewerContentOnNavigator;
}
else if (theContentCorner === "BOTTOMLEFT")
{
xPos = spaceFromLeftEdgeOfViewerToContentStart;
yPos = spaceFromTopEdgeOfViewerToContentStart + heightOfViewerContentOnNavigator;
}
simulateNavigatorClick(viewer.navigator, xPos, yPos);
} }
else if (theContentCorner === "TOPRIGHT")
{
xPos = spaceFromLeftEdgeOfViewerToContentStart + widthOfViewerContentOnNavigator;
yPos = spaceFromTopEdgeOfViewerToContentStart;
}
else if (theContentCorner === "BOTTOMRIGHT")
{
xPos = spaceFromLeftEdgeOfViewerToContentStart + widthOfViewerContentOnNavigator;
yPos = spaceFromTopEdgeOfViewerToContentStart + heightOfViewerContentOnNavigator;
}
else if (theContentCorner === "BOTTOMLEFT")
{
xPos = spaceFromLeftEdgeOfViewerToContentStart;
yPos = spaceFromTopEdgeOfViewerToContentStart + heightOfViewerContentOnNavigator;
}
simulateNavigatorClick(viewer.navigator, xPos, yPos);
}; };
var dragNavigatorBackToCenter = function() var dragNavigatorBackToCenter = function()
@ -296,65 +302,43 @@ QUnit.config.autostart = false;
seadragonProperties.visibilityRatio = 1; seadragonProperties.visibilityRatio = 1;
viewer = OpenSeadragon(seadragonProperties); viewer = OpenSeadragon(seadragonProperties);
var assessAfterDragNavigatorFromTopLeft = function() { var navigatorInteractionOperations = [ clickOnNavigator("TOPRIGHT"),dragNavigatorBackToCenter,
assessNavigatorDisplayRegionAndMainViewerState("After drag on navigator from top left"); clickOnNavigator("BOTTOMLEFT"),dragNavigatorBackToCenter,
assessViewerInCenter(); clickOnNavigator("BOTTOMRIGHT"),dragNavigatorBackToCenter,
start(); clickOnNavigator("TOPLEFT"),dragNavigatorBackToCenter ];
}; var navigatorAssessmentOperations = [assessViewerInCorner("TOPRIGHT"),assessViewerInCenter,
assessViewerInCorner("BOTTOMLEFT"),assessViewerInCenter,
assessViewerInCorner("BOTTOMRIGHT"),assessViewerInCenter,
assessViewerInCorner("TOPLEFT"),assessViewerInCenter];
var assessAfterClickOnNavigatorTopLeft = function() { var navigatorAssessmentMessages = ["After click on navigator on top right","After drag on navigator from top right",
assessNavigatorDisplayRegionAndMainViewerState("After click on navigator on top left"); "After click on navigator on bottom left","After drag on navigator from bottom left",
assessViewerInCorner("TOPLEFT"); "After click on navigator on bottom right","After drag on navigator from bottom right",
dragNavigatorBackToCenter(); "After click on navigator on top right","After drag on navigator from top right"];
waitForViewer(assessAfterDragNavigatorFromTopLeft);
};
var assessAfterDragNavigatorFromBottomRight = function() { var assessNavigatorOperationAndTakeNextStep = function(step)
assessNavigatorDisplayRegionAndMainViewerState("After drag on navigator from bottom right"); {
assessViewerInCenter(); return function()
clickOnNavigator("TOPLEFT"); {
waitForViewer(assessAfterClickOnNavigatorTopLeft); var nextStep = step+1;
}; assessNavigatorDisplayRegionAndMainViewerState(navigatorAssessmentMessages[step]);
navigatorAssessmentOperations[step]();
var assessAfterClickOnNavigatorBottomRight = function() { if (step === navigatorInteractionOperations.length-1)
assessNavigatorDisplayRegionAndMainViewerState("After click on navigator on bottom right"); {
assessViewerInCorner("BOTTOMRIGHT"); start();
dragNavigatorBackToCenter(); }
waitForViewer(assessAfterDragNavigatorFromBottomRight); else
}; {
navigatorInteractionOperations[nextStep]();
var assessAfterDragNavigatorFromBottomLeft = function() { waitForViewer(assessNavigatorOperationAndTakeNextStep(nextStep));
assessNavigatorDisplayRegionAndMainViewerState("After drag on navigator from top left"); }
assessViewerInCenter(); };
clickOnNavigator("BOTTOMRIGHT");
waitForViewer(assessAfterClickOnNavigatorBottomRight);
};
var assessAfterClickOnNavigatorBottomLeft = function() {
assessNavigatorDisplayRegionAndMainViewerState("After click on navigator on bottom left");
assessViewerInCorner("BOTTOMLEFT");
dragNavigatorBackToCenter();
waitForViewer(assessAfterDragNavigatorFromBottomLeft);
};
var assessAfterDragNavigatorFromTopRight = function() {
assessNavigatorDisplayRegionAndMainViewerState("After drag on navigato from top rightr");
assessViewerInCenter();
clickOnNavigator("BOTTOMLEFT");
waitForViewer(assessAfterClickOnNavigatorBottomLeft);
};
var assessAfterClickOnNavigatorTopRight = function() {
assessNavigatorDisplayRegionAndMainViewerState("After click on navigator on top right");
assessViewerInCorner("TOPRIGHT");
dragNavigatorBackToCenter();
waitForViewer(assessAfterDragNavigatorFromTopRight);
}; };
var assessAfterDragOnViewer = function () { var assessAfterDragOnViewer = function () {
assessNavigatorDisplayRegionAndMainViewerState("After pan"); assessNavigatorDisplayRegionAndMainViewerState("After pan");
clickOnNavigator("TOPRIGHT"); navigatorInteractionOperations[0]();
waitForViewer(assessAfterClickOnNavigatorTopRight); waitForViewer(assessNavigatorOperationAndTakeNextStep(0));
}; };
var assessAfterZoomOnViewer = function () { var assessAfterZoomOnViewer = function () {