Skip to content

Commit 538a324

Browse files
committed
Change the logic of NewVersionTest
* handling the new alert when creating a new version of an item that is in moderation * refactoring code to reduce duplicated code
1 parent b440ef3 commit 538a324

File tree

1 file changed

+75
-44
lines changed

1 file changed

+75
-44
lines changed
Lines changed: 75 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.tle.webtests.test.workflow.rejection;
22

33
import static org.testng.Assert.assertEquals;
4-
4+
import static org.testng.Assert.assertTrue;
5+
import org.openqa.selenium.Alert;
6+
import org.openqa.selenium.UnhandledAlertException;
57
import org.testng.annotations.Test;
6-
78
import com.tle.webtests.framework.TestInstitution;
89
import com.tle.webtests.pageobject.searching.ItemAdminPage;
910
import com.tle.webtests.pageobject.searching.ItemListPage;
@@ -15,81 +16,111 @@
1516
import com.tle.webtests.pageobject.wizard.WizardPageTab;
1617
import com.tle.webtests.test.AbstractCleanupTest;
1718

19+
1820
@TestInstitution("workflow")
1921
public class NewVersionTest extends AbstractCleanupTest
2022
{
23+
private static final String BACKTICK_PASSWORD = "``````";
24+
25+
private static final String SORTING = "datemodified";
26+
27+
private static final String ADMIN_USERNAME = "admin";
28+
29+
private static final String FIRST_MODERATOR_USERNAME = "SimpleModerator";
30+
31+
private static final String SECOND_MODERATOR_USERNAME = "SecondStepModerator";
2132

2233
public NewVersionTest()
2334
{
24-
setDeleteCredentials("admin", "``````");
35+
setDeleteCredentials(ADMIN_USERNAME, BACKTICK_PASSWORD );
2536
}
2637

2738
@Test
2839
public void newVersion()
2940
{
30-
3141
// Login as admin user and contribute an item to the collection
32-
logon("admin", "``````");
33-
42+
logon(ADMIN_USERNAME, BACKTICK_PASSWORD);
3443
WizardPageTab wizard = new ContributePage(context).load().openWizard("Move to Live During Moderation");
3544
String itemFullName = context.getFullName("item");
3645
String itemFullName2 = itemFullName + " 2";
37-
wizard.editbox(1, itemFullName);
38-
wizard.save().submit();
46+
saveItem(wizard,1,itemFullName);
3947
logout();
4048

4149
// Login as SimpleModerator and moderate the item at the first step.
42-
logon("SimpleModerator", "``````");
50+
logon(FIRST_MODERATOR_USERNAME, BACKTICK_PASSWORD);
51+
doModeration( FIRST_MODERATOR_USERNAME, BACKTICK_PASSWORD, "moderation step 1", itemFullName, false );
52+
logout();
4353

44-
TaskListPage taskListPage = new TaskListPage(context).load();
45-
ModerateListSearchResults modResults = taskListPage.exactQuery(itemFullName);
46-
assertEquals(modResults.getStepName(itemFullName), "moderation step 1");
47-
modResults.moderate(itemFullName).accept();
54+
//login as admin to validate that we can't create a new version while an item is still under moderation
55+
logon(ADMIN_USERNAME, BACKTICK_PASSWORD);
56+
Boolean alertDisplayed = false;
57+
try {
58+
SearchPage.searchAndView(context, itemFullName).adminTab().newVersion();
59+
}
60+
catch(UnhandledAlertException f){
61+
Alert alert = getContext().getDriver().switchTo().alert();
62+
alert.accept();
63+
alertDisplayed = true;
64+
}
65+
assertTrue( alertDisplayed, "Failed to trigger check of new version not allowed when already version in moderation.");
4866
logout();
4967

50-
// login as the owner of the item and new version it.
51-
logon("admin", "``````");
68+
// Login as the SecondStepModerator and moderate again because this workflow needs moderating twice.
69+
logon(SECOND_MODERATOR_USERNAME, BACKTICK_PASSWORD);
70+
doModeration( SECOND_MODERATOR_USERNAME, BACKTICK_PASSWORD, "moderation step 2", itemFullName, false );
71+
logout();
5272

73+
// Now the item should be in a state where we're allowed to create a new version.
74+
// login as admin and new version it.
75+
logon(ADMIN_USERNAME, BACKTICK_PASSWORD);
5376
wizard = SearchPage.searchAndView(context, itemFullName).adminTab().newVersion();
54-
wizard.editbox(1, itemFullName2);
55-
wizard.save().submit();
56-
57-
// check that there is a version that is live, and one that is
58-
// moderating.
59-
ItemAdminPage adminPage = new ItemAdminPage(context).load();
60-
adminPage.exactQuery(itemFullName);
61-
adminPage.setSort("datemodified");
62-
ItemListPage itemList = adminPage.results();
77+
saveItem(wizard,1,itemFullName2);
78+
// check that there is a version that is live, and one that is moderating.
79+
ItemListPage itemList = getItemList(itemFullName);
6380
assertEquals(itemList.getResultForTitle(itemFullName, 1).getStatus(), "live");
6481
assertEquals(itemList.getResultForTitle(itemFullName2, 1).getStatus(), "moderating");
6582
logout();
6683

67-
// Login as SimpleModerator and moderate the item at the first step.
68-
logon("SimpleModerator", "``````");
69-
70-
taskListPage = new TaskListPage(context).load();
71-
modResults = taskListPage.exactQuery(itemFullName2);
72-
assertEquals(modResults.getStepName(itemFullName2), "moderation step 1");
73-
modResults.moderate(itemFullName2).accept();
74-
75-
// After moderation, check that the item has gone life after the first
76-
// moderation step
77-
adminPage = new ItemAdminPage(context).load();
78-
adminPage.exactQuery(itemFullName2);
79-
adminPage.setSort("datemodified");
80-
itemList = adminPage.results();
84+
// Login as SimpleModerator and moderate the new version of this item at the first step.
85+
logon(FIRST_MODERATOR_USERNAME, BACKTICK_PASSWORD);
86+
doModeration(FIRST_MODERATOR_USERNAME, BACKTICK_PASSWORD, "moderation step 1", itemFullName2,false);
87+
// After moderation, check that the item has gone life after the first moderation step
88+
itemList = getItemList(itemFullName2);
8189
assertEquals(itemList.getResultForTitle(itemFullName2, 1).getStatus(), "live");
8290
logout();
8391

8492
// Login as the SecondStepModerator and check that the item is still
8593
// there to moderate, and is still live once moderated from second step.
86-
logon("SecondStepModerator", "``````");
87-
taskListPage = new TaskListPage(context).load();
88-
modResults = taskListPage.exactQuery(itemFullName2);
89-
ModerationView tasksTab = modResults.moderate(itemFullName2);
90-
tasksTab.assignToMe();
91-
tasksTab.accept();
94+
logon(SECOND_MODERATOR_USERNAME, BACKTICK_PASSWORD);
95+
doModeration(SECOND_MODERATOR_USERNAME,BACKTICK_PASSWORD,"", itemFullName2, true);
9296
logout();
9397
}
9498

99+
private void doModeration( String username, String password, String stepName, String itemFullName, Boolean lastModeration ) {
100+
TaskListPage taskListPage = new TaskListPage(context).load();
101+
ModerateListSearchResults modResults = taskListPage.exactQuery(itemFullName);
102+
if(!lastModeration)
103+
{
104+
assertEquals(modResults.getStepName(itemFullName), stepName );
105+
modResults.moderate(itemFullName).accept();
106+
}
107+
else
108+
{
109+
ModerationView tasksTab = modResults.moderate(itemFullName);
110+
tasksTab.assignToMe();
111+
tasksTab.accept();
112+
}
113+
}
114+
115+
private ItemListPage getItemList(String itemFullName){
116+
ItemAdminPage adminPage = new ItemAdminPage(context).load();
117+
adminPage.exactQuery(itemFullName);
118+
adminPage.setSort(SORTING);
119+
return adminPage.results();
120+
}
121+
122+
private void saveItem(WizardPageTab wizard, int ctrlNum, String itemFullName){
123+
wizard.editbox(ctrlNum, itemFullName);
124+
wizard.save().submit();
125+
}
95126
}

0 commit comments

Comments
 (0)