001    package edu.samplu.krad.demo.uif.library;
002    
003    import org.junit.Test;
004    import org.openqa.selenium.By;
005    import org.openqa.selenium.WebElement;
006    
007    /**
008     * @author Kuali Rice Team (rice.collab@kuali.org)
009     */
010    public class DemoLibraryFieldsImageSmokeTest extends DemoLibraryBase {
011    
012        /**
013         * /kr-krad/kradsampleapp?viewId=Demo-ImageField-View&methodToCall=start
014         */
015        public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-ImageField-View&methodToCall=start";
016    
017        @Override
018        public String getBookmarkUrl() {
019            return BOOKMARK_URL;
020        }
021    
022        @Override
023        protected void navigate() throws Exception {
024            navigateToLibraryDemo("Fields", "Image Field");
025        }
026    
027        protected void testImageFieldDefault() throws Exception {
028            WebElement exampleDiv = navigateToExample("Demo-ImageField-Example1");
029            WebElement field = findElement(By.cssSelector("div[data-label='ImageField 1']"), exampleDiv);
030    
031            String fieldId = field.getAttribute("id");
032    
033            assertIsVisible("#" + fieldId);
034            assertIsVisible("label[data-label_for='" + fieldId + "']");
035            WebElement label = findElement(By.cssSelector("label[data-label_for='" + fieldId + "']"), field);
036            if (!label.getText().contains("ImageField 1:")) {
037                fail("Label text does not match");
038            }
039    
040            String imgId = label.getAttribute("for");
041    
042            assertIsVisible("#" + imgId + "[src='/krad/images/pdf.png']");
043            assertIsVisible("#" + imgId + "[alt='']");
044    
045            // validate that the image comes after the label
046            findElement(By.cssSelector("span[data-label_for='" + fieldId + "'] + img[src='/krad/images/pdf.png']"),
047                    exampleDiv);
048        }
049    
050        protected void testImageFieldAlternateText() throws Exception {
051            WebElement exampleDiv = navigateToExample("Demo-ImageField-Example2");
052            WebElement field = findElement(By.cssSelector("div[data-label='ImageField 1']"), exampleDiv);
053    
054            String fieldId = field.getAttribute("id");
055    
056            WebElement label = findElement(By.cssSelector("label[data-label_for='" + fieldId + "']"), field);
057    
058            String imgId = label.getAttribute("for");
059    
060            assertIsVisible("#" + imgId + "[src='/krad/images/pdf_ne.png']");
061            assertIsVisible("#" + imgId + "[alt='pdf']");
062        }
063    
064        protected void testImageFieldExamples() throws Exception {
065            testImageFieldDefault();
066            testImageFieldAlternateText();
067        }
068    
069        @Test
070        public void testImageFieldExamplesBookmark() throws Exception {
071            testImageFieldExamples();
072            passed();
073        }
074    
075        @Test
076        public void testImageFieldExamplesNav() throws Exception {
077            testImageFieldExamples();
078            passed();
079        }
080    
081        @Test
082        public void testImageFieldDefaultBookmark() throws Exception {
083            testImageFieldDefault();
084            passed();
085        }
086    
087        @Test
088        public void testImageFieldDefaultNav() throws Exception {
089            testImageFieldDefault();
090            passed();
091        }
092    
093        @Test
094        public void testImageFieldAlternateTextBookmark() throws Exception {
095            testImageFieldAlternateText();
096            passed();
097        }
098    
099        @Test
100        public void testImageFieldAlternateTextNav() throws Exception {
101            testImageFieldAlternateText();
102            passed();
103        }
104    }