001/*
002 * Copyright 2005-2013 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 */
016package edu.samplu.krad.configview;
017
018import com.thoughtworks.selenium.SeleneseTestBase;
019import edu.samplu.common.SmokeTestBase;
020import org.junit.Test;
021import org.openqa.selenium.By;
022
023/**
024 * @author Kuali Rice Team (rice.collab@kuali.org)
025 */
026public class CollectionsSmokeTest extends SmokeTestBase {
027
028    /**
029     * /kr-krad/uicomponents?viewId=ConfigurationTestView-Collections&methodToCall=start
030     */
031    public static final String BOOKMARK_URL = "/kr-krad/uicomponents?viewId=ConfigurationTestView-Collections&methodToCall=start";
032
033    /**
034     * (//a[contains(text(),'Collections Configuration Test View')])[2]
035     */
036    public static final String TEXT_COLLECTIONS_CONFIGURATION_TEST_VIEW_XPATH =
037            "(//a[contains(text(),'Collections Configuration Test View')])[2]";
038
039    /**
040     * Kuali :: Collection Test View
041     */
042    public static final String KUALI_COLLECTION_WINDOW_TITLE = "Kuali :: Collection Test View";
043
044    @Override
045    protected String getBookmarkUrl() {
046        return BOOKMARK_URL;
047    }
048
049    protected void navigate() throws Exception {
050        waitAndClickKRAD();
051        waitAndClickByXpath(TEXT_COLLECTIONS_CONFIGURATION_TEST_VIEW_XPATH);
052        switchToWindow(KUALI_COLLECTION_WINDOW_TITLE);
053    }
054
055    protected void testCollections() throws Exception {
056        testActionColumnPlacement();
057        testAddViaLightbox();
058        testColumnSequence();
059        testSequencerow();
060        passed();
061    }
062
063    @Test
064    public void testCollectionsBookmark() throws Exception {
065        testCollections();
066    }
067
068    @Test
069    public void testCollectionsNav() throws Exception {
070        testCollections();
071    }
072
073    @Test
074    public void testAddDeleteBookmark() throws Exception {
075        testAddRowOfText();
076        testAddBlankLine();
077        passed();
078    }
079
080    @Test
081    public void testAddDeleteNav() throws Exception {
082        testAddRowOfText();
083        testAddBlankLine();
084        passed();
085    }
086
087    @Test
088    public void testSumBookmark() throws Exception {
089        testSum();
090        passed();
091    }
092
093    @Test
094    public void testSumNav() throws Exception {
095        testSum();
096        passed();
097    }
098
099    protected void testAddRowOfText() throws Exception {
100        assertTableLayout();
101        waitAndTypeByName("newCollectionLines['list1'].field1", "asdf1");
102        waitAndTypeByName("newCollectionLines['list1'].field2", "asdf2");
103        waitAndTypeByName("newCollectionLines['list1'].field3", "asdf3");
104        waitAndTypeByName("newCollectionLines['list1'].field4", "asdf4");
105        waitAndClickByXpath("//button[contains(.,'add')]"); // the first button is the one we want
106
107        for (int second = 0;; second++) {
108            if (second >= waitSeconds)
109                failableFail(TIMEOUT_MESSAGE);
110            try {
111                if (waitAndGetAttributeByName("newCollectionLines['list1'].field1", "value").equals(""))
112                    break;
113            } catch (Exception e) {}
114            Thread.sleep(1000);
115        }
116
117        SeleneseTestBase.assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field1", "value"));
118        SeleneseTestBase.assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field2", "value"));
119        SeleneseTestBase.assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field3", "value"));
120        SeleneseTestBase.assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field4", "value"));
121        SeleneseTestBase.assertEquals("asdf1", waitAndGetAttributeByName("list1[0].field1", "value"));
122        SeleneseTestBase.assertEquals("asdf2", waitAndGetAttributeByName("list1[0].field2", "value"));
123        SeleneseTestBase.assertEquals("asdf3", waitAndGetAttributeByName("list1[0].field3", "value"));
124        SeleneseTestBase.assertEquals("asdf4", waitAndGetAttributeByName("list1[0].field4", "value"));
125        SeleneseTestBase.assertTrue(isElementPresentByXpath("//div[@id='Collections-Base-TableLayout_disclosureContent']/div/table/tbody/tr[2]/td[6]/div/fieldset/div/div[@class='uif-boxLayout uif-horizontalBoxLayout clearfix']/button"));
126    }
127    /**
128     * Test adding a column of values to the Add Blank Line Tests Table Layout
129     */
130    protected void testAddBlankLine() throws Exception {
131        waitAndClickByLinkText("Add Blank Line");
132        waitAndClickById("Collections-AddBlankLine-TableTop_del_line0"); // the line withe asdf1, etc.
133        Thread.sleep(3000); //  TODO a wait until the loading.gif isn't visible would be better
134        waitAndClickByXpath("//button[contains(.,'Add Line')]");
135        Thread.sleep(3000); //  TODO a wait until the loading.gif isn't visible would be better
136        assertElementPresentByName("list1[0].field1");
137        assertTableLayout();
138        SeleneseTestBase.assertEquals("", waitAndGetAttributeByName("list1[0].field1", "value"));
139        SeleneseTestBase.assertEquals("", waitAndGetAttributeByName("list1[0].field2", "value"));
140        SeleneseTestBase.assertEquals("", waitAndGetAttributeByName("list1[0].field3", "value"));
141        SeleneseTestBase.assertEquals("", waitAndGetAttributeByName("list1[0].field4", "value"));
142    }
143
144    private void testSum() throws InterruptedException {
145        SeleneseTestBase.assertEquals("5", waitAndGetAttributeByName("list1[0].field1", "value"));
146        SeleneseTestBase.assertEquals("6", waitAndGetAttributeByName("list1[0].field2", "value"));
147        SeleneseTestBase.assertEquals("7", waitAndGetAttributeByName("list1[0].field3", "value"));
148        SeleneseTestBase.assertEquals("8", waitAndGetAttributeByName("list1[0].field4", "value"));
149        SeleneseTestBase.assertEquals("Total: 419", driver.findElement(By.xpath("//fieldset/div/div[2]/div[2]")).getText());
150        waitAndTypeByName("list1[0].field1", "1");
151        waitAndTypeByName("list1[0].field2", "1");
152        waitAndTypeByName("list1[0].field3", "1");
153        waitAndTypeByName("list1[0].field4", "1");
154        SeleneseTestBase.assertEquals("Total: 465", driver.findElement(By.xpath("//fieldset/div/div[2]/div[2]")).getText());
155    }
156
157    /**
158     * Test action column placement in table layout collections
159     */
160    protected void testActionColumnPlacement() throws Exception {
161        //Lack of proper locators its not possible to uniquely identify/locate this elements without use of ID's.
162        //This restricts us to use the XPath to locate elements from the dome.
163        //This test is prone to throw error in case of any changes in the dom Html graph.
164        waitAndClickByLinkText("Column Sequence");
165        Thread.sleep(2000);
166
167        //jiraAwareWaitAndClick("css=div.jGrowl-close");
168        // check if actions column RIGHT by default
169        //SeleneseTestBase.assertTrue(isElementPresent("//div[@id='ConfigurationTestView-collection1']//tr[2]/td[6]//button[contains(.,\"delete\")]"));
170        for (int second = 0;; second++) {
171            if (second >= waitSeconds)
172                failableFail(TIMEOUT_MESSAGE);
173            try {
174                if (isElementPresentByXpath("//tr[2]/td[6]/div/fieldset/div/div[2]/button"))
175                    break;
176            } catch (Exception e) {}
177            Thread.sleep(1000);
178        }
179        SeleneseTestBase.assertTrue(isElementPresentByXpath("//tr[2]/td[6]/div/fieldset/div/div[2]/button"));
180
181        // check if actions column is LEFT
182        //SeleneseTestBase.assertTrue(isElementPresent("//div[@id='ConfigurationTestView-collection2']//tr[2]/td[1]//button[contains(.,\"delete\")]"));
183        for (int second = 0;; second++) {
184            if (second >= waitSeconds)
185                failableFail(TIMEOUT_MESSAGE);
186            try {
187                if (isElementPresentByXpath("//div[2]/div[2]/div[2]/table/tbody/tr[2]/td/div/fieldset/div/div[2]/button"))
188                    break;
189            } catch (Exception e) {}
190            Thread.sleep(1000);
191        }
192        SeleneseTestBase.assertTrue(isElementPresentByXpath("//div[2]/div[2]/div[2]/table/tbody/tr[2]/td/div/fieldset/div/div[2]/button"));
193
194        // check if actions column is 3rd in a sub collection
195        //SeleneseTestBase.assertTrue(isElementPresent("//div[@id='ConfigurationTestView-subCollection2_line0']//tr[2]/td[3]//button[contains(.,\"delete\")]"));
196        for (int second = 0;; second++) {
197            if (second >= waitSeconds)
198                failableFail(TIMEOUT_MESSAGE);
199            try {
200                if (isElementPresentByXpath("//tr[2]/td[3]/div/fieldset/div/div[2]/button"))
201                    break;
202            } catch (Exception e) {}
203            Thread.sleep(1000);
204        }
205        SeleneseTestBase.assertTrue(isElementPresentByXpath("//tr[2]/td[3]/div/fieldset/div/div[2]/button"));
206    }
207
208    protected void testAddViaLightbox() throws Exception {
209        waitAndClickByLinkText("Add Via Lightbox");
210        SeleneseTestBase.assertEquals("Total: 419", driver.findElement(By.xpath("//fieldset/div/div[2]/div[2]")).getText());
211        waitAndClickByXpath("//button[contains(.,'Add Line')]");
212        Thread.sleep(3000);
213        waitAndTypeByXpath("//form/div/table/tbody/tr/td/div/input", "1");
214        waitAndTypeByXpath("//form/div/table/tbody/tr[2]/td/div/input", "1");
215        waitAndTypeByXpath("//form/div/table/tbody/tr[3]/td/div/input", "1");
216        waitAndTypeByXpath("//form/div/table/tbody/tr[4]/td/div/input", "1");
217        waitAndClickByXpath("//button[@id='Collections-AddViaLightbox-TableTop_add']");
218        Thread.sleep(3000);
219        SeleneseTestBase.assertEquals("Total: 420", driver.findElement(By.xpath("//fieldset/div/div[2]/div[2]")).getText());
220    }
221
222    protected void testColumnSequence() throws Exception {
223        waitAndClickByLinkText("Column Sequence");
224        Thread.sleep(3000);
225        waitAndTypeByName("newCollectionLines['list1'].field1", "1");
226        waitAndTypeByName("newCollectionLines['list1'].field2", "1");
227        waitAndTypeByName("newCollectionLines['list1'].field3", "1");
228        waitAndTypeByName("newCollectionLines['list1'].field4", "1");
229        waitAndClick(By.id("Collections-ColumnSequence-TableDefault_add"));
230        Thread.sleep(3000);
231
232        //Check if row has been added really or not
233        testIfRowHasBeenAdded();
234
235        //Check for the added if delete is present or not
236        SeleneseTestBase.assertTrue(isElementPresentByXpath("//div[@id='Collections-ColumnSequence-TableDefault_disclosureContent']/div[@class='dataTables_wrapper']/table/tbody/tr[2]/td[6]/div/fieldset/div/div[@class='uif-boxLayout uif-horizontalBoxLayout clearfix']/button"));
237    }
238
239    protected void testSequencerow() throws Exception {
240        waitAndClickByLinkText("Save Row");
241        Thread.sleep(3000);
242        waitAndTypeByName("newCollectionLines['list1'].field1", "1");
243        waitAndTypeByName("newCollectionLines['list1'].field2", "1");
244        waitAndTypeByName("newCollectionLines['list1'].field3", "1");
245        waitAndTypeByName("newCollectionLines['list1'].field4", "1");
246        waitAndClickByXpath("//button[contains(.,'add')]");
247        Thread.sleep(3000);
248
249        //Check if row has been added really or not
250        testIfRowHasBeenAdded();
251
252        //Check for the added if delete is present or not
253        SeleneseTestBase.assertTrue(isElementPresentByXpath("//div[@id='Collections-SaveRow-Table_disclosureContent']/div[@class='dataTables_wrapper']/table/tbody/tr[2]/td[6]/div/fieldset/div/div[@class='uif-boxLayout uif-horizontalBoxLayout clearfix']/button"));
254        //        SeleneseTestBase.assertTrue(isElementPresentByXpath("//div[@id='Collections-SaveRow-Table_disclosureContent']/div[@class='dataTables_wrapper']/table/tbody/tr[2]/td[6]/div/fieldset/div/div[@class='uif-boxLayout uif-horizontalBoxLayout clearfix']/button[@class='uif-action uif-secondaryActionButton uif-smallActionButton uif-saveLineAction']"));
255    }
256
257    protected void testIfRowHasBeenAdded() throws Exception {
258        //Check if row has been added really or not
259        SeleneseTestBase.assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field1", "value"));
260        SeleneseTestBase.assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field2", "value"));
261        SeleneseTestBase.assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field3", "value"));
262        SeleneseTestBase.assertEquals("", waitAndGetAttributeByName("newCollectionLines['list1'].field4", "value"));
263        SeleneseTestBase.assertEquals("1", waitAndGetAttributeByName("list1[0].field1", "value"));
264        SeleneseTestBase.assertEquals("1", waitAndGetAttributeByName("list1[0].field2", "value"));
265        SeleneseTestBase.assertEquals("1", waitAndGetAttributeByName("list1[0].field3", "value"));
266        SeleneseTestBase.assertEquals("1", waitAndGetAttributeByName("list1[0].field4", "value"));
267    }
268}