NetsBlox / Snap--Build-Your-Own-Blocks

a visual programming language inspired by Scratch
http://snap.berkeley.edu
GNU Affero General Public License v3.0
3 stars 6 forks source link

on action done snapDriver dragAndDrop #730

Closed hamidzr closed 4 years ago

hamidzr commented 6 years ago

can you think of a way of coming up with a generic check to see if dragAndDrop is finished or not ? although this action seems synchronous one cannot simply chain it in a test case (use of sleep or an expect is required. For example if we are using drag and drop to attach blocks together we can use prevBlock.next() to check. Maybe just check the grab the block under the final position to see if it is the intended block?

hamidzr commented 6 years ago

if there is no good solution we can tack a short sleep at the end and come up with more specific sub-methods with their own checks

brollb commented 6 years ago

So drag and drop is synchronous but I think the issue is that the SnapActions are not synchronous so when a drag and drop happens which connects a couple blocks, the actual connection of the block is performed async. The ideal approach, imo, would be to get a reference to the action's promise bc then we could actual tell when it is resolved

brollb commented 6 years ago

It is worth mentioning that this may not be trivial given the dragAndDrop method uses only morphic APIs which know nothing about promises.

brollb commented 5 years ago

Just to clarify for anyone else checking out this issue (I am looking at it again for the first time in a bit).

The issue is that we would like to write a test which is simulating user interactions - not operating on the underlying actions. Specifically, we would like to drag and drop a block onto the workspace. Although drag and drop is synchronous in morphic, it results in an action being asynchronously applied to the netsblox project. This makes it tricky to test the effects of the drag and drop as they are applied async (and there is no reference to the promise returned by SnapActions). This might motivate adding a return value to HandMorph.prototype.drop so we could actually return a reference to the promise (and we could actually detect when the async action is complete).

As of right now, the best way is to simply use driver.expect or driver.sleep.

Note - If you only care about editing the project (and not necessarily simulating the user actions), then there are some easy alternatives which return promises and can be chained (or can use await) to ensure that the async action has completed. These include driver.addBlock(<spec>, <point>), SnapActions.moveBlock(<block>, <target>), and SnapActions.setBlockPosition(<block>, <point>).

brollb commented 4 years ago

Another approach is to wait for the queued local actions to be settled in SnapActions: https://github.com/NetsBlox/Snap--Build-Your-Own-Blocks/pull/890/files