Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Improves calendar cards tests by using navigator to confirm card is open #560

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 47 additions & 12 deletions test/functional/automation/blackberry.invoke.card.calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,61 @@ describe("calendar cards", function () {
onCancel = null;
});

/*
* @param func Function function that will cause some change in the foreground application
* @param test Function boolean condition that guarantees the foreground application has changed
* @param onComplete callback triggered condition in test function is satisfied
*/
function testForegroundApp(func, test, onComplete) {
var intervalId,
flag,
checkForeground = function () {
flag = test();
};
runs(function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need this runs() as you aren't waiting for anything. I don't think there's much point to pass in func at all. Just run that code inline before you start the check.

func();
intervalId = setInterval(checkForeground, 500);
});
waitsFor(function () {
return flag;
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have a timeout threshold here

runs(function () {
clearInterval(intervalId);
onComplete();
});
}

it("opens and cancels calendarPicker", function () {
blackberry.invoke.card.invokeCalendarPicker({}, onDone, onCancel, invokeCallback);
waits(waitTimeout);
runs(function () {
internal.automation.touchTopLeft();
waits(waitTimeout);
runs(function () {
var intervalId;
testForegroundApp(function () {
blackberry.invoke.card.invokeCalendarPicker({}, onDone, onCancel, invokeCallback);
}, function () {
return (internal.automation.getForegroundAppInfo()["label-card0"] === "calendar.viewer.nav");
}, function () {
testForegroundApp(function () {
intervalId = setInterval(internal.automation.touchTopLeft, 500);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this running in a loop? Shouldn't we only be clicking cancel once?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The card is in the foreground before the button is clickable, so even though we are sure the card is in the foreground we cannot click anything until all of the ui for the card is active.

This keeps touching the button location until the card is ready.

}, function () {
var appInfo = internal.automation.getForegroundAppInfo();
return !(appInfo.hasOwnProperty("label-card0"));
}, function () {
clearInterval(intervalId);
expect(onCancel).toHaveBeenCalledWith('cancel');
});
});
});

it("opens and cancels calendarComposer", function () {
blackberry.invoke.card.invokeCalendarComposer({}, onDone, onCancel, invokeCallback);
waits(waitTimeout);
runs(function () {
internal.automation.touchTopLeft();
waits(waitTimeout);
runs(function () {
testForegroundApp(function () {
blackberry.invoke.card.invokeCalendarComposer({}, onDone, onCancel, invokeCallback);
}, function () {
return (internal.automation.getForegroundAppInfo()["label-card0"] === "calendar.eventcreate");
}, function () {
testForegroundApp(function () {
internal.automation.touchTopLeft();
}, function () {
var appInfo = internal.automation.getForegroundAppInfo();
return !(appInfo.hasOwnProperty("label-card0"));
}, function () {
expect(onDone).toHaveBeenCalled();
});
});
Expand Down