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.travel.account;
17  
18  import org.junit.Ignore;
19  import org.kuali.rice.krad.demo.ViewDemoAftBase;
20  import org.junit.Test;
21  import org.kuali.rice.testtools.selenium.WebDriverUtils;
22  import org.openqa.selenium.By;
23  import org.openqa.selenium.WebElement;
24  
25  /**
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class DemoTravelAccountLookUpAft extends ViewDemoAftBase {
29  
30      /**
31       * /kr-krad/lookup?methodToCall=start&dataObjectClassName=org.kuali.rice.krad.demo.travel.dataobject.TravelAccount&hideReturnLink=true&showMaintenanceLinks=true
32       */
33      public static final String BOOKMARK_URL = "/kr-krad/lookup?methodToCall=start&dataObjectClassName=org.kuali.rice.krad.demo.travel.dataobject.TravelAccount&hideReturnLink=true&showMaintenanceLinks=true";
34      
35      /**
36       * Search
37       */
38      public static final String SEARCH = "Search";
39      
40      /**
41       * Clear Values
42       */
43      public static final String CLEAR_VALUES = "Clear Values";
44  
45      /**
46       * Travel account number field
47       */
48      public static final String TRAVEL_ACCOUNT_NUMBER_FIELD = "lookupCriteria[number]";
49  
50      /**
51       * Travel account name field
52       */
53      public static final String TRAVEL_ACCOUNT_NAME_FIELD = "lookupCriteria[name]";
54  
55      @Override
56      public String getBookmarkUrl() {
57          return BOOKMARK_URL;
58      }
59  
60      @Override
61      protected void navigate() throws Exception {
62          waitAndClickDemoLink();
63          waitAndClickByLinkText("Travel Account Lookup");
64      }
65  
66      protected void testTravelAccountLookUp() throws Exception {
67      	//Search by Travel Account Number
68          waitAndTypeByName(TRAVEL_ACCOUNT_NUMBER_FIELD, "a1");
69          waitAndClickButtonByText(SEARCH);
70          waitForElementPresentByXpath("//a[contains(text(), 'a1')]");
71          waitAndClickButtonByText(CLEAR_VALUES);
72  
73          //Inquiry check on Travel Account Number
74          waitAndTypeByName(TRAVEL_ACCOUNT_NUMBER_FIELD, "a1");
75          waitAndClickByXpath("//button[@title='Direct Inquiry']");
76          gotoLightBox();
77          waitForElementPresentByXpath("//a[contains(text(),'a1')]");
78          waitForTextPresent("Travel Account 1");
79          waitAndClickButtonByText("Close");
80          selectTopFrame();
81  
82          //Search by Travel Account Name
83          waitAndTypeByName("lookupCriteria[name]","Travel Account 1");
84          waitAndClickButtonByText(SEARCH);
85          waitForElementPresentByXpath("//a[contains(text(),'a1')]");
86          waitForTextPresent("Travel Account 1");
87          waitAndClickButtonByText(CLEAR_VALUES);
88  
89          //Search by Travel Account Type Code
90          testSearchAndSelect("CAT");
91          waitAndClickButtonByText(SEARCH);
92          waitForTextPresent("CAT - Clearing");
93          waitAndClickButtonByText(CLEAR_VALUES);
94          testSearchAndSelect("EAT");
95          waitAndClickButtonByText(SEARCH);
96          waitForTextPresent("EAT - Expense");
97          waitAndClickButtonByText(CLEAR_VALUES);
98          testSearchAndSelect("IAT");
99          waitAndClickButtonByText(SEARCH);
100         waitForProgressLoading();
101         waitForTextPresent("IAT - Income");
102         waitAndClickButtonByText(CLEAR_VALUES);
103         
104         //LookUp on Travel Account Type Code
105         waitAndClickByXpath("//input[@name='lookupCriteria[accountTypeCode]' and @value='CAT']");
106         waitAndClickByXpath("//button[@class='btn btn-default uif-action icon-search']");
107         gotoLightBox();
108         waitForElementPresentByXpath("//input[@name='lookupCriteria[accountTypeCode]' and @value='CAT']");
109         waitAndClickButtonByText("Close");
110         selectTopFrame();
111         waitAndClickButtonByText(CLEAR_VALUES);
112 
113         //Search by Travel Account Date Created
114         waitAndTypeByName("lookupCriteria[createDate]", "06/01/2014");
115         waitAndClickButtonByText(SEARCH);
116         waitForElementPresentByXpath("//a[contains(text(),'a16')]");
117         waitForTextPresent("fran");
118         waitAndClickButtonByText(CLEAR_VALUES);
119         
120         //Search by Travel Account Fiscal Officer
121         waitAndTypeByName("lookupCriteria[fiscalOfficer.principalName]","fred");
122         waitAndClickButtonByText(SEARCH);
123         waitForElementPresentByXpath("//a[contains(text(),'a1')]");
124         waitForTextPresent("fred");
125         waitAndClickButtonByText(CLEAR_VALUES);
126         
127         //Search by Default (No filters)
128         waitAndClickButtonByText(SEARCH);
129         By[] bysPresent = new By[] {By.xpath("//a[contains(text(), 'a1')]"), By.xpath("//a[contains(text(), 'a2')]")};
130         assertElementsPresentInResultPages(bysPresent);
131     }
132 
133     protected void testTravelAccountLookUpXss(String fieldName) throws Exception {
134         waitAndTypeByName(fieldName,"\"/><script>alert('!')</script>");
135         waitAndClickButtonByText(SEARCH);
136         waitForProgressLoading();
137         
138         if(isAlertPresent())    {
139             jiraAwareFail(fieldName + " caused XSS.");
140         }
141         waitAndClickButtonByText(CLEAR_VALUES);
142         Thread.sleep(1000);
143     }
144 
145     public boolean isAlertPresent()
146     {
147         try {
148             driver.switchTo().alert();
149             return true;
150         }  catch (Exception Ex) {
151             return false;
152         } 
153     }
154 
155     private void testTravelAccountLookupCaseConstraint() throws Exception {
156         waitAndTypeByName(TRAVEL_ACCOUNT_NUMBER_FIELD, "a4");
157         waitAndClickButtonByText(SEARCH);
158         waitAndClickByLinkText("edit");
159         waitAndTypeLabeledInput("Description:", getDescriptionUnique());
160 
161         //save to check the binding is correctly applied subsequent times KULRICE-12638
162         waitAndClickButtonByText("Save");
163         waitForProgressSaving(WebDriverUtils.configuredImplicityWait() * 10);
164         waitForTextPresent("Document was successfully saved.");
165 
166         //remove the subsidized percent
167         jGrowl("Clear subsidized percent");
168         clearTextByName("document.newMaintainableObject.dataObject.subsidizedPercent");
169         waitAndClickButtonByText("Save");
170         waitForProgressSaving(WebDriverUtils.configuredImplicityWait() * 10);
171         waitForTextPresent("Subsidized Percent: Required");
172 
173         //re-add the subsidized percent and save
174         waitAndTypeByName("document.newMaintainableObject.dataObject.subsidizedPercent","45");
175         waitAndClickButtonByText("Save");
176         waitForProgressSaving(WebDriverUtils.configuredImplicityWait() * 10);
177         waitForTextPresent("Document was successfully saved.");
178 
179         //submit successfully
180         waitAndClickSubmitByText();
181         waitAndClickConfirmSubmitOk();
182         waitForProgressLoading(WebDriverUtils.configuredImplicityWait() * 10);
183         waitForTextPresent("Document was successfully submitted.");
184     }
185 
186     private void testTravelAccountLookUpDocumentLocking() throws Exception {
187         waitAndTypeByName(TRAVEL_ACCOUNT_NUMBER_FIELD, "a4");
188     	waitAndClickButtonByText(SEARCH);
189     	waitAndClickByLinkText("edit");
190     	waitAndTypeByName("document.documentHeader.documentDescription","Document Locking Description");
191         String documentId = getText(By.xpath("//div[@data-label='Document Number']"));
192 
193         waitAndClickByLinkText("Ad Hoc Recipients");
194 
195         waitAndClickAdHocGroupAddQuickFinder();
196         gotoLightBox();
197         waitAndClickButtonByText(SEARCH);
198         waitAndClickByLinkText("return value");
199         waitAndClickByXpath("//button[@id='CollectionGroup_AdHocWorkgroup_add']");
200 
201         waitAndClickAdHocPersonAddQuickFinder();
202     	gotoLightBox();
203     	waitAndClickButtonByText(SEARCH);
204     	waitAndClickByLinkText("return value");
205     	waitAndClickByXpath("//button[@id='Uif-AdHocPersonCollection_add']");
206 
207         waitAndClickSubmitByText();
208         waitAndClickConfirmSubmitOk();
209         waitForProgressLoading(WebDriverUtils.configuredImplicityWait() * 10);
210         checkForDocErrorKrad();
211 
212     	if(waitForIsTextPresent("Document was successfully submitted.")) {
213 
214             //get document number so that we can unlock after
215             WebElement webElement = findElement(By.xpath("./html/body/form/div/header/div/table/tbody/tr[1]/td[1]/div"));
216             documentId = webElement.getText();
217 
218     		navigate();
219             waitAndTypeByName(TRAVEL_ACCOUNT_NUMBER_FIELD, "a4");
220     		waitAndClickButtonByText(SEARCH);
221         	waitAndClickByLinkText("edit");
222         	waitAndTypeByName("document.documentHeader.documentDescription","Document Locking Description");
223 
224             waitAndClickSubmitByText();
225             waitAndClickConfirmSubmitOk();
226             waitForProgressLoading();
227             // there should be a doc error at this point
228         }
229 
230         waitForTextPresent("This document cannot be Saved or Routed");
231 
232         //unlock record
233         if(documentId != "") {
234             open(getBaseUrlString() + "/kew/DocHandler.do?docId=" + documentId + "&command=displayActionListView");
235             waitAndClickByXpath("/html/body/form/div/div[2]/main/section[7]/header/h3/a/span/span[1]");
236             waitAndTypeByXpath("/html/body/form/div/div[2]/main/section[7]/div/div[1]/textarea", "blocking test");
237             waitAndClickByXpath("/html/body/form/div/div[2]/main/section[7]/div/div[2]/button[2]");
238         }
239     }
240 
241     @Test
242     public void testTravelAccountLookUpBookmark() throws Exception {
243         testTravelAccountLookUp();
244         testXss();
245         passed();
246     }
247 
248     private void testXss() throws Exception {
249         testTravelAccountLookUpXss(TRAVEL_ACCOUNT_NUMBER_FIELD);
250     }
251     
252     private void testSearchAndSelect(String selectorText) throws Exception {
253         jGrowl("Click Travel Account Type Code quickfinder");
254     	waitAndClickByXpath("//button[@class='btn btn-default uif-action icon-search']");
255     	gotoLightBox();
256         waitAndClickSearchByText();
257         
258     	if(selectorText.equalsIgnoreCase("CAT")){
259     		waitAndClickByXpath("//table/tbody/tr[1]/td/div/fieldset/div/a");
260     	}
261     	
262     	if(selectorText.equalsIgnoreCase("EAT")){
263     		waitAndClickByXpath("//table/tbody/tr[2]/td/div/fieldset/div/a");
264     	}
265     	
266     	if(selectorText.equalsIgnoreCase("IAT")){
267     		waitAndClickByXpath("//table/tbody/tr[3]/td/div/fieldset/div/a");
268     	}
269     }
270 
271         @Test
272         public void testTravelAccountLookUpNav() throws Exception {
273             testTravelAccountLookUp();
274             testXss();
275             passed();
276         }
277 
278         @Ignore("https://jira.kuali.org/browse/KULRICE-13357 AFT Failures Dialogs on CI")
279         @Test
280         public void testTravelAccountLookUpDocumentLockingBookmark() throws Exception {
281             testTravelAccountLookUpDocumentLocking();
282             passed();
283         }
284 
285         @Ignore("https://jira.kuali.org/browse/KULRICE-13357 AFT Failures Dialogs on CI")
286         @Test
287         public void testTravelAccountLookUpDocumentLockingNav() throws Exception {
288             testTravelAccountLookUpDocumentLocking();
289             passed();
290         }
291 
292         @Test
293         public void testTravelAccountLookupCaseConstraintBookmark() throws Exception {
294             testTravelAccountLookupCaseConstraint();
295             passed();
296         }
297 
298         @Test
299         public void testTravelAccountLookupCaseConstraintNav() throws Exception {
300             testTravelAccountLookupCaseConstraint();
301             passed();
302         }
303 }
304