001    /**
002     * Copyright 2005-2014 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package edu.sampleu.main;
017    
018    import org.apache.commons.io.FileUtils;
019    import org.junit.Rule;
020    import org.junit.Test;
021    import org.junit.rules.TemporaryFolder;
022    import org.kuali.rice.krad.uif.UifPropertyPaths;
023    import org.kuali.rice.krad.util.KRADConstants;
024    import org.openqa.selenium.By;
025    
026    import java.io.File;
027    
028    /**
029     * Tests the Notes and Attachments in the People Flow screen.
030     *
031     * @author Kuali Rice Team (rice.collab@kuali.org)
032     */
033    public class PeopleFlowCreateNewNotesAndAttachmentsAft extends PeopleFlowCreateNewAftBase {
034    
035        /**
036         * Provider of the temporary folder.
037         */
038        @Rule
039        public TemporaryFolder temporaryFolder = new TemporaryFolder();
040    
041        private static final String NOTES_AND_ATTACHMENTS_PREFIX = UifPropertyPaths.NEW_COLLECTION_LINES
042                + "['"
043                + KRADConstants.DOCUMENT_PROPERTY_NAME
044                + "."
045                + KRADConstants.NOTES_PROPERTY_NAME
046                + "']";
047    
048        @Override
049        public String getBookmarkUrl() {
050            return BOOKMARK_URL;
051        }
052    
053        /**
054         * Tests adding both the required note and an optional attachment.
055         *
056         * @throws Exception when an error is encountered in the test
057         */
058        @Test
059        public void testPeopleFlowCreateNewNotesAndAttachments_DefaultAttachmentNav() throws Exception {
060            navigateToPeopleFlowNotesAndAttachments();
061    
062            waitAndTypeByName(NOTES_AND_ATTACHMENTS_PREFIX + "." + KRADConstants.NOTE_TEXT_PROPERTY_NAME,
063                    "Attachment_Note");
064            waitAndAddAttachment("attachment.txt", "Testing123");
065            waitAndClick(By.cssSelector("button[title='Add a Note']"));
066    
067            Thread.sleep(2000);
068    
069            waitForTextPresent("Attachment_Note");
070            assertTextPresent("attachment.txt");
071            assertTextNotPresent("Note Text is a required field.");
072            passed();
073        }
074    
075        /**
076         * Tests adding just the required note.
077         *
078         * @throws Exception when an error is encountered in the test
079         */
080        @Test
081        public void testPeopleFlowCreateNewNotesAndAttachments_DefaultNoAttachmentNav() throws Exception {
082            navigateToPeopleFlowNotesAndAttachments();
083    
084            waitAndTypeByName(NOTES_AND_ATTACHMENTS_PREFIX + "." + KRADConstants.NOTE_TEXT_PROPERTY_NAME,
085                    "Attachment_Note");
086            waitAndClick(By.cssSelector("button[title='Add a Note']"));
087    
088            waitForTextPresent("Attachment_Note");
089            assertTextNotPresent("Note Text is a required field");
090            passed();
091        }
092    
093        /**
094         * Tests adding just the optional attachment, which should result in an error.
095         *
096         * @throws Exception when an error is encountered in the test
097         */
098        @Test
099        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            Thread.sleep(2000);
106            waitForTextPresent("Note Text is a required field");
107            assertTextNotPresent("attachment.txt");
108            passed();
109        }
110    
111        private void navigateToPeopleFlowNotesAndAttachments() throws Exception {
112            selectFrameIframePortlet();
113    
114            waitAndClickByLinkText("Create New");
115            waitForElementPresent(
116                    "div[data-header_for='PeopleFlow-MaintenanceView'] div[data-label='Document Number'] > span");
117    
118            waitAndClickByLinkText("Notes and Attachments (0)");
119        }
120    
121        private void waitAndAddAttachment(String fileName, String content) throws Exception {
122            File file = temporaryFolder.newFile(fileName);
123            FileUtils.writeStringToFile(file, content);
124            String path = file.getAbsolutePath().toString();
125            waitAndTypeByName("attachmentFile", path);
126        }
127    }