"use strict";

var env = require('../../../../helpers/env')
  , setup = require("../../../common/setup-base")
  , desired = require("../desired")
  , wd = require("wd")
  , droidText = 'android.widget.TextView'
  , TouchAction = wd.TouchAction
  , _ = require('underscore');


describe("apidemo - touch - tap", function () {
  var driver;
  setup(this, _.defaults({
    appActivity: '.text.LogTextBox1'
  }, desired)).then(function (d) { driver = d; });

  if (env.FAST_TESTS) {
    beforeEach(function () {
      return driver.resetApp();
    });
  }

  describe('tap visible element', function () {
    it('should tap an element', function (done) {
      driver
        .elementByName("Add")
        .then(function (el) {
          var action = new TouchAction(driver);
          return action.tap({el: el }).perform();
        })
        .elementsByClassName(droidText)
        .then(function (els) {
          return els[1];
        })
        .text()
        .should.become("This is a test\n")
        .nodeify(done);
    });

    it('should tap an element from an offset', function (done) {
      driver
        .elementByName("Add")
        .then(function (el) {
          var action = new TouchAction(driver);
          return action.tap({el: el, x: 1, y: 1 }).perform();
        })
        .elementsByClassName(droidText)
        .then(function (els) {
          return els[1];
        })
        .text()
        .should.become("This is a test\n")
        .nodeify(done);
    });

    it('should tap an element twice', function (done) {
      driver
        .elementByName("Add")
        .then(function (el) {
          var action = new TouchAction(driver);
          return action.tap({el: el, count: 2 }).perform();
        })
        .elementsByClassName(droidText)
        .then(function (els) {
          return els[1];
        })
        .text()
        .should.become("This is a test\nThis is a test\n")
        .nodeify(done);
    });

    it('should tap an element from an offset twice', function (done) {
      driver
        .elementByName("Add")
        .then(function (el) {
          var action = new TouchAction(driver);
          return action.tap({el: el, x:1, y: 1, count: 2 }).perform();
        })
        .sleep(2000)
        .elementsByClassName(droidText)
        .then(function (els) {
          return els[1];
        })
        .text()
        .should.become("This is a test\nThis is a test\n")
        .nodeify(done);
    });
  });
});

@@ -1475,32 +1475,564 @@
 done);%0A    %7D);%0A%0A
+    it('should tap from an absolute position', function (done) %7B%0A      driver%0A        .elementByName(%22Add%22)%0A        .getLocation()%0A        .then(function (loc) %7B%0A          var x = loc.x + 10%0A            , y = loc.y + 10;%0A          var action = new TouchAction(driver);%0A          return action.tap(%7Bx: x, y: y%7D).perform();%0A        %7D)%0A        .elementsByClassName(droidText)%0A        .then(function (els) %7B%0A          return els%5B1%5D;%0A        %7D)%0A        .text()%0A        .should.become(%22This is a test%5Cn%22)%0A        .nodeify(done);%0A    %7D);%0A%0A
     it('should t

Add test for tapping an absolute position