001/**
002 * Copyright 2005-2016 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.sampleu.main;
017
018import org.junit.Before;
019import org.junit.BeforeClass;
020import org.junit.Test;
021import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils;
022import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
023import org.kuali.rice.testtools.selenium.WebDriverUtils;
024import org.openqa.selenium.By;
025import static edu.sampleu.main.PeopleFlowCreateNewAftBase.PeopleFlowDocInfo;
026/**
027 * test that checks that rules can be added to agendas
028 *
029 * @author Kuali Rice Team (rice.collab@kuali.org)
030 */
031public class AgendaEditorAndOrToggleSyncAft extends WebDriverLegacyITBase {
032    public static final String PEOPLE_FLOW_LINK_TEXT = "People Flow";
033    public static final String BOOKMARK_URL =
034            AutomatedFunctionalTestUtils.PORTAL
035                    + "?channelTitle=Agenda%20Lookup&channelUrl="
036                    + WebDriverUtils.getBaseUrlString()
037                    + AutomatedFunctionalTestUtils.KRAD_LOOKUP_METHOD
038                    + "org.kuali.rice.krms.impl.repository.AgendaBo"
039                    + AutomatedFunctionalTestUtils.SHOW_MAINTENANCE_LINKS
040                    + "&returnLocation="
041                    + AutomatedFunctionalTestUtils.PORTAL_URL
042                    + AutomatedFunctionalTestUtils.HIDE_RETURN_LINK;
043
044    public static final String ID_TEXT = "T1001";
045
046    private String getPeopleFlowId() throws Exception {
047        selectParentWindow();
048        waitAndClickMainMenu();
049        waitAndClickByLinkText(PEOPLE_FLOW_LINK_TEXT);
050        waitForPageToLoad();
051
052        PeopleFlowDocInfo docInfo = peopleFlowCreateNew();
053        jGrowl("people flow id is created");
054
055        selectParentWindow();
056        waitAndClickMainMenu();
057        waitAndClickByLinkText(PEOPLE_FLOW_LINK_TEXT);
058        waitForPageToLoad();
059        jGrowl("ready to search people flow");
060
061        selectFrameIframePortlet();
062        selectByName("lookupCriteria[namespaceCode]", "KUALI - Kuali Systems");
063        waitClearAndType("lookupCriteria[name]", docInfo.getName());
064        waitAndClickByXpath("//button[contains(text(),'Search')]");
065        waitForTextPresent("edit");
066        jGrowl("search people flow search complete");
067
068        String id = getTextByXpath("(//span[contains(@id,'line0_control')])[1]");
069        assertTrue(id != null);
070        jGrowl("people flow id is " + id);
071
072        selectParentWindow();
073        waitAndClickMainMenu();
074        waitAndClickByLinkText(AGENDA_LOOKUP_LINK_TEXT);
075        waitForPageToLoad();
076
077        return id;
078    }
079
080    private PeopleFlowDocInfo peopleFlowCreateNew() throws Exception {
081        selectFrameIframePortlet();
082
083        waitAndClickByLinkText("Create New");
084        String peopleFlowNamespace = "KUALI - Kuali Systems";
085        String peopleFlowName = "Document Name" + AutomatedFunctionalTestUtils.createUniqueDtsPlusTwoRandomChars();
086
087        //Save docId
088        waitForElementPresentByXpath("//div[@data-label='Document Number']/span");
089        String docId = getTextByXpath("//div[@data-label='Document Number']/span");
090        assertTrue(docId != null);
091        jGrowlSticky("Doc Id is " + docId);
092
093        clearTextByName("document.documentHeader.documentDescription");
094        waitAndTypeByName("document.documentHeader.documentDescription", "Description for Document");
095        waitAndSelectByName("document.newMaintainableObject.dataObject.namespaceCode", peopleFlowNamespace);
096        clearTextByName("document.newMaintainableObject.dataObject.name");
097        waitAndTypeByName("document.newMaintainableObject.dataObject.name", peopleFlowName);
098
099        jGrowl("Add Member kr");
100        clearTextByName("newCollectionLines['document.newMaintainableObject.dataObject.members'].memberName");
101        waitAndTypeByName("newCollectionLines['document.newMaintainableObject.dataObject.members'].memberName", "kr");
102        findElement(By.name("newCollectionLines['document.newMaintainableObject.dataObject.members'].forceAction")).click();
103        waitAndClick(By.cssSelector("button[data-loadingmessage='Adding Line...']"));
104        Thread.sleep(3000);
105        checkForIncidentReport();
106
107        jGrowl("Add Member admin");
108        clearTextByName("newCollectionLines['document.newMaintainableObject.dataObject.members'].priority");
109        waitAndTypeByName("newCollectionLines['document.newMaintainableObject.dataObject.members'].priority", "2");
110        clearTextByName("newCollectionLines['document.newMaintainableObject.dataObject.members'].memberName");
111        waitAndTypeByName("newCollectionLines['document.newMaintainableObject.dataObject.members'].memberName", "admin");
112        waitAndClick(By.cssSelector("button[data-loadingmessage='Adding Line...']"));
113        Thread.sleep(3000);
114
115        waitAndClickButtonByExactText("Save");
116        waitForTextPresent("SAVED", WebDriverUtils.configuredImplicityWait() * 4);
117        waitForTextPresent(" Document was successfully saved.");
118
119        submit();
120
121        return new PeopleFlowDocInfo(docId, peopleFlowNamespace, peopleFlowName);
122    }
123
124    @Override
125    protected String getBookmarkUrl() {
126        return BOOKMARK_URL;
127    }
128
129    @Override
130    protected void navigate() throws Exception {
131        waitAndClickByLinkText(AGENDA_LOOKUP_LINK_TEXT);
132        waitForPageToLoad();
133    }
134
135    protected void testAgendaEditorAndOrToggleSync() throws Exception {
136        selectFrameIframePortlet();
137        waitClearAndType("lookupCriteria[name]", "SimpleAgendaCompoundProp");
138        waitAndClickByXpath("//button[contains(text(),'Search')]");
139        waitAndClickByXpath("//a[contains(text(),'edit')]");
140        selectFrameIframePortlet();
141        waitAndClickByXpath("//a/div[contains(text(),'CmpdTestRule: For testing compound props')]");
142        waitAndClickByXpath("//button[contains(text(),'Edit Rule')]");
143        selectFrameIframePortlet();
144        waitForTextPresent("( Campus Code = Muir AND Campus Code = Revelle AND Campus Code = Warren )");
145        selectByName("document.newMaintainableObject.dataObject.agendaItemLine.rule.propositionTree.rootElement.children[0].children[1].data.proposition.compoundOpCode","OR");
146        selectByName("document.newMaintainableObject.dataObject.agendaItemLine.rule.propositionTree.rootElement.children[0].children[3].data.proposition.compoundOpCode","OR");
147        waitForTextNotPresent("( Campus Code = Muir AND Campus Code = Revelle AND Campus Code = Warren )");
148        waitForTextPresent("( Campus Code = Muir OR Campus Code = Revelle OR Campus Code = Warren )");
149    }
150
151    protected void testAgendaEditorEditRuleAddActionsBlank() throws Exception {
152        //Save & Submit
153        testFillRequiredDetails("", null);
154        save();
155        submit();
156
157        //Blanket Approve
158        selectParentWindow();
159        waitAndClickMainMenu();
160        navigate();
161        testFillRequiredDetails("",null);
162        waitForTextPresent("INITIATED");
163        waitAndClickButtonByExactText("Blanket Approve");
164        waitAndClickConfirmBlanketApproveOk();
165    }
166
167    protected void save() throws InterruptedException {
168        waitForTextPresent("INITIATED");
169        waitAndClickButtonByExactText("Save");
170        waitForProgressSaving();
171        waitForTextPresent("SAVED");
172        waitForTextPresent(" Document was successfully saved.");
173    }
174
175    protected void testAgendaEditorEditRuleAddActionsKrmsActionResolverType() throws Exception {
176        //Save & Submit
177        selectParentWindow();
178        waitAndClickMainMenu();
179        navigate();
180        testFillRequiredDetails("KrmsActionResolverType", null);
181        save();
182        submit();
183
184        //Blanket Approve
185        selectParentWindow();
186        waitAndClickMainMenu();
187        navigate();
188        testFillRequiredDetails("KrmsActionResolverType",null);
189        waitForTextPresent("INITIATED");
190        waitAndClickButtonByExactText("Blanket Approve");
191        waitAndClickConfirmBlanketApproveOk();
192    }
193
194    protected void submit() throws InterruptedException {
195        waitAndClickButtonByExactText("Submit");
196        waitAndClickConfirmSubmitOk();
197        waitForTextPresent("ENROUTE");
198        waitForTextPresent("Document was successfully submitted.");
199    }
200
201    protected void testAgendaEditorEditRuleAddActionsNotifyPeopleFlow(String peopleFlowId) throws Exception {
202        //Save & Submit
203        selectParentWindow();
204        waitAndClickMainMenu();
205        navigate();
206        testFillRequiredDetails("Notify PeopleFlow", peopleFlowId);
207        save();
208        submit();
209
210        //Blanket Approve
211        selectParentWindow();
212        waitAndClickMainMenu();
213        navigate();
214        testFillRequiredDetails("Notify PeopleFlow",peopleFlowId);
215        waitForTextPresent("INITIATED");
216        waitAndClickButtonByExactText("Blanket Approve");
217        waitAndClickConfirmBlanketApproveOk();
218    }
219
220    protected void testAgendaEditorEditRuleAddActionsRouteToPeopleFlow(String peopleFlowId) throws Exception {
221        //Save & Submit
222        selectParentWindow();
223        waitAndClickMainMenu();
224        navigate();
225        testFillRequiredDetails("Route to PeopleFlow", peopleFlowId);
226        save();
227        submit();
228
229        //Blanket Approve
230        selectParentWindow();
231        waitAndClickMainMenu();
232        navigate();
233        testFillRequiredDetails("Route to PeopleFlow",peopleFlowId);
234        waitForTextPresent("INITIATED");
235        waitAndClickButtonByExactText("Blanket Approve");
236        waitAndClickConfirmBlanketApproveOk();
237    }
238
239    protected void testAgendaEditorEditRuleAddActionsValidationAction() throws Exception {
240        //Save & Submit
241        selectParentWindow();
242        waitAndClickMainMenu();
243        navigate();
244        testFillRequiredDetails("Validation Action",null);
245        save();
246        submit();
247
248        //Blanket Approve
249        selectParentWindow();
250        waitAndClickMainMenu();
251        navigate();
252        testFillRequiredDetails("Validation Action",null);
253        waitForTextPresent("INITIATED");
254        waitAndClickButtonByExactText("Blanket Approve");
255        waitAndClickConfirmBlanketApproveOk();
256    }
257
258    private void testFillRequiredDetails(String selectValue,String peopleFlowId) throws Exception {
259        selectFrameIframePortlet();
260        waitClearAndType("lookupCriteria[id]", ID_TEXT);
261        waitAndClickByXpath("//button[contains(text(),'Search')]");
262        waitAndClickByXpath("//a[contains(text(),'edit')]");
263        selectFrameIframePortlet();
264        waitAndClickByXpath("//a[@class='agendaNode ruleNode']");
265        waitAndClickByXpath("//button[contains(text(),'Edit Rule')]");
266        selectFrameIframePortlet();
267        selectByName("document.newMaintainableObject.dataObject.agendaItemLineRuleAction.typeId", selectValue);
268
269        if (selectValue.equals("KrmsActionResolverType") || selectValue.equalsIgnoreCase("Validation Action")){
270            waitClearAndType("document.newMaintainableObject.dataObject.agendaItemLineRuleAction.name", "ActionName");
271        }
272
273        waitForElementPresentByXpath("document.newMaintainableObject.dataObject.customRuleActionAttributesMap[peopleFlowId]");
274
275        if(selectValue.equalsIgnoreCase("Notify PeopleFlow") || selectValue.equalsIgnoreCase("Route to PeopleFlow")){
276            waitClearAndType("document.newMaintainableObject.dataObject.customRuleActionAttributesMap[peopleFlowId]", peopleFlowId);
277            waitClearAndType("document.newMaintainableObject.dataObject.customRuleActionAttributesMap[peopleFlowName]", "Document Name1412916151718sz");
278            waitClearAndType("document.newMaintainableObject.dataObject.agendaItemLineRuleAction.name", "test");
279        }else if(selectValue.equalsIgnoreCase("Validation Action")) {
280            waitAndClickByName("document.newMaintainableObject.dataObject.customRuleActionAttributesMap[actionTypeCode]");
281            waitClearAndType("document.newMaintainableObject.dataObject.customRuleActionAttributesMap[actionMessage]","This is msg");
282        }
283        waitAndClickButtonByExactText("Update Rule");
284        acceptAlertIfPresent();
285    }
286
287    protected void waitClearAndType(String name, String value) throws Exception {
288        clearTextByName(name);
289        waitAndTypeByName(name,value);
290    }
291
292    @Test
293    public void testAgendaEditorAndOrToggleSyncBookmark() throws Exception {
294        testAgendaEditorAndOrToggleSync();
295        passed();
296    }
297
298    @Test
299    public void testAgendaEditorAndOrToggleSyncNav() throws Exception {
300        testAgendaEditorAndOrToggleSync();
301        passed();
302    }
303
304    @Test
305    public void testAgendaEditorAddActionsBookmark() throws Exception {
306        String peopleFlowId = getPeopleFlowId();
307        testAgendaEditorEditRuleAddActionsBlank();
308        testAgendaEditorEditRuleAddActionsKrmsActionResolverType();
309        testAgendaEditorEditRuleAddActionsNotifyPeopleFlow(peopleFlowId);
310        testAgendaEditorEditRuleAddActionsRouteToPeopleFlow(peopleFlowId);
311        testAgendaEditorEditRuleAddActionsValidationAction();
312        passed();
313    }
314
315    @Test
316    public void testAgendaEditorAddActionsNav() throws Exception {
317        String peopleFlowId = getPeopleFlowId();
318        testAgendaEditorEditRuleAddActionsBlank();
319        testAgendaEditorEditRuleAddActionsKrmsActionResolverType();
320        testAgendaEditorEditRuleAddActionsNotifyPeopleFlow(peopleFlowId);
321        testAgendaEditorEditRuleAddActionsRouteToPeopleFlow(peopleFlowId);
322        testAgendaEditorEditRuleAddActionsValidationAction();
323        passed();
324    }
325}
326