'use strict';

/* https://github.com/angular/protractor/blob/master/docs/getting-started.md */

describe("Home page", function() {
  it("should be the default one", function() {
    browser.get('#/');
    expect(browser.getLocationAbsUrl()).toMatch('/home');
  });

  describe(", while clicking task Done button", function() {
    it("should remove given task", function() {
      browser.get('#/home');
      var firstTaskDescription;
      element.all(by.binding('task.description')).first().getText().then(function(text) {
        firstTaskDescription = text;
      })

      element.all(by.css('.btn.btn-primary.btn-xs')).first().click();

      element.all(by.binding('task.description')).first().getText().then(function(text) {
        expect(text).not.toBe(firstTaskDescription);
      })
    });
  });  

  describe(", while clicking Show completed button", function() {
    it("should show given done task", function() {
      browser.get('#/home');
      var firstTaskDescription;
      element.all(by.binding('task.description')).first().getText().then(function(text) {
        firstTaskDescription = text;
      })

      element.all(by.css('.btn.btn-primary.btn-xs')).first().click();
      element(by.css('.btn.btn-default.btn-xs')).click();

      element.all(by.binding('task.description')).last().getText().then(function(text) {
        expect(text).toBe(firstTaskDescription);
      })
    });

    it("should change its title", function() {
      browser.get('#/home');
      expect(element(by.css('.btn.btn-default.btn-xs')).getText()).toBe('View Completed tasks');
      element(by.css('.btn.btn-default.btn-xs')).click();
      expect(element(by.css('.btn.btn-default.btn-xs')).getText()).toBe('Hide Completed tasks');
    });
  });
});
@@ -576,67 +576,25 @@
     
-element.all(by.css('.btn.btn-primary.btn-xs')).first().clic
+clickFirstDoneTas
 k();
@@ -1089,126 +1089,54 @@
     
-element.all(by.css('.btn.btn-primary.btn-xs')).first().click();%0A      element(by.css('.btn.btn-default.btn-xs')).click
+clickFirstDoneTask();%0A      clickShowCompleted
 ();%0A
@@ -1475,56 +1475,26 @@
     
-element(by.css('.btn.btn-default.btn-xs')).click
+clickShowCompleted
 ();%0A
@@ -1598,17 +1598,219 @@
     %7D);%0A
-
   %7D);
+%0A%0A  function clickFirstDoneTask() %7B%0A    element.all(by.css('.btn.btn-primary.btn-xs')).first().click();%0A  %7D%0A%0A  function clickShowCompleted() %7B%0A    element(by.css('.btn.btn-default.btn-xs')).click();%0A  %7D
 %0A%7D);

refactor e2e scenarios