Commits

Richard Stephens  committed 7c1fadd

AUI-1403: add integration test to verify that selector is being used as expected

  • Participants
  • Parent commits 46499d6

Comments (0)

Files changed (3)

File atlassian-aui-pageobjects/src/main/java/com/atlassian/pageobjects/aui/component/restfultable/EditRow.java

         return errors;
     }
 
+    public PageElement getPageElement()
+    {
+        return row;
+    }
+
     public PageElement getSubmitButton()
     {
         return row.find(By.cssSelector(".aui-button[type=submit]"));

File auiplugin-tests/src/main/resources/restfultable/restfultable-example.js

         }
     });
 
+    var CheckboxEditView = AJS.RestfulTable.CustomEditView.extend({
+        render: function (self) {
+            console.log(self);
+            var $select = $("<input type='checkbox' class='ajs-restfultable-input-" + self.name + "' />" +
+                "<input type='hidden' name='" + self.name + "'/>");
+            return $select;
+        }
+    });
+
+    var DummyReadView = AJS.RestfulTable.CustomReadView.extend({
+        render: function (self) {
+            return $("<strong />").text("Blah");
+        }
+    });
+
     // DOM ready
     $(function () {
 
             columns: [
                 {id: "name", header: "Name", readView: NameReadView}, // id is the mapping of the rest property to render
                 {id: "group", header: "Group", editView: EditGroupView}, // header is the text in the <th>
-                {id: "number", header: "Number"}
+                {id: "number", header: "Number"},
+                {id: "checkbox", header: "Checkbox", readView: DummyReadView, editView: CheckboxEditView}
             ],
             resources: {
                 all: url, // resource to get all contacts
                 self: url // resource to get single contact url/{id}
             },
             noEntriesMsg: "You have no contacts. Loner!", // message to be displayed when table is empty
-            allowReorder: true // drag and drop reordering
+            allowReorder: true, // drag and drop reordering
+            fieldFocusSelector: function(name) {
+                return ":input[type!=hidden][name=" + name + "], #" + name + ", .ajs-restfultable-input-" + name;
+            }
         });
 
         // duplicate of the first table but with the addPosition: "bottom" option applied.
             columns: [
                 {id: "name", header: "Name", readView: NameReadView}, // id is the mapping of the rest property to render
                 {id: "group", header: "Group", editView: EditGroupView}, // header is the text in the <th>
-                {id: "number", header: "Number"}
+                {id: "number", header: "Number"},
+                {id: "checkbox", header: "Checkbox", readView: DummyReadView, editView: CheckboxEditView}
             ],
             resources: {
                 all: url, // resource to get all contacts
             },
             noEntriesMsg: "You have no contacts. Loner!", // message to be displayed when table is empty
             allowReorder: true, // drag and drop reordering
+            fieldFocusSelector: function(name) {
+                return ":input[type!=hidden][name=" + name + "], #" + name + ", .ajs-restfultable-input-" + name;
+            },
             addPosition: "bottom"
         });
     });

File auiplugin-tests/src/test/java/it/com/atlassian/aui/javascript/integrationTests/experimental/AUIRestfultableTest.java

 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.openqa.selenium.By;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
     }
 
     @Test
+    public void testCustomFocusSelector()
+    {
+        RestfulTable table = restfulTablePage.getTable();
+        table.addEntry("name", "Scott", "group", "Work", "number", "0412947430");
+        Row firstRow = table.getFirstRow();
+        EditRow row = firstRow.edit("checkbox");
+        String javascript = "return AJS.$(arguments[0]).is(':focus');";
+        Boolean hasFocus = row.getPageElement().find(By.className("ajs-restfultable-input-checkbox")).javascript().execute(javascript, Boolean.class).by(1000);
+        assertTrue(hasFocus.booleanValue());
+    }
+
+    @Test
     public void testValidationErrorEditingEntry()
     {
         RestfulTable table = restfulTablePage.getTable();