View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.demo.uif.library.elements;
17  
18  import java.io.File;
19  import java.util.List;
20  import org.junit.Test;
21  import org.kuali.rice.testtools.selenium.WebDriverFileResourceAftBase;
22  import org.openqa.selenium.By;
23  
24  /**
25   * @author Kuali Rice Team (rice.collab@kuali.org)
26   */
27  public class LibraryElementMultiFileUploadAft extends WebDriverFileResourceAftBase {
28  
29      /**
30       * /kr-krad/kradsampleapp?viewId=Demo-MultiFileUploadView
31       */
32      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-MultiFileUploadView";
33      
34      // values set by default for repeatable testing; left as configurable for load tests
35      protected List<File> fileUploadList;
36      
37      @Override
38      protected String getBookmarkUrl() {
39          return BOOKMARK_URL;
40      }
41  
42      @Override
43      protected void navigate() throws Exception {
44      	waitAndClickLibraryLink();
45          waitAndClickByLinkText("Elements");
46      	waitAndClickByLinkText("Multi-file Upload");
47      }
48  
49      protected void testElementMultiFileUpload() throws Exception {
50      	fileUploadSetUpforText();
51      	fileIngesterByName("files");
52          assertLinked();
53          assertDelete();
54  
55      	selectByName("exampleShown", "Max Size Multi-file Upload");
56          fileUploadSetUpforPdf();
57          fileIngesterByName("files1");
58          waitForElementVisibleBy(By.linkText("test.pdf"));
59          assertTrue(isTextPresent("9.2 KB")); // file size
60          clickFirstTrashIcon();
61          waitForElementNotPresent(By.linkText("test.pdf"));
62  
63      	selectByName("exampleShown", "Extra Fields Multi-file Upload");
64          fileUploadSetUpforText();
65          fileIngesterByName("files2");
66          assertLinked();
67          isElementPresentByName("files2[0].detail1"); // detail 1 extra field
68          isElementPresentByName("files2[0].detail2"); // detail 2 extra field
69          assertDelete();
70  
71          selectByName("exampleShown", "File Types Multi-file Upload");
72      	fileUploadSetUpforJpg();
73          fileIngesterByName("files3");
74          waitForElementVisibleBy(By.linkText("home.jpg"));
75          clickFirstTrashIcon();
76          waitForElementNotPresent(By.linkText("home.jpg"));
77      }
78  
79      private void assertLinked() throws InterruptedException {
80          waitForElementVisibleBy(By.linkText("test.txt"));
81          waitForElementVisibleBy(By.linkText("test1.txt"));
82      }
83  
84      private void assertDelete() throws InterruptedException {
85          clickFirstTrashIcon();
86          waitForElementNotPresent(By.linkText("test.txt"));
87  
88          clickFirstTrashIcon();
89          waitForElementNotPresent(By.linkText("test1.txt"));
90      }
91  
92      private void clickFirstTrashIcon() throws InterruptedException {
93          jGrowl("Click trash icon");
94          waitAndClickByXpath("//div[@id='Demo-MultiFileUploadView']//button[contains(@class,'icon-trash')]");
95          waitAndClickConfirmDeleteYes();
96      }
97  
98      private void fileUploadSetUpforText() throws Exception {
99      	setUpResourceDir("general", "txt");
100     }
101     
102     private void fileUploadSetUpforJpg() throws Exception {
103     	setUpResourceDir("general", "jpg");
104     }
105 
106     private void fileUploadSetUpforPdf() throws Exception {
107         setUpResourceDir("general", "pdf");
108     }
109 
110     @Test
111     public void testElementMultiFileUploadBookmark() throws Exception {
112     	testElementMultiFileUpload();
113         passed();
114     }
115 
116     @Test
117     public void testElementMultiFileUploadNav() throws Exception {
118     	testElementMultiFileUpload();
119         passed();
120     }
121 }