View Javadoc
1   /**
2    * Copyright 2005-2014 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 edu.sampleu.main;
17  
18  import org.apache.commons.io.FileUtils;
19  import org.junit.Rule;
20  import org.junit.Test;
21  import org.junit.rules.TemporaryFolder;
22  import org.kuali.rice.krad.uif.UifPropertyPaths;
23  import org.kuali.rice.krad.util.KRADConstants;
24  import org.openqa.selenium.By;
25  
26  import java.io.File;
27  
28  /**
29   * Tests the Notes and Attachments in the People Flow screen.
30   *
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public class PeopleFlowCreateNewNotesAndAttachmentsAft extends PeopleFlowCreateNewAftBase {
34  
35      /**
36       * Provider of the temporary folder.
37       */
38      @Rule
39      public TemporaryFolder temporaryFolder = new TemporaryFolder();
40  
41      private static final String NOTES_AND_ATTACHMENTS_PREFIX = UifPropertyPaths.NEW_COLLECTION_LINES
42              + "['"
43              + KRADConstants.DOCUMENT_PROPERTY_NAME
44              + "."
45              + KRADConstants.NOTES_PROPERTY_NAME
46              + "']";
47  
48      @Override
49      public String getBookmarkUrl() {
50          return BOOKMARK_URL;
51      }
52  
53      /**
54       * Tests adding both the required note and an optional attachment.
55       *
56       * @throws Exception when an error is encountered in the test
57       */
58      @Test
59      public void testPeopleFlowCreateNewNotesAndAttachments_DefaultAttachmentNav() throws Exception {
60          navigateToPeopleFlowNotesAndAttachments();
61  
62          waitAndTypeByName(NOTES_AND_ATTACHMENTS_PREFIX + "." + KRADConstants.NOTE_TEXT_PROPERTY_NAME,
63                  "Attachment_Note");
64          waitAndAddAttachment("attachment.txt", "Testing123");
65          waitAndClick(By.cssSelector("button[title='Add a Note']"));
66  
67          Thread.sleep(2000);
68  
69          assertTextPresent("Attachment_Note");
70          assertTextPresent("attachment.txt");
71          assertTextNotPresent("Note Text is a required field.");
72      }
73  
74      /**
75       * Tests adding just the required note.
76       *
77       * @throws Exception when an error is encountered in the test
78       */
79      @Test
80      public void testPeopleFlowCreateNewNotesAndAttachments_DefaultNoAttachmentNav() throws Exception {
81          navigateToPeopleFlowNotesAndAttachments();
82  
83          waitAndTypeByName(NOTES_AND_ATTACHMENTS_PREFIX + "." + KRADConstants.NOTE_TEXT_PROPERTY_NAME,
84                  "Attachment_Note");
85          waitAndClick(By.cssSelector("button[title='Add a Note']"));
86  
87          Thread.sleep(2000);
88  
89          assertTextPresent("Attachment_Note");
90          assertTextNotPresent("Note Text is a required field");
91      }
92  
93      /**
94       * Tests adding just the optional attachment, which should result in an error.
95       *
96       * @throws Exception when an error is encountered in the test
97       */
98      @Test
99      public void testPeopleFlowCreateNewNotesAndAttachments_NoNoteTextNav() throws Exception {
100         navigateToPeopleFlowNotesAndAttachments();
101 
102         waitAndAddAttachment("attachment.txt", "Testing123");
103         waitAndClick(By.cssSelector("button[title='Add a Note']"));
104 
105         waitForTextPresent("Note Text is a required field");
106         assertTextNotPresent("attachment.txt");
107     }
108 
109     private void navigateToPeopleFlowNotesAndAttachments() throws Exception {
110         selectFrameIframePortlet();
111 
112         waitAndClickByLinkText("Create New");
113         waitForElementPresent(
114                 "div[data-header_for='PeopleFlow-MaintenanceView'] div[data-label='Document Number'] > span");
115 
116         waitAndClickByLinkText("Notes and Attachments (0)");
117     }
118 
119     private void waitAndAddAttachment(String fileName, String content) throws Exception {
120         File file = temporaryFolder.newFile(fileName);
121         FileUtils.writeStringToFile(file, content);
122         String path = file.getAbsolutePath().toString();
123         waitAndTypeByName("attachmentFile", path);
124     }
125 }